Add copyright
[unix-history] / usr / src / usr.bin / talk / get_addrs.c
CommitLineData
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
d0aeaf5a
DF
8static char sccsid[] = "@(#)get_addrs.c 5.1 (Berkeley) %G%";
9#endif not lint
955a40d4
MK
10
11#include "talk_ctl.h"
12
963ce42e
MK
13struct hostent *gethostbyname();
14struct servent *getservbyname();
955a40d4
MK
15
16get_addrs(my_machine_name, his_machine_name)
963ce42e
MK
17 char *my_machine_name;
18 char *his_machine_name;
955a40d4 19{
963ce42e
MK
20 struct hostent *hp;
21 struct servent *sp;
955a40d4 22
963ce42e 23 msg.pid = getpid();
955a40d4 24 /* look up the address of the local host */
963ce42e
MK
25 hp = gethostbyname(my_machine_name);
26 if (hp == (struct hostent *) 0) {
27 printf("This machine doesn't exist. Boy, am I confused!\n");
28 exit(-1);
955a40d4 29 }
963ce42e
MK
30 bcopy(hp->h_addr, (char *)&my_machine_addr, hp->h_length);
31 /* if he is on the same machine, then simply copy */
32 if (bcmp((char *)&his_machine_name, (char *)&my_machine_name,
33 sizeof(his_machine_name)) == 0)
34 bcopy((char *)&my_machine_addr, (char *)&his_machine_addr,
35 sizeof(his_machine_name));
36 else {
37 /* look up the address of the recipient's machine */
38 hp = gethostbyname(his_machine_name);
39 if (hp == (struct hostent *) 0 ) {
40 printf("%s is an unknown host\n", his_machine_name);
41 exit(-1);
42 }
43 bcopy(hp->h_addr, (char *) &his_machine_addr, hp->h_length);
955a40d4 44 }
955a40d4 45 /* find the daemon portal */
963ce42e
MK
46 sp = getservbyname("talk", "udp");
47 if (sp == 0) {
48 p_error("This machine doesn't support talk");
49 exit(-1);
50 }
51 daemon_port = sp->s_port;
955a40d4 52}