]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/get_names.c
Remove unnecessary casts, and add necessary ones for printf arguments.
[bsdgames-darwin.git] / hunt / huntd / get_names.c
1 /* $NetBSD: get_names.c,v 1.3 1998/07/06 07:00:31 mrg Exp $ */
2 /*
3 * Copyright (c) 1983 Regents of the University of California.
4 * All rights reserved. The Berkeley software License Agreement
5 * specifies the terms and conditions for redistribution.
6 */
7
8 #include <sys/cdefs.h>
9 #ifndef lint
10 __RCSID("$NetBSD: get_names.c,v 1.3 1998/07/06 07:00:31 mrg Exp $");
11 #endif /* not lint */
12
13 #include "bsd.h"
14
15 #if defined(TALK_43) || defined(TALK_42)
16
17 # include <sys/param.h>
18 # include <netdb.h>
19 # include <stdio.h>
20 # include <string.h>
21 # include <unistd.h>
22 # include "hunt.h"
23 # include "talk_ctl.h"
24
25 extern CTL_MSG msg;
26
27 static char hostname[MAXHOSTNAMELEN + 1];
28 char *my_machine_name;
29
30 /*
31 * Determine the local user and machine
32 */
33 void
34 get_local_name(my_name)
35 char *my_name;
36 {
37 struct hostent *hp;
38 struct servent *sp;
39
40 /* Load these useful values into the standard message header */
41 msg.id_num = 0;
42 (void) strncpy(msg.l_name, my_name, NAME_SIZE);
43 msg.l_name[NAME_SIZE - 1] = '\0';
44 msg.r_tty[0] = '\0';
45 msg.pid = getpid();
46 # ifdef TALK_43
47 msg.vers = TALK_VERSION;
48 msg.addr.sa_family = htons(AF_INET);
49 msg.ctl_addr.sa_family = htons(AF_INET);
50 # else
51 msg.addr.sin_family = htons(AF_INET);
52 msg.ctl_addr.sin_family = htons(AF_INET);
53 # endif
54
55 (void)gethostname(hostname, sizeof (hostname));
56 hostname[sizeof(hostname) - 1] = '\0';
57 my_machine_name = hostname;
58 /* look up the address of the local host */
59 hp = gethostbyname(my_machine_name);
60 if (hp == (struct hostent *) 0) {
61 printf("This machine doesn't exist. Boy, am I confused!\n");
62 exit(-1);
63 }
64 memcpy(&my_machine_addr, hp->h_addr, hp->h_length);
65 /* find the daemon portal */
66 # ifdef TALK_43
67 sp = getservbyname("ntalk", "udp");
68 # else
69 sp = getservbyname("talk", "udp");
70 # endif
71 if (sp == 0) {
72 # ifdef LOG
73 syslog(LOG_ERR, "This machine doesn't support talk");
74 # else
75 perror("This machine doesn't support talk");
76 # endif
77 exit(-1);
78 }
79 daemon_port = sp->s_port;
80 }
81
82 /*
83 * Determine the remote user and machine
84 */
85 int
86 get_remote_name(his_address)
87 char *his_address;
88 {
89 char *his_name;
90 char *his_machine_name;
91 char *ptr;
92 struct hostent *hp;
93
94
95 /* check for, and strip out, the machine name of the target */
96 for (ptr = his_address; *ptr != '\0' && *ptr != '@' && *ptr != ':'
97 && *ptr != '!' && *ptr != '.'; ptr++)
98 continue;
99 if (*ptr == '\0') {
100 /* this is a local to local talk */
101 his_name = his_address;
102 his_machine_name = my_machine_name;
103 } else {
104 if (*ptr == '@') {
105 /* user@host */
106 his_name = his_address;
107 his_machine_name = ptr + 1;
108 } else {
109 /* host.user or host!user or host:user */
110 his_name = ptr + 1;
111 his_machine_name = his_address;
112 }
113 *ptr = '\0';
114 }
115 /* Load these useful values into the standard message header */
116 (void) strncpy(msg.r_name, his_name, NAME_SIZE);
117 msg.r_name[NAME_SIZE - 1] = '\0';
118
119 /* if he is on the same machine, then simply copy */
120 if (memcmp((char *) &his_machine_name, (char *) &my_machine_name,
121 sizeof(his_machine_name)) == 0)
122 memcpy(&his_machine_addr, &my_machine_addr,
123 sizeof(his_machine_name));
124 else {
125 /* look up the address of the recipient's machine */
126 hp = gethostbyname(his_machine_name);
127 if (hp == (struct hostent *) 0)
128 return 0; /* unknown host */
129 memcpy(&his_machine_addr, hp->h_addr, hp->h_length);
130 }
131 return 1;
132 }
133 #endif