xref: /original-bsd/old/talk/talk/get_addrs.c (revision 0842ddeb)
1 /*-
2  * Copyright (c) 1983, 1985
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)get_addrs.c	5.1 (Berkeley) 6/6/85";
10 #endif not lint
11 
12 #include "talk_ctl.h"
13 #include <netdb.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <unistd.h>
17 
18 void
19 get_addrs(my_machine_name, his_machine_name)
20 	char *my_machine_name;
21 	char *his_machine_name;
22 {
23 	struct hostent *hp;
24 	struct servent *sp;
25 
26 	msg.pid = getpid();
27 	/* look up the address of the local host */
28 	hp = gethostbyname(my_machine_name);
29 	if (hp == (struct hostent *) 0) {
30 		printf("This machine doesn't exist. Boy, am I confused!\n");
31 		exit(-1);
32 	}
33 	bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
34 	/* if he is on the same machine, then simply copy */
35 	if (bcmp((char *)&his_machine_name, (char *)&my_machine_name,
36 	    sizeof(his_machine_name)) == 0)
37 		bcopy((char *)&my_machine_addr, (char *)&his_machine_addr,
38 		    sizeof(his_machine_name));
39 	else {
40 		/* look up the address of the recipient's machine */
41 		hp = gethostbyname(his_machine_name);
42 		if (hp == (struct hostent *) 0 ) {
43 			printf("%s is an unknown host\n", his_machine_name);
44 			exit(-1);
45 		}
46 		bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
47 	}
48 	/* find the daemon portal */
49 	sp = getservbyname("talk", "udp");
50 	if (sp == 0) {
51 		p_error("This machine doesn't support talk");
52 		exit(-1);
53 	}
54 	daemon_port = sp->s_port;
55 }
56