|
|
1.1 root 1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)get_addrs.c 5.6 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: #include "talk_ctl.h"
25: #include <netdb.h>
26:
27: get_addrs(my_machine_name, his_machine_name)
28: char *my_machine_name, *his_machine_name;
29: {
30: struct hostent *hp;
31: struct servent *sp;
32:
33: msg.pid = htonl(getpid());
34: /* look up the address of the local host */
35: hp = gethostbyname(my_machine_name);
36: if (hp == NULL) {
37: fprintf(stderr, "talk: %s: ", my_machine_name);
38: herror((char *)NULL);
39: exit(-1);
40: }
41: bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
42: /*
43: * If the callee is on-machine, just copy the
44: * network address, otherwise do a lookup...
45: */
46: if (strcmp(his_machine_name, my_machine_name)) {
47: hp = gethostbyname(his_machine_name);
48: if (hp == NULL) {
49: fprintf(stderr, "talk: %s: ", his_machine_name);
50: herror((char *)NULL);
51: exit(-1);
52: }
53: bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
54: } else
55: his_machine_addr = my_machine_addr;
56: /* find the server's port */
57: sp = getservbyname("ntalk", "udp");
58: if (sp == 0) {
59: fprintf(stderr, "talk: %s/%s: service is not registered.\n",
60: "ntalk", "udp");
61: exit(-1);
62: }
63: daemon_port = sp->s_port;
64: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.