]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hunt/huntd/get_names.c
1 /* $NetBSD: get_names.c,v 1.2 1997/10/10 16:33:35 lukem 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.2 1997/10/10 16:33:35 lukem Exp $");
15 #if defined(TALK_43) || defined(TALK_42)
17 # include <sys/param.h>
23 # include "talk_ctl.h"
27 static char hostname
[MAXHOSTNAMELEN
];
28 char *my_machine_name
;
31 * Determine the local user and machine
34 get_local_name(my_name
)
40 /* Load these useful values into the standard message header */
42 (void) strncpy(msg
.l_name
, my_name
, NAME_SIZE
);
43 msg
.l_name
[NAME_SIZE
- 1] = '\0';
47 msg
.vers
= TALK_VERSION
;
48 msg
.addr
.sa_family
= htons(AF_INET
);
49 msg
.ctl_addr
.sa_family
= htons(AF_INET
);
51 msg
.addr
.sin_family
= htons(AF_INET
);
52 msg
.ctl_addr
.sin_family
= htons(AF_INET
);
55 (void) gethostname(hostname
, sizeof (hostname
));
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) {
60 printf("This machine doesn't exist. Boy, am I confused!\n");
63 memcpy(&my_machine_addr
, hp
->h_addr
, hp
->h_length
);
64 /* find the daemon portal */
66 sp
= getservbyname("ntalk", "udp");
68 sp
= getservbyname("talk", "udp");
72 syslog(LOG_ERR
, "This machine doesn't support talk");
74 perror("This machine doesn't support talk");
78 daemon_port
= sp
->s_port
;
82 * Determine the remote user and machine
85 get_remote_name(his_address
)
89 char *his_machine_name
;
94 /* check for, and strip out, the machine name of the target */
95 for (ptr
= his_address
; *ptr
!= '\0' && *ptr
!= '@' && *ptr
!= ':'
96 && *ptr
!= '!' && *ptr
!= '.'; ptr
++)
99 /* this is a local to local talk */
100 his_name
= his_address
;
101 his_machine_name
= my_machine_name
;
105 his_name
= his_address
;
106 his_machine_name
= ptr
+ 1;
108 /* host.user or host!user or host:user */
110 his_machine_name
= his_address
;
114 /* Load these useful values into the standard message header */
115 (void) strncpy(msg
.r_name
, his_name
, NAME_SIZE
);
116 msg
.r_name
[NAME_SIZE
- 1] = '\0';
118 /* if he is on the same machine, then simply copy */
119 if (memcmp((char *) &his_machine_name
, (char *) &my_machine_name
,
120 sizeof(his_machine_name
)) == 0)
121 memcpy(&his_machine_addr
, &my_machine_addr
,
122 sizeof(his_machine_name
));
124 /* look up the address of the recipient's machine */
125 hp
= gethostbyname(his_machine_name
);
126 if (hp
== (struct hostent
*) 0)
127 return 0; /* unknown host */
128 memcpy(&his_machine_addr
, hp
->h_addr
, hp
->h_length
);