]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/get_names.c
1 /* $NetBSD: get_names.c,v 1.4 2000/07/03 03:57:41 matt Exp $ */
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.
10 __RCSID("$NetBSD: get_names.c,v 1.4 2000/07/03 03:57:41 matt Exp $");
15 #if defined(TALK_43) || defined(TALK_42)
17 # include <sys/param.h>
24 # include "talk_ctl.h"
28 static char hostname
[MAXHOSTNAMELEN
+ 1];
29 char *my_machine_name
;
32 * Determine the local user and machine
35 get_local_name(my_name
)
41 /* Load these useful values into the standard message header */
43 (void) strncpy(msg
.l_name
, my_name
, NAME_SIZE
);
44 msg
.l_name
[NAME_SIZE
- 1] = '\0';
48 msg
.vers
= TALK_VERSION
;
49 msg
.addr
.sa_family
= htons(AF_INET
);
50 msg
.ctl_addr
.sa_family
= htons(AF_INET
);
52 msg
.addr
.sin_family
= htons(AF_INET
);
53 msg
.ctl_addr
.sin_family
= htons(AF_INET
);
56 (void)gethostname(hostname
, sizeof (hostname
));
57 hostname
[sizeof(hostname
) - 1] = '\0';
58 my_machine_name
= hostname
;
59 /* look up the address of the local host */
60 hp
= gethostbyname(my_machine_name
);
61 if (hp
== (struct hostent
*) 0) {
62 printf("This machine doesn't exist. Boy, am I confused!\n");
65 memcpy(&my_machine_addr
, hp
->h_addr
, hp
->h_length
);
66 /* find the daemon portal */
68 sp
= getservbyname("ntalk", "udp");
70 sp
= getservbyname("talk", "udp");
74 syslog(LOG_ERR
, "This machine doesn't support talk");
76 perror("This machine doesn't support talk");
80 daemon_port
= sp
->s_port
;
84 * Determine the remote user and machine
87 get_remote_name(his_address
)
91 char *his_machine_name
;
96 /* check for, and strip out, the machine name of the target */
97 for (ptr
= his_address
; *ptr
!= '\0' && *ptr
!= '@' && *ptr
!= ':'
98 && *ptr
!= '!' && *ptr
!= '.'; ptr
++)
101 /* this is a local to local talk */
102 his_name
= his_address
;
103 his_machine_name
= my_machine_name
;
107 his_name
= his_address
;
108 his_machine_name
= ptr
+ 1;
110 /* host.user or host!user or host:user */
112 his_machine_name
= his_address
;
116 /* Load these useful values into the standard message header */
117 (void) strncpy(msg
.r_name
, his_name
, NAME_SIZE
);
118 msg
.r_name
[NAME_SIZE
- 1] = '\0';
120 /* if he is on the same machine, then simply copy */
121 if (memcmp((char *) &his_machine_name
, (char *) &my_machine_name
,
122 sizeof(his_machine_name
)) == 0)
123 memcpy(&his_machine_addr
, &my_machine_addr
,
124 sizeof(his_machine_name
));
126 /* look up the address of the recipient's machine */
127 hp
= gethostbyname(his_machine_name
);
128 if (hp
== (struct hostent
*) 0)
129 return 0; /* unknown host */
130 memcpy(&his_machine_addr
, hp
->h_addr
, hp
->h_length
);