]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/get_names.c
1 /* $NetBSD: get_names.c,v 1.6 2001/02/05 00:42:15 christos 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.6 2001/02/05 00:42:15 christos Exp $");
15 #if defined(TALK_43) || defined(TALK_42)
17 # include <sys/param.h>
24 # include "talk_ctl.h"
26 static char hostname
[MAXHOSTNAMELEN
+ 1];
27 char *my_machine_name
;
30 * Determine the local user and machine
33 get_local_name(my_name
)
39 /* Load these useful values into the standard message header */
41 (void) strncpy(msg
.l_name
, my_name
, NAME_SIZE
);
42 msg
.l_name
[NAME_SIZE
- 1] = '\0';
46 msg
.vers
= TALK_VERSION
;
47 msg
.addr
.sa_family
= htons(AF_INET
);
48 msg
.ctl_addr
.sa_family
= htons(AF_INET
);
50 msg
.addr
.sin_family
= htons(AF_INET
);
51 msg
.ctl_addr
.sin_family
= htons(AF_INET
);
54 (void)gethostname(hostname
, sizeof (hostname
));
55 hostname
[sizeof(hostname
) - 1] = '\0';
56 my_machine_name
= hostname
;
57 /* look up the address of the local host */
58 hp
= gethostbyname(my_machine_name
);
59 if (hp
== (struct hostent
*) 0) {
62 "This machine doesn't exist. Boy, am I confused!");
64 perror("This machine doesn't exist. Boy, am I confused!");
68 memcpy(&my_machine_addr
, hp
->h_addr
, hp
->h_length
);
69 /* find the daemon portal */
71 sp
= getservbyname("ntalk", "udp");
73 sp
= getservbyname("talk", "udp");
77 syslog(LOG_ERR
, "This machine doesn't support talk");
79 perror("This machine doesn't support talk");
83 daemon_port
= sp
->s_port
;
87 * Determine the remote user and machine
90 get_remote_name(his_address
)
94 char *his_machine_name
;
99 /* check for, and strip out, the machine name of the target */
100 for (ptr
= his_address
; *ptr
!= '\0' && *ptr
!= '@' && *ptr
!= ':'
101 && *ptr
!= '!' && *ptr
!= '.'; ptr
++)
104 /* this is a local to local talk */
105 his_name
= his_address
;
106 his_machine_name
= my_machine_name
;
110 his_name
= his_address
;
111 his_machine_name
= ptr
+ 1;
113 /* host.user or host!user or host:user */
115 his_machine_name
= his_address
;
119 /* Load these useful values into the standard message header */
120 (void) strncpy(msg
.r_name
, his_name
, NAME_SIZE
);
121 msg
.r_name
[NAME_SIZE
- 1] = '\0';
123 /* if he is on the same machine, then simply copy */
124 if (memcmp((char *) &his_machine_name
, (char *) &my_machine_name
,
125 sizeof(his_machine_name
)) == 0)
126 memcpy(&his_machine_addr
, &my_machine_addr
,
127 sizeof(his_machine_name
));
129 /* look up the address of the recipient's machine */
130 hp
= gethostbyname(his_machine_name
);
131 if (hp
== (struct hostent
*) 0)
132 return 0; /* unknown host */
133 memcpy(&his_machine_addr
, hp
->h_addr
, hp
->h_length
);