xref: /original-bsd/usr.bin/talk/get_addrs.c (revision 81a135f6)
1 #ifndef lint
2 static char sccsid[] = "@(#)get_addrs.c	1.2 (Berkeley) 04/11/84";
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 	/* look up the address of the local host */
19 	hp = gethostbyname(my_machine_name);
20 	if (hp == (struct hostent *) 0) {
21 		printf("This machine doesn't exist. Boy, am I confused!\n");
22 		exit(-1);
23 	}
24 	bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
25 	/* if he is on the same machine, then simply copy */
26 	if (bcmp((char *)&his_machine_name, (char *)&my_machine_name,
27 	    sizeof(his_machine_name)) == 0)
28 		bcopy((char *)&my_machine_addr, (char *)&his_machine_addr,
29 		    sizeof(his_machine_name));
30 	else {
31 		/* look up the address of the recipient's machine */
32 		hp = gethostbyname(his_machine_name);
33 		if (hp == (struct hostent *) 0 ) {
34 			printf("%s is an unknown host\n", his_machine_name);
35 			exit(-1);
36 		}
37 		bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
38 	}
39 	/* find the daemon portal */
40 	sp = getservbyname("talk", "udp");
41 	if (sp == 0) {
42 		p_error("This machine doesn't support talk");
43 		exit(-1);
44 	}
45 	daemon_port = sp->s_port;
46 }
47