Commit | Line | Data |
---|---|---|
d0aeaf5a DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
f9ac90b4 KB |
3 | * All rights reserved. |
4 | * | |
cb956e54 | 5 | * %sccs.include.redist.c% |
d0aeaf5a DF |
6 | */ |
7 | ||
963ce42e | 8 | #ifndef lint |
cb956e54 | 9 | static char sccsid[] = "@(#)get_addrs.c 5.6 (Berkeley) %G%"; |
f9ac90b4 | 10 | #endif /* not lint */ |
955a40d4 MK |
11 | |
12 | #include "talk_ctl.h" | |
4fa2ac2d | 13 | #include <netdb.h> |
955a40d4 MK |
14 | |
15 | get_addrs(my_machine_name, his_machine_name) | |
4fa2ac2d | 16 | char *my_machine_name, *his_machine_name; |
955a40d4 | 17 | { |
963ce42e MK |
18 | struct hostent *hp; |
19 | struct servent *sp; | |
955a40d4 | 20 | |
4fa2ac2d | 21 | msg.pid = htonl(getpid()); |
955a40d4 | 22 | /* look up the address of the local host */ |
963ce42e | 23 | hp = gethostbyname(my_machine_name); |
7620b226 KB |
24 | if (hp == NULL) { |
25 | fprintf(stderr, "talk: %s: ", my_machine_name); | |
26 | herror((char *)NULL); | |
963ce42e | 27 | exit(-1); |
955a40d4 | 28 | } |
963ce42e | 29 | bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length); |
4fa2ac2d KM |
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)) { | |
963ce42e | 35 | hp = gethostbyname(his_machine_name); |
7620b226 KB |
36 | if (hp == NULL) { |
37 | fprintf(stderr, "talk: %s: ", his_machine_name); | |
38 | herror((char *)NULL); | |
963ce42e MK |
39 | exit(-1); |
40 | } | |
41 | bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length); | |
4fa2ac2d KM |
42 | } else |
43 | his_machine_addr = my_machine_addr; | |
44 | /* find the server's port */ | |
45 | sp = getservbyname("ntalk", "udp"); | |
963ce42e | 46 | if (sp == 0) { |
4fa2ac2d KM |
47 | fprintf(stderr, "talk: %s/%s: service is not registered.\n", |
48 | "ntalk", "udp"); | |
963ce42e MK |
49 | exit(-1); |
50 | } | |
51 | daemon_port = sp->s_port; | |
955a40d4 | 52 | } |