combine find_node and add_node, use db(3) hashing; malloc node and
[unix-history] / usr / src / usr.bin / talk / get_addrs.c
CommitLineData
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
a4e94754 9static char sccsid[] = "@(#)get_addrs.c 5.7 (Berkeley) %G%";
f9ac90b4 10#endif /* not lint */
955a40d4 11
a4e94754
KB
12#include <sys/types.h>
13#include <sys/socket.h>
14#include <netinet/in.h>
15#include <protocols/talkd.h>
4fa2ac2d 16#include <netdb.h>
a4e94754
KB
17#include <stdio.h>
18#include "talk_ctl.h"
955a40d4
MK
19
20get_addrs(my_machine_name, his_machine_name)
4fa2ac2d 21 char *my_machine_name, *his_machine_name;
955a40d4 22{
963ce42e
MK
23 struct hostent *hp;
24 struct servent *sp;
955a40d4 25
4fa2ac2d 26 msg.pid = htonl(getpid());
955a40d4 27 /* look up the address of the local host */
963ce42e 28 hp = gethostbyname(my_machine_name);
7620b226
KB
29 if (hp == NULL) {
30 fprintf(stderr, "talk: %s: ", my_machine_name);
31 herror((char *)NULL);
963ce42e 32 exit(-1);
955a40d4 33 }
963ce42e 34 bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
4fa2ac2d
KM
35 /*
36 * If the callee is on-machine, just copy the
37 * network address, otherwise do a lookup...
38 */
39 if (strcmp(his_machine_name, my_machine_name)) {
963ce42e 40 hp = gethostbyname(his_machine_name);
7620b226
KB
41 if (hp == NULL) {
42 fprintf(stderr, "talk: %s: ", his_machine_name);
43 herror((char *)NULL);
963ce42e
MK
44 exit(-1);
45 }
46 bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
4fa2ac2d
KM
47 } else
48 his_machine_addr = my_machine_addr;
49 /* find the server's port */
50 sp = getservbyname("ntalk", "udp");
963ce42e 51 if (sp == 0) {
4fa2ac2d
KM
52 fprintf(stderr, "talk: %s/%s: service is not registered.\n",
53 "ntalk", "udp");
963ce42e
MK
54 exit(-1);
55 }
56 daemon_port = sp->s_port;
955a40d4 57}