1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-24 08:29:04 +00:00

Use the proper length in get_srcaddr, not sizeof(sockaddr_in6).

This was a bug in r24413. The size needs to vary with the address family
on some platforms including OS X. This was noticed by Chris Clements.
This commit is contained in:
david
2011-06-28 00:35:01 +00:00
parent b9237eac33
commit f5fe8fb6e9

View File

@@ -3044,6 +3044,7 @@ static int get_srcaddr(const struct sockaddr_storage *dst,
{
static const unsigned short DUMMY_PORT = 1234;
struct sockaddr_storage dst_dummy;
size_t dst_dummy_len;
socklen_t len;
int fd, rc;
@@ -3055,14 +3056,16 @@ static int get_srcaddr(const struct sockaddr_storage *dst,
if (dst_dummy.ss_family == AF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in *) &dst_dummy;
sin->sin_port = htons(DUMMY_PORT);
dst_dummy_len = sizeof(*sin);
} else if (dst_dummy.ss_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &dst_dummy;
sin6->sin6_port = htons(DUMMY_PORT);
dst_dummy_len = sizeof(*sin6);
} else {
return -1;
}
rc = connect(fd, (struct sockaddr *) &dst_dummy, sizeof(struct sockaddr_in6));
rc = connect(fd, (struct sockaddr *) &dst_dummy, dst_dummy_len);
if (rc == -1)
netutil_fatal("%s: can't connect socket: %s", __func__, socket_strerror(socket_errno()));