diff --git a/nsock/include/nsock.h b/nsock/include/nsock.h index 522b31d..6cb103b 100644 --- a/nsock/include/nsock.h +++ b/nsock/include/nsock.h @@ -449,7 +449,7 @@ int nsock_iod_set_ttl(nsock_iod nsi, int ttl); /* Sets connection lingering options to apply before connect(). It makes a copy * of the options, so you can free() yours if necessary. This copy is freed * when the iod is destroyed */ -int nsock_iod_set_linger(nsock_iod nsi, struct linger* lingeropts); +int nsock_iod_set_linger(nsock_iod nsi, struct linger lingeropts); /* Returns that host/port/protocol information for the last communication (or * comm. attempt) this nsi has been involved with. By "involved" with I mean diff --git a/nsock/src/nsock_internal.h b/nsock/src/nsock_internal.h index 34bae36..3c1da41 100644 --- a/nsock/src/nsock_internal.h +++ b/nsock/src/nsock_internal.h @@ -298,7 +298,8 @@ struct niod { int ttl; /* structure used to trigger connection lingering */ - struct linger *lingeropts; + struct linger lingeropts; + int lingeropts_set; /* Pointer to mspcap struct (used only if pcap support is included) */ void *pcap; diff --git a/nsock/src/nsock_iod.c b/nsock/src/nsock_iod.c index 8090a20..6c4c8d1 100644 --- a/nsock/src/nsock_iod.c +++ b/nsock/src/nsock_iod.c @@ -137,7 +137,7 @@ nsock_iod nsock_iod_new2(nsock_pool nsockp, int sd, void *userdata) { nsi->ipoptslen = 0; nsi->ttl = -1; - nsi->lingeropts = NULL; + nsi->lingeropts_set = 0; #if HAVE_OPENSSL nsi->ssl_session = NULL; @@ -268,11 +268,6 @@ void nsock_iod_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) if (nsi->ipoptslen) free(nsi->ipopts); - if (nsi->lingeropts) { - free(nsi->lingeropts); - nsi->lingeropts = NULL; - } - #if HAVE_PCAP if (nsi->pcap){ mspcap *mp = (mspcap *)nsi->pcap; @@ -424,14 +419,12 @@ int nsock_iod_set_ttl(nsock_iod iod, int ttl) { /* Sets connection lingering options to apply before connect(). It makes a copy * of the options, so you can free() yours if necessary. This copy is freed * when the iod is destroyed */ -int nsock_iod_set_linger(nsock_iod nsi, struct linger* lingeropts) +int nsock_iod_set_linger(nsock_iod nsi, struct linger lingeropts_arg) { struct niod *iod = (struct niod *)nsi; - assert(iod); - - iod->lingeropts = safe_malloc(sizeof(struct linger)); - memcpy(iod->lingeropts, lingeropts, sizeof(struct linger)); + iod->lingeropts = lingeropts_arg; + iod->lingeropts_set = 1; return 0; } diff --git a/scan_engine_connect.cc b/scan_engine_connect.cc index cd831a7..571c16f 100644 --- a/scan_engine_connect.cc +++ b/scan_engine_connect.cc @@ -395,7 +395,7 @@ UltraProbe *sendConnectScanProbe(UltraScanInfo *USI, HostScanStats *hss, struct linger l; l.l_onoff = 1; l.l_linger = 0; - nsock_iod_set_linger(CP->sock_nsi, &l); + nsock_iod_set_linger(CP->sock_nsi, l); /* Spoof the source IP address. The following is copied from l_connect from nse_nsock.cc. */