Module Name:    src
Committed By:   dholland
Date:           Sat Mar 29 20:10:10 UTC 2014

Modified Files:
        src/games/hunt/huntd: ctl.c ctl_transact.c driver.c faketalk.c
            get_names.c hunt.h

Log Message:
Make the code for issuing talk requests to find players actually build.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/games/hunt/huntd/ctl.c
cvs rdiff -u -r1.9 -r1.10 src/games/hunt/huntd/ctl_transact.c
cvs rdiff -u -r1.24 -r1.25 src/games/hunt/huntd/driver.c
cvs rdiff -u -r1.20 -r1.21 src/games/hunt/huntd/faketalk.c \
    src/games/hunt/huntd/hunt.h
cvs rdiff -u -r1.14 -r1.15 src/games/hunt/huntd/get_names.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/hunt/huntd/ctl.c
diff -u src/games/hunt/huntd/ctl.c:1.5 src/games/hunt/huntd/ctl.c:1.6
--- src/games/hunt/huntd/ctl.c:1.5	Sat Jul  4 04:29:54 2009
+++ src/games/hunt/huntd/ctl.c	Sat Mar 29 20:10:10 2014
@@ -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
 #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)

Index: src/games/hunt/huntd/ctl_transact.c
diff -u src/games/hunt/huntd/ctl_transact.c:1.9 src/games/hunt/huntd/ctl_transact.c:1.10
--- src/games/hunt/huntd/ctl_transact.c:1.9	Sat Jul  4 04:29:54 2009
+++ src/games/hunt/huntd/ctl_transact.c	Sat Mar 29 20:10:10 2014
@@ -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 2
  * 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_
 	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");

Index: src/games/hunt/huntd/driver.c
diff -u src/games/hunt/huntd/driver.c:1.24 src/games/hunt/huntd/driver.c:1.25
--- src/games/hunt/huntd/driver.c:1.24	Sat Mar 29 19:41:10 2014
+++ src/games/hunt/huntd/driver.c	Sat Mar 29 20:10:10 2014
@@ -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/0
 
 
 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 */

Index: src/games/hunt/huntd/faketalk.c
diff -u src/games/hunt/huntd/faketalk.c:1.20 src/games/hunt/huntd/faketalk.c:1.21
--- src/games/hunt/huntd/faketalk.c:1.20	Sat Mar 29 19:41:10 2014
+++ src/games/hunt/huntd/faketalk.c	Sat Mar 29 20:10:10 2014
@@ -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;
Index: src/games/hunt/huntd/hunt.h
diff -u src/games/hunt/huntd/hunt.h:1.20 src/games/hunt/huntd/hunt.h:1.21
--- src/games/hunt/huntd/hunt.h:1.20	Sat Mar 29 19:41:10 2014
+++ src/games/hunt/huntd/hunt.h	Sat Mar 29 20:10:10 2014
@@ -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 *);

Index: src/games/hunt/huntd/get_names.c
diff -u src/games/hunt/huntd/get_names.c:1.14 src/games/hunt/huntd/get_names.c:1.15
--- src/games/hunt/huntd/get_names.c:1.14	Sat Mar 29 19:26:28 2014
+++ src/games/hunt/huntd/get_names.c	Sat Mar 29 20:10:10 2014
@@ -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 201
 #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);

Reply via email to