Module Name:    src
Committed By:   dholland
Date:           Sun Mar 30 04:57:37 UTC 2014

Modified Files:
        src/games/hunt/hunt: hunt.c server.c

Log Message:
I wish the socket API didn't require casts. Easy to mess them up.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/games/hunt/hunt/hunt.c
cvs rdiff -u -r1.7 -r1.8 src/games/hunt/hunt/server.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/hunt/hunt.c
diff -u src/games/hunt/hunt/hunt.c:1.52 src/games/hunt/hunt/hunt.c:1.53
--- src/games/hunt/hunt/hunt.c:1.52	Sun Mar 30 04:40:50 2014
+++ src/games/hunt/hunt/hunt.c	Sun Mar 30 04:57:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: hunt.c,v 1.52 2014/03/30 04:40:50 dholland Exp $	*/
+/*	$NetBSD: hunt.c,v 1.53 2014/03/30 04:57:37 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: hunt.c,v 1.52 2014/03/30 04:40:50 dholland Exp $");
+__RCSID("$NetBSD: hunt.c,v 1.53 2014/03/30 04:57:37 dholland Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -449,10 +449,10 @@ dump_scores(const struct sockaddr_storag
 	printf("\n%s:\n", lookuphost(host, hostlen));
 	fflush(stdout);
 
-	s = socket(SOCK_FAMILY, SOCK_STREAM, 0);
+	s = socket(host->ss_family, SOCK_STREAM, 0);
 	if (s < 0)
 		err(1, "socket");
-	if (connect(s, (struct sockaddr *) &host, sizeof host) < 0)
+	if (connect(s, (const struct sockaddr *)host, hostlen) < 0)
 		err(1, "connect");
 	while ((cnt = read(s, buf, BUFSIZ)) > 0)
 		write(fileno(stdout), buf, cnt);

Index: src/games/hunt/hunt/server.c
diff -u src/games/hunt/hunt/server.c:1.7 src/games/hunt/hunt/server.c:1.8
--- src/games/hunt/hunt/server.c:1.7	Sun Mar 30 04:39:40 2014
+++ src/games/hunt/hunt/server.c	Sun Mar 30 04:57:37 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: server.c,v 1.7 2014/03/30 04:39:40 dholland Exp $	*/
+/*	$NetBSD: server.c,v 1.8 2014/03/30 04:57:37 dholland Exp $	*/
 /*
  * Copyright (c) 1983-2003, Regents of the University of California.
  * All rights reserved.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: server.c,v 1.7 2014/03/30 04:39:40 dholland Exp $");
+__RCSID("$NetBSD: server.c,v 1.8 2014/03/30 04:57:37 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/stat.h>
@@ -97,13 +97,15 @@ serverlist_setup(const char *explicit_ho
 }
 
 static void
-add_daemon_addr(const struct sockaddr_storage *addr, uint16_t port_num)
+add_daemon_addr(const struct sockaddr_storage *addr, socklen_t addrlen,
+		uint16_t port_num)
 {
 	const struct sockaddr_in *sin;
 
 	if (addr->ss_family != AF_INET) {
 		return;
 	}
+	assert(addrlen == sizeof(struct sockaddr_in));
 	sin = (const struct sockaddr_in *)addr;
 
 	assert(numdaemons <= maxdaemons);
@@ -139,7 +141,7 @@ add_daemon_addr(const struct sockaddr_st
 }
 
 static bool
-have_daemon_addr(const struct sockaddr_storage *addr)
+have_daemon_addr(const struct sockaddr_storage *addr, socklen_t addrlen)
 {
 	unsigned j;
 	const struct sockaddr_in *sin;
@@ -147,6 +149,7 @@ have_daemon_addr(const struct sockaddr_s
 	if (addr->ss_family != AF_INET) {
 		return false;
 	}
+	assert(addrlen == sizeof(struct sockaddr_in));
 	sin = (const struct sockaddr_in *)addr;
 
 	for (j = 0; j < numdaemons; j++) {
@@ -207,6 +210,7 @@ send_messages(int contactsock, unsigned 
 	int option;
 	int i;
 
+	memset(&contactaddr, 0, sizeof(contactaddr));
 	contactaddr.sin_family = SOCK_FAMILY;
 	contactaddr.sin_port = htons(port);
 
@@ -311,12 +315,12 @@ get_responses(int contactsock)
 			/* trash, ignore it */
 			continue;
 		}
-		if (have_daemon_addr(&addr)) {
+		if (have_daemon_addr(&addr, addrlen)) {
 			/* this shouldn't happen */
 			continue;
 		}
 
-		add_daemon_addr(&addr, port_num);
+		add_daemon_addr(&addr, addrlen, port_num);
 	}
 
 	initial = false;

Reply via email to