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