home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume4 / bridge / part02 / get_addrs.c < prev    next >
C/C++ Source or Header  |  1988-05-31  |  2KB  |  75 lines

  1. #ifndef lint
  2. static    char sccsid[] = "@(#)get_addrs.c 1.1 86/02/05 SMI"; /* from UCB 1.5 83/04/01 */
  3. #endif
  4.  
  5. #include "talk_ctl.h"
  6.  
  7. struct hostent *gethostbyname();
  8. struct servent *getservbyname();
  9.  
  10. get_addrs(my_machine_name, his_machine_name)
  11. char *my_machine_name;
  12. char *his_machine_name;
  13. {
  14.     struct hostent *hp;
  15.     struct servent *sp;
  16.  
  17.     msg.pid = getpid();
  18.  
  19.     /* look up the address of the local host */
  20.  
  21.     hp = gethostbyname(my_machine_name);
  22.  
  23.     if (hp == (struct hostent *) 0) {
  24.     printf("This machine doesn't exist. Boy, am I confused!\n");
  25.     exit(-1);
  26.     }
  27.  
  28.     if (hp->h_addrtype != AF_INET) {
  29.     printf("Protocal mix up with local machine address\n");
  30.     exit(-1);
  31.     }
  32.  
  33.     bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
  34.  
  35.     /* if he is on the same machine, then simply copy */
  36.  
  37.     if ( bcmp((char *)&his_machine_name, (char *)&my_machine_name,
  38.         sizeof(his_machine_name)) == 0) {
  39.     bcopy((char *)&my_machine_addr, (char *)&his_machine_addr,
  40.         sizeof(his_machine_name));
  41.     } else {
  42.  
  43.     /* look up the address of the recipient's machine */
  44.  
  45.     hp = gethostbyname(his_machine_name);
  46.  
  47.     if (hp == (struct hostent *) 0 ) {
  48.         printf("%s is an unknown host\n", his_machine_name);
  49.         exit(-1);
  50.     }
  51.  
  52.     if (hp->h_addrtype != AF_INET) {
  53.         printf("Protocol mix up with remote machine address\n");
  54.         exit(-1);
  55.     }
  56.  
  57.     bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
  58.     }
  59.  
  60.     /* find the daemon portal */
  61.  
  62. #ifdef NTALK
  63.     sp = getservbyname("ntalk", "udp");
  64. #else
  65.     sp = getservbyname("talk", "udp");
  66. #endif
  67.  
  68.     if (strcmp(sp->s_proto, "udp") != 0) {
  69.     printf("Protocol mix up with talk daemon\n");
  70.     exit(-1);
  71.     }
  72.  
  73.     daemon_port = sp->s_port;
  74. }
  75.