1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 static char sccsid[] = "@(#)get_addrs.c 5.3 (Berkeley) 05/20/88"; 15 #endif /* not lint */ 16 17 #include "talk_ctl.h" 18 #include <netdb.h> 19 20 get_addrs(my_machine_name, his_machine_name) 21 char *my_machine_name, *his_machine_name; 22 { 23 struct hostent *hp; 24 struct servent *sp; 25 26 msg.pid = htonl(getpid()); 27 /* look up the address of the local host */ 28 hp = gethostbyname(my_machine_name); 29 if (hp == (struct hostent *) 0) { 30 fprintf(stderr, 31 "talk: %s: Can't figure out network address.\n", 32 my_machine_name); 33 exit(-1); 34 } 35 bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length); 36 /* 37 * If the callee is on-machine, just copy the 38 * network address, otherwise do a lookup... 39 */ 40 if (strcmp(his_machine_name, my_machine_name)) { 41 hp = gethostbyname(his_machine_name); 42 if (hp == (struct hostent *) 0 ) { 43 fprintf(stderr, 44 "talk: %s: Can't figure out network address.\n", 45 his_machine_name); 46 exit(-1); 47 } 48 bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length); 49 } else 50 his_machine_addr = my_machine_addr; 51 /* find the server's port */ 52 sp = getservbyname("ntalk", "udp"); 53 if (sp == 0) { 54 fprintf(stderr, "talk: %s/%s: service is not registered.\n", 55 "ntalk", "udp"); 56 exit(-1); 57 } 58 daemon_port = sp->s_port; 59 } 60