summaryrefslogtreecommitdiffstats
path: root/hunt
diff options
context:
space:
mode:
authordholland <dholland@NetBSD.org>2014-03-30 04:57:37 +0000
committerdholland <dholland@NetBSD.org>2014-03-30 04:57:37 +0000
commit571fdd8c925268b4be1b866ff8f96c140bfe0ef9 (patch)
tree33319240737d914b842de9bb4c6dcf86d8e9088c /hunt
parent3cb1d3cdd0f23cb0b6ffecb45143d260ad9010a5 (diff)
downloadbsdgames-darwin-571fdd8c925268b4be1b866ff8f96c140bfe0ef9.tar.gz
bsdgames-darwin-571fdd8c925268b4be1b866ff8f96c140bfe0ef9.tar.zst
bsdgames-darwin-571fdd8c925268b4be1b866ff8f96c140bfe0ef9.zip
I wish the socket API didn't require casts. Easy to mess them up.
Diffstat (limited to 'hunt')
-rw-r--r--hunt/hunt/hunt.c8
-rw-r--r--hunt/hunt/server.c16
2 files changed, 14 insertions, 10 deletions
diff --git a/hunt/hunt/hunt.c b/hunt/hunt/hunt.c
index cc3a0c06..1a116d33 100644
--- a/hunt/hunt/hunt.c
+++ b/hunt/hunt/hunt.c
@@ -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_storage *host, socklen_t hostlen)
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);
diff --git a/hunt/hunt/server.c b/hunt/hunt/server.c
index 463df047..c2e9021d 100644
--- a/hunt/hunt/server.c
+++ b/hunt/hunt/server.c
@@ -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_host_arg, uint16_t port_arg)
}
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_storage *addr, uint16_t port_num)
}
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_storage *addr)
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 short msg)
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;