Commit | Line | Data |
---|---|---|
963ce42e MK |
1 | #ifndef lint |
2 | static char sccsid[] = "@(#)get_addrs.c 1.2 (Berkeley) %G%"; | |
3 | #endif | |
955a40d4 MK |
4 | |
5 | #include "talk_ctl.h" | |
6 | ||
963ce42e MK |
7 | struct hostent *gethostbyname(); |
8 | struct servent *getservbyname(); | |
955a40d4 MK |
9 | |
10 | get_addrs(my_machine_name, his_machine_name) | |
963ce42e MK |
11 | char *my_machine_name; |
12 | char *his_machine_name; | |
955a40d4 | 13 | { |
963ce42e MK |
14 | struct hostent *hp; |
15 | struct servent *sp; | |
955a40d4 | 16 | |
963ce42e | 17 | msg.pid = getpid(); |
955a40d4 | 18 | /* look up the address of the local host */ |
963ce42e MK |
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); | |
955a40d4 | 23 | } |
963ce42e MK |
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); | |
955a40d4 | 38 | } |
955a40d4 | 39 | /* find the daemon portal */ |
963ce42e MK |
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; | |
955a40d4 | 46 | } |