This commit is contained in:
Krishnashis Das 2026-08-27 10:29:26 +08:00 committed by GitHub
commit 81a54c440d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 0 deletions

View file

@ -425,6 +425,14 @@ static nse_nsock_udata *check_nsock_udata (lua_State *L, int idx, bool open)
if (nu->source_addr.ss_family != AF_UNSPEC) {
nsock_iod_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
} else if (0 == o.SourceSockAddr(&ss, &sslen)) {
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
if (ss.ss_family == AF_INET)
sslen = sizeof(struct sockaddr_in);
#if HAVE_IPV6
else if (ss.ss_family == AF_INET6)
sslen = sizeof(struct sockaddr_in6);
#endif
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
}
if (o.ipoptionslen)
@ -548,6 +556,14 @@ static int connect (lua_State *L, int status, lua_KContext ctx)
if (nu->source_addr.ss_family != AF_UNSPEC) {
nsock_iod_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
} else if (0 == o.SourceSockAddr(&ss, &sslen)) {
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
if (ss.ss_family == AF_INET)
sslen = sizeof(struct sockaddr_in);
#if HAVE_IPV6
else if (ss.ss_family == AF_INET6)
sslen = sizeof(struct sockaddr_in6);
#endif
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
}
if (o.ipoptionslen)

View file

@ -434,6 +434,14 @@ static void init_socket(int sd, const HostScanStats *hss, UltraScanInfo *USI) {
#endif
if (!bind_failed && 0 == o.SourceSockAddr(&ss, &sslen)) {
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
if (ss.ss_family == AF_INET)
sslen = sizeof(struct sockaddr_in);
#if HAVE_IPV6
else if (ss.ss_family == AF_INET6)
sslen = sizeof(struct sockaddr_in6);
#endif
if (::bind(sd, (struct sockaddr*)&ss, sslen) != 0) {
error("%s: Problem binding source address (%s), errno: %d", __func__, inet_socktop_safe(&ss), socket_errno());
perror("bind");

View file

@ -2137,6 +2137,14 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
fatal("Failed to allocate Nsock I/O descriptor in %s()", __func__);
}
if (0 == svc->target->SourceSockAddr(&ss, &ss_len)) {
// Use the exact protocol-specific length. Some platforms (e.g. FreeBSD)
// reject sizeof(sockaddr_storage) passed to bind() with EINVAL.
if (ss.ss_family == AF_INET)
ss_len = sizeof(struct sockaddr_in);
#if HAVE_IPV6
else if (ss.ss_family == AF_INET6)
ss_len = sizeof(struct sockaddr_in6);
#endif
nsock_iod_set_localaddr(svc->niod, &ss, ss_len);
}
if (o.ipoptionslen)