-/* $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.
#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>
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);
-/* $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.
*/
#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>
}
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);
}
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;
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++) {
int option;
int i;
+ memset(&contactaddr, 0, sizeof(contactaddr));
contactaddr.sin_family = SOCK_FAMILY;
contactaddr.sin_port = htons(port);
/* 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;