xref: /original-bsd/usr.bin/talk/get_addrs.c (revision 76210d32)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)get_addrs.c	5.6 (Berkeley) 06/01/90";
10 #endif /* not lint */
11 
12 #include "talk_ctl.h"
13 #include <netdb.h>
14 
15 get_addrs(my_machine_name, his_machine_name)
16 	char *my_machine_name, *his_machine_name;
17 {
18 	struct hostent *hp;
19 	struct servent *sp;
20 
21 	msg.pid = htonl(getpid());
22 	/* look up the address of the local host */
23 	hp = gethostbyname(my_machine_name);
24 	if (hp == NULL) {
25 		fprintf(stderr, "talk: %s: ", my_machine_name);
26 		herror((char *)NULL);
27 		exit(-1);
28 	}
29 	bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
30 	/*
31 	 * If the callee is on-machine, just copy the
32 	 * network address, otherwise do a lookup...
33 	 */
34 	if (strcmp(his_machine_name, my_machine_name)) {
35 		hp = gethostbyname(his_machine_name);
36 		if (hp == NULL) {
37 			fprintf(stderr, "talk: %s: ", his_machine_name);
38 			herror((char *)NULL);
39 			exit(-1);
40 		}
41 		bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
42 	} else
43 		his_machine_addr = my_machine_addr;
44 	/* find the server's port */
45 	sp = getservbyname("ntalk", "udp");
46 	if (sp == 0) {
47 		fprintf(stderr, "talk: %s/%s: service is not registered.\n",
48 		     "ntalk", "udp");
49 		exit(-1);
50 	}
51 	daemon_port = sp->s_port;
52 }
53