From 852ad9440da8159ed60bde5290f2bf384188545a Mon Sep 17 00:00:00 2001 From: david Date: Wed, 11 Aug 2010 14:39:42 +0000 Subject: [PATCH] Improve indentation and comments in init_socket. --- scan_engine.cc | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/scan_engine.cc b/scan_engine.cc index 3210aa833..016c7306a 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -2951,34 +2951,29 @@ static void ultrascan_port_probe_update(UltraScanInfo *USI, HostScanStats *hss, -/* We set the socket lingering so we will RST connection instead of wasting - bandwidth with the four step close */ +/* Set the socket lingering so we will RST connections instead of wasting + bandwidth with the four-step close. Set the source address if needed. */ static void init_socket(int sd) { + static int bind_failed = 0; struct linger l; - int res; - static int bind_failed=0; struct sockaddr_storage ss; size_t sslen; l.l_onoff = 1; l.l_linger = 0; - if (setsockopt(sd, SOL_SOCKET, SO_LINGER, (const char *) &l, sizeof(struct linger))) - { - error("Problem setting socket SO_LINGER, errno: %d", socket_errno()); - perror("setsockopt"); - } - if (o.spoofsource && !bind_failed) - { - o.SourceSockAddr(&ss, &sslen); - res=bind(sd, (struct sockaddr*)&ss, sslen); - if (res<0) - { - error("%s: Problem binding source address (%s), errno: %d", __func__, inet_socktop(&ss), socket_errno()); - perror("bind"); - bind_failed=1; - } + if (setsockopt(sd, SOL_SOCKET, SO_LINGER, (const char *) &l, sizeof(l)) != 0) { + error("Problem setting socket SO_LINGER, errno: %d", socket_errno()); + perror("setsockopt"); + } + if (o.spoofsource && !bind_failed) { + o.SourceSockAddr(&ss, &sslen); + if (bind(sd, (struct sockaddr*)&ss, sslen) != 0) { + error("%s: Problem binding source address (%s), errno: %d", __func__, inet_socktop(&ss), socket_errno()); + perror("bind"); + bind_failed = 1; } + } } /* If this is NOT a ping probe, set pingseq to 0. Otherwise it will be the