summaryrefslogtreecommitdiffstats
path: root/hunt
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2014-03-29 20:10:10 +0000
committerdholland <dholland@NetBSD.org>2014-03-29 20:10:10 +0000
commit69e736d4a907daf72fc3e2b718e3c8bd2424a429 (patch)
tree7f6b9577261ba8a58fc298ec274b6ed13a4cd029 /hunt
parentb432256ee8cb43f841c457f6d542c54fc98291e0 (diff)
downloadbsdgames-darwin-69e736d4a907daf72fc3e2b718e3c8bd2424a429.tar.gz
bsdgames-darwin-69e736d4a907daf72fc3e2b718e3c8bd2424a429.tar.zst
bsdgames-darwin-69e736d4a907daf72fc3e2b718e3c8bd2424a429.zip
Make the code for issuing talk requests to find players actually build.
Diffstat (limited to 'hunt')
-rw-r--r--hunt/huntd/ctl.c14
-rw-r--r--hunt/huntd/ctl_transact.c16
-rw-r--r--hunt/huntd/driver.c8
-rw-r--r--hunt/huntd/faketalk.c14
-rw-r--r--hunt/huntd/get_names.c44
-rw-r--r--hunt/huntd/hunt.h4
6 files changed, 55 insertions, 45 deletions
diff --git a/hunt/huntd/ctl.c b/hunt/huntd/ctl.c
index 9b3c689e..05dc474b 100644
--- a/hunt/huntd/ctl.c
+++ b/hunt/huntd/ctl.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ctl.c,v 1.5 2009/07/04 04:29:54 dholland Exp $ */
+/* $NetBSD: ctl.c,v 1.6 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)ctl.c 5.2 (Berkeley) 3/13/86";
#else
-__RCSID("$NetBSD: ctl.c,v 1.5 2009/07/04 04:29:54 dholland Exp $");
+__RCSID("$NetBSD: ctl.c,v 1.6 2014/03/29 20:10:10 dholland Exp $");
#endif
#endif /* not lint */
@@ -52,8 +52,8 @@ __RCSID("$NetBSD: ctl.c,v 1.5 2009/07/04 04:29:54 dholland Exp $");
#include "hunt.h"
#include "talk_ctl.h"
-struct sockaddr_in daemon_addr = { AF_INET };
-struct sockaddr_in ctl_addr = { AF_INET };
+struct sockaddr_in daemon_addr;
+struct sockaddr_in ctl_addr;
/* inet addresses of the two machines */
struct in_addr my_machine_addr;
@@ -69,14 +69,16 @@ CTL_MSG msg;
void
open_ctl(void)
{
- int length;
+ socklen_t length;
+ ctl_addr.sin_family = AF_INET;
ctl_addr.sin_port = 0;
ctl_addr.sin_addr = my_machine_addr;
ctl_sockt = socket(AF_INET, SOCK_DGRAM, 0);
if (ctl_sockt <= 0)
p_error("Bad socket");
- if (bind(ctl_sockt, &ctl_addr, sizeof(ctl_addr)) != 0)
+ if (bind(ctl_sockt, (struct sockaddr *)&ctl_addr,
+ sizeof(ctl_addr)) != 0)
p_error("Couldn't bind to control socket");
length = sizeof(ctl_addr);
if (getsockname(ctl_sockt, (struct sockaddr *) &ctl_addr, &length) < 0)
diff --git a/hunt/huntd/ctl_transact.c b/hunt/huntd/ctl_transact.c
index 4ad6215a..9196c9d2 100644
--- a/hunt/huntd/ctl_transact.c
+++ b/hunt/huntd/ctl_transact.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ctl_transact.c,v 1.9 2009/07/04 04:29:54 dholland Exp $ */
+/* $NetBSD: ctl_transact.c,v 1.10 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)ctl_transact.c 5.2 (Berkeley) 3/13/86";
#else
-__RCSID("$NetBSD: ctl_transact.c,v 1.9 2009/07/04 04:29:54 dholland Exp $");
+__RCSID("$NetBSD: ctl_transact.c,v 1.10 2014/03/29 20:10:10 dholland Exp $");
#endif
#endif /* not lint */
@@ -57,13 +57,14 @@ __RCSID("$NetBSD: ctl_transact.c,v 1.9 2009/07/04 04:29:54 dholland Exp $");
* of time
*/
void
-ctl_transact(struct in_addr target, CTL_MSG msg, int type, CTL_RESPONSE *rp)
+ctl_transact(struct in_addr target, CTL_MSG tmsg, int type, CTL_RESPONSE *rp)
{
struct pollfd set[1];
int nready, cc, retries;
nready = 0;
- msg.type = type;
+ tmsg.type = type;
+ daemon_addr.sin_family = AF_INET;
daemon_addr.sin_addr = target;
daemon_addr.sin_port = daemon_port;
set[0].fd = ctl_sockt;
@@ -76,9 +77,10 @@ ctl_transact(struct in_addr target, CTL_MSG msg, int type, CTL_RESPONSE *rp)
do {
/* resend message until a response is obtained */
for (retries = MAX_RETRY; retries > 0; retries -= 1) {
- cc = sendto(ctl_sockt, &msg, sizeof (msg), 0,
- &daemon_addr, sizeof (daemon_addr));
- if (cc != sizeof (msg)) {
+ cc = sendto(ctl_sockt, &tmsg, sizeof (tmsg), 0,
+ (struct sockaddr *) &daemon_addr,
+ sizeof(daemon_addr));
+ if (cc != sizeof (tmsg)) {
if (errno == EINTR)
continue;
p_error("Error on write to talk daemon");
diff --git a/hunt/huntd/driver.c b/hunt/huntd/driver.c
index e200b662..5770e554 100644
--- a/hunt/huntd/driver.c
+++ b/hunt/huntd/driver.c
@@ -1,4 +1,4 @@
-/* $NetBSD: driver.c,v 1.24 2014/03/29 19:41:10 dholland Exp $ */
+/* $NetBSD: driver.c,v 1.25 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: driver.c,v 1.24 2014/03/29 19:41:10 dholland Exp $");
+__RCSID("$NetBSD: driver.c,v 1.25 2014/03/29 20:10:10 dholland Exp $");
#endif /* not lint */
#include <sys/ioctl.h>
@@ -47,8 +47,8 @@ __RCSID("$NetBSD: driver.c,v 1.24 2014/03/29 19:41:10 dholland Exp $");
static SOCKET Daemon;
-static char *First_arg; /* pointer to argv[0] */
-static char *Last_arg; /* pointer to end of argv/environ */
+char *First_arg; /* pointer to argv[0] */
+char *Last_arg; /* pointer to end of argv/environ */
#ifdef INTERNET
static int Test_socket; /* test socket to answer datagrams */
diff --git a/hunt/huntd/faketalk.c b/hunt/huntd/faketalk.c
index 973a4edf..d6f81e7c 100644
--- a/hunt/huntd/faketalk.c
+++ b/hunt/huntd/faketalk.c
@@ -1,4 +1,4 @@
-/* $NetBSD: faketalk.c,v 1.20 2014/03/29 19:41:10 dholland Exp $ */
+/* $NetBSD: faketalk.c,v 1.21 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: faketalk.c,v 1.20 2014/03/29 19:41:10 dholland Exp $");
+__RCSID("$NetBSD: faketalk.c,v 1.21 2014/03/29 20:10:10 dholland Exp $");
#endif /* not lint */
#include "bsd.h"
@@ -89,7 +89,8 @@ faketalk(void)
FILE *f;
int service; /* socket of service */
struct sockaddr_in des; /* address of destination */
- char *a, *b;
+ char *a;
+ const char *b;
(void) signal(SIGCHLD, exorcise);
@@ -182,11 +183,11 @@ faketalk(void)
else
t -= 1;
}
- while (isspace(*s))
+ while (isspace((unsigned char)*s))
s += 1;
if (*s == '\\')
s += 1;
- while (isspace(*t))
+ while (isspace((unsigned char)*t))
t -= 1;
*(t + 1) = '\0';
do_announce(s); /* construct and send talk request */
@@ -211,7 +212,8 @@ do_announce(char *s)
get_remote_name(s); /* setup his_machine_addr, msg.r_name */
#ifdef TALK_43
- msg.ctl_addr = *(struct osockaddr *) &ctl_addr;
+ /* XXX this is nothing like a safe cast */
+ msg.ctl_addr = *(struct talkd_sockaddr *) &ctl_addr;
msg.ctl_addr.sa_family = htons(msg.ctl_addr.sa_family);
#else
msg.ctl_addr = ctl_addr;
diff --git a/hunt/huntd/get_names.c b/hunt/huntd/get_names.c
index c20201b2..9c08f0f7 100644
--- a/hunt/huntd/get_names.c
+++ b/hunt/huntd/get_names.c
@@ -1,4 +1,4 @@
-/* $NetBSD: get_names.c,v 1.14 2014/03/29 19:26:28 dholland Exp $ */
+/* $NetBSD: get_names.c,v 1.15 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
* All rights reserved.
@@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: get_names.c,v 1.14 2014/03/29 19:26:28 dholland Exp $");
+__RCSID("$NetBSD: get_names.c,v 1.15 2014/03/29 20:10:10 dholland Exp $");
#endif /* not lint */
#include "bsd.h"
@@ -45,6 +45,8 @@ __RCSID("$NetBSD: get_names.c,v 1.14 2014/03/29 19:26:28 dholland Exp $");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <assert.h>
+
#include "hunt.h"
#include "talk_ctl.h"
@@ -55,7 +57,7 @@ char *my_machine_name;
* Determine the local user and machine
*/
void
-get_local_name(char *my_name)
+get_local_name(const char *my_name)
{
struct hostent *hp;
struct servent *sp;
@@ -116,7 +118,8 @@ get_remote_name(char *his_address)
const char *his_name;
const char *his_machine_name;
char *ptr;
- struct hostent *hp;
+ struct addrinfo ai0, *ai;
+ struct sockaddr_in *sin;
/* check for, and strip out, the machine name of the target */
for (ptr = his_address; *ptr != '\0' && *ptr != '@' && *ptr != ':'
@@ -144,24 +147,25 @@ get_remote_name(char *his_address)
* Since this is used for sending udp talk packets,
* it has to be AF_INET.
*/
- ai.ai_flags = 0;
- ai.family = AF_INET;
- ai.socktype = SOCK_DGRAM;
- ai.protocol = IPPROTO_UDP;
- ai.ai_addrlen = 0;
- ai.ai_addr = NULL;
- ai.ai_canonname = NULL;
- ai.ai_neext = NULL;
- aierror = getaddrinfo(his_machine_name, NULL, ai, &ai);
- if (aierror != 0) {
+ ai0.ai_flags = 0;
+ ai0.ai_family = AF_INET;
+ ai0.ai_socktype = SOCK_DGRAM;
+ ai0.ai_protocol = IPPROTO_UDP;
+ ai0.ai_addrlen = 0;
+ ai0.ai_addr = NULL;
+ ai0.ai_canonname = NULL;
+ ai0.ai_next = NULL;
+ if (getaddrinfo(his_machine_name, NULL, &ai0, &ai) != 0) {
return 0;
}
- assert(ai.family == AF_INET);
- assert(ai.socktype == SOCK_DGRAM);
- assert(ai.protocol == IPPROTO_UDP);
- assert(ai.ai_addrln == sizeof(his_machine_addr));
- assert(ai.ai_addr != NULL);
- his_machine_addr = *ai->ai_addr;
+ assert(ai->ai_family == AF_INET);
+ assert(ai->ai_socktype == SOCK_DGRAM);
+ assert(ai->ai_protocol == IPPROTO_UDP);
+ assert(ai->ai_addrlen == sizeof(his_machine_addr));
+ assert(ai->ai_addr != NULL);
+ sin = (struct sockaddr_in *)ai->ai_addr;
+ his_machine_addr = sin->sin_addr;
+ freeaddrinfo(ai);
}
/* Load these useful values into the standard message header */
(void) strncpy(msg.r_name, his_name, NAME_SIZE);
diff --git a/hunt/huntd/hunt.h b/hunt/huntd/hunt.h
index 122e7468..fb011952 100644
--- a/hunt/huntd/hunt.h
+++ b/hunt/huntd/hunt.h
@@ -1,4 +1,4 @@
-/* $NetBSD: hunt.h,v 1.20 2014/03/29 19:41:10 dholland Exp $ */
+/* $NetBSD: hunt.h,v 1.21 2014/03/29 20:10:10 dholland Exp $ */
/*
* Copyright (c) 1983-2003, Regents of the University of California.
@@ -424,7 +424,7 @@ void drawplayer(PLAYER *, bool);
void execute(PLAYER *);
void faketalk(void);
void fixshots(int, int, char);
-void get_local_name(char *);
+void get_local_name(const char *);
int get_remote_name(char *);
BULLET *is_bullet(int, int);
void look(PLAYER *);