xref: /original-bsd/old/talk/talk/get_addrs.c (revision 7e5c8007)
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 
14 struct	hostent *gethostbyname();
15 struct	servent *getservbyname();
16 
17 get_addrs(my_machine_name, his_machine_name)
18 	char *my_machine_name;
19 	char *his_machine_name;
20 {
21 	struct hostent *hp;
22 	struct servent *sp;
23 
24 	msg.pid = getpid();
25 	/* look up the address of the local host */
26 	hp = gethostbyname(my_machine_name);
27 	if (hp == (struct hostent *) 0) {
28 		printf("This machine doesn't exist. Boy, am I confused!\n");
29 		exit(-1);
30 	}
31 	bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
32 	/* if he is on the same machine, then simply copy */
33 	if (bcmp((char *)&his_machine_name, (char *)&my_machine_name,
34 	    sizeof(his_machine_name)) == 0)
35 		bcopy((char *)&my_machine_addr, (char *)&his_machine_addr,
36 		    sizeof(his_machine_name));
37 	else {
38 		/* look up the address of the recipient's machine */
39 		hp = gethostbyname(his_machine_name);
40 		if (hp == (struct hostent *) 0 ) {
41 			printf("%s is an unknown host\n", his_machine_name);
42 			exit(-1);
43 		}
44 		bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
45 	}
46 	/* find the daemon portal */
47 	sp = getservbyname("talk", "udp");
48 	if (sp == 0) {
49 		p_error("This machine doesn't support talk");
50 		exit(-1);
51 	}
52 	daemon_port = sp->s_port;
53 }
54