diff -u3 -Hb -r nmap-3.59ALPHA3\main.cc .\main.cc --- nmap-3.59ALPHA3\main.cc Fri Mar 12 03:59:04 2004 +++ .\main.cc Mon May 31 21:59:12 2004 @@ -180,10 +180,12 @@ #if HAVE_SIGNAL signal(SIGINT, sigdie); signal(SIGTERM, sigdie); +#ifndef WIN32 signal(SIGHUP, sigdie); signal(SIGCHLD, reaper); #endif +#endif /* First we figure out whether the name nmap is called as qualifies it for interactive mode treatment */ @@ -335,7 +337,9 @@ #if HAVE_SIGNAL signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); +#ifndef WIN32 signal(SIGHUP, SIG_DFL); +#endif signal(SIGSEGV, SIG_DFL); #endif diff -u3 -Hb -r nmap-3.59ALPHA3\mswin32\winip\snmp95.cpp .\mswin32\winip\snmp95.cpp --- nmap-3.59ALPHA3\mswin32\winip\snmp95.cpp Tue Aug 27 23:07:39 2002 +++ .\mswin32\winip\snmp95.cpp Sun Nov 30 02:20:57 2003 @@ -141,7 +141,7 @@ static bool Populate() { -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) if(populated) return szAddrtable != 0; populated = true; diff -u3 -Hb -r nmap-3.59ALPHA3\mswin32\winip\snmpapi.cpp .\mswin32\winip\snmpapi.cpp --- nmap-3.59ALPHA3\mswin32\winip\snmpapi.cpp Sun Oct 14 23:35:46 2001 +++ .\mswin32\winip\snmpapi.cpp Sat Nov 29 23:50:13 2003 @@ -26,6 +26,7 @@ #include "..\tcpip.h" #include "winip.h" #include +#include SNMPAPI SNMP_FUNC_TYPE diff -u3 -Hb -r nmap-3.59ALPHA3\nbase\nbase.h .\nbase\nbase.h --- nmap-3.59ALPHA3\nbase\nbase.h Wed Jul 07 08:08:10 2004 +++ .\nbase\nbase.h Wed Jul 07 14:14:47 2004 @@ -282,8 +282,12 @@ #define stat _stat // wtf was ms thinking? #define execve _execve + +#if !defined(__GNUC__) && !defined(__cplusplus) #define snprintf _snprintf #define vsnprintf _vsnprintf +#endif + #define strcasecmp _stricmp #define strncasecmp _strnicmp diff -u3 -Hb -r nmap-3.59ALPHA3\nbase\nbase_winconfig.h .\nbase\nbase_winconfig.h --- nmap-3.59ALPHA3\nbase\nbase_winconfig.h Fri Mar 12 03:59:04 2004 +++ .\nbase\nbase_winconfig.h Mon May 31 21:44:50 2004 @@ -123,6 +123,10 @@ #define HAVE_AF_INET6 1 #define HAVE_SOCKADDR_STORAGE 1 +#ifdef __GNUC__ +#define bzero(addr, num) __builtin_memset (addr, '\0', num) +#else #define __attribute__(x) +#endif #endif /* NBASE_WINCONFIG_H */ diff -u3 -Hb -r nmap-3.59ALPHA3\nbase\nbase_winunix.h .\nbase\nbase_winunix.h --- nmap-3.59ALPHA3\nbase\nbase_winunix.h Wed Jul 07 10:02:15 2004 +++ .\nbase\nbase_winunix.h Wed Jul 07 14:16:36 2004 @@ -92,10 +92,11 @@ // Supress winsock.h #define _WINSOCKAPI_ +#define WIN32_LEAN_AND_MEAN #include #include -/* #include // IPv6 stuff */ +#include /* IPv6 stuff */ #include #include #include @@ -115,7 +116,10 @@ typedef unsigned short u_int16_t; typedef unsigned long u_int32_t; + +#ifndef _SSIZE_T_ typedef unsigned int ssize_t; +#endif //#define HAVE_STRUCT_IP //#define HAVE_STRUCT_ICMP diff -u3 -Hb -r nmap-3.59ALPHA3\nmap.cc .\nmap.cc --- nmap-3.59ALPHA3\nmap.cc Fri Aug 20 06:42:18 2004 +++ .\nmap.cc Fri Aug 20 11:32:55 2004 @@ -864,7 +864,7 @@ } } -#if HAVE_SIGNAL +#if defined(HAVE_SIGNAL) && defined(SIGPIPE) signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE so our program doesn't crash because of it, but we really shouldn't get an unsuspected SIGPIPE */ @@ -1820,6 +1820,7 @@ fprintf(stderr, "\n[%d finished status=%d (%s)]\nnmap> ", (int) pid, status, (status == 0)? "success" : "failure"); } } +#endif void sigdie(int signo) { int abt = 0; @@ -1828,20 +1829,33 @@ case SIGINT: fprintf(stderr, "caught SIGINT signal, cleaning up\n"); break; + +#ifdef SIGTERM case SIGTERM: fprintf(stderr, "caught SIGTERM signal, cleaning up\n"); break; +#endif + +#ifdef SIGHUP case SIGHUP: fprintf(stderr, "caught SIGHUP signal, cleaning up\n"); break; +#endif + +#ifdef SIGSEGV case SIGSEGV: fprintf(stderr, "caught SIGSEGV signal, cleaning up\n"); abt = 1; break; +#endif + +#ifdef SIGBUS case SIGBUS: fprintf(stderr, "caught SIGBUS signal, cleaning up\n"); abt = 1; break; +#endif + default: fprintf(stderr, "caught signal %d, cleaning up\n", signo); abt = 1; @@ -1853,7 +1867,6 @@ exit(1); } -#endif int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) { char *dirptr; diff -u3 -Hb -r nmap-3.59ALPHA3\nmap_rpc.cc .\nmap_rpc.cc --- nmap-3.59ALPHA3\nmap_rpc.cc Thu Aug 19 10:10:40 2004 +++ .\nmap_rpc.cc Fri Aug 20 11:35:32 2004 @@ -283,13 +283,17 @@ rpch->prog_ver = htonl(31337 + (rpc_xid_base & 0xFFFFF)); if (ipproto == IPPROTO_UDP) { + int err; + /* Simply send this sucker we have created ... */ do { if (o.debugging > 1) hdump((unsigned char *) rpch, sizeof(struct rpc_hdr)); res = sendto(udp_rpc_socket, (char *)rpch, sizeof(struct rpc_hdr), 0, (struct sockaddr *) &sock, sizeof(struct sockaddr_in)); - } while(res == -1 && (socket_errno() == EINTR || socket_errno() == ENOBUFS)); + if (res < 0) + err = socket_errno(); + } while(res == -1 && (err == EINTR || err == ENOBUFS)); if (res == -1) { if (o.debugging) { gh_perror("Sendto in send_rpc_query"); diff -u3 -Hb -r nmap-3.59ALPHA3\nsock\src\nsock_connect.c .\nsock\src\nsock_connect.c --- nmap-3.59ALPHA3\nsock\src\nsock_connect.c Fri Mar 12 03:50:58 2004 +++ .\nsock\src\nsock_connect.c Fri Aug 20 11:40:40 2004 @@ -93,11 +93,18 @@ memcpy(&nse->iod->peer, ss, sslen); nse->iod->peerlen = sslen; - if ((res = connect(nse->iod->sd, (struct sockaddr *) ss, - sslen)) != -1) { - nse->event_done = 1; nse->status = NSE_STATUS_SUCCESS; - } else if (proto != IPPROTO_TCP || (socket_errno() != EINPROGRESS && socket_errno() != EAGAIN)) { - nse->event_done = 1; nse->status = NSE_STATUS_ERROR; nse->errnum = socket_errno(); + if ((res = connect(nse->iod->sd, (struct sockaddr *) ss, sslen)) != -1) { + nse->event_done = 1; + nse->status = NSE_STATUS_SUCCESS; + } + else { + int err = socket_errno(); + + if (proto != IPPROTO_TCP || (err != EINPROGRESS && err != EAGAIN)) { + nse->event_done = 1; + nse->status = NSE_STATUS_ERROR; + nse->errnum = err; + } } } } diff -u3 -Hb -r nmap-3.59ALPHA3\nsock\src\nsock_core.c .\nsock\src\nsock_core.c --- nmap-3.59ALPHA3\nsock\src\nsock_core.c Fri Mar 12 03:50:58 2004 +++ .\nsock\src\nsock_core.c Wed Jul 07 14:48:11 2004 @@ -86,6 +86,7 @@ int event_msecs; /* Msecs before an event goes off */ int combined_msecs; + int sock_err; struct timeval select_tv; struct timeval *select_tv_p; @@ -130,10 +131,10 @@ ms->mioi.results_left = select(ms->mioi.max_sd + 1, &ms->mioi.fds_results_r, &ms->mioi.fds_results_w, &ms->mioi.fds_results_x, select_tv_p); gettimeofday(&nsock_tod, NULL); /* Who knows how long select sat around for */ - } while (ms->mioi.results_left == -1 && socket_errno() == EINTR); + } while (ms->mioi.results_left == -1 && (sock_err = socket_errno()) == EINTR); - if (ms->mioi.results_left == -1 && socket_errno() != EINTR) { - ms->errnum = socket_errno(); + if (ms->mioi.results_left == -1 && sock_err != EINTR) { + ms->errnum = sock_err; return -1; } diff -u3 -Hb -r nmap-3.59ALPHA3\scan_engine.cc .\scan_engine.cc --- nmap-3.59ALPHA3\scan_engine.cc Fri Aug 20 05:07:13 2004 +++ .\scan_engine.cc Fri Aug 20 11:54:04 2004 @@ -1548,7 +1548,8 @@ ultrascan_port_update(USI, hss, probeI, PORT_OPEN, &USI->now); probe = NULL; } else { - switch(socket_errno()) { + int err = socket_errno(); + switch(err) { case EINPROGRESS: case EAGAIN: USI->gstats->CSI->watchSD(CP->sd); @@ -1556,7 +1557,7 @@ default: if (!connecterror) { connecterror = true; - fprintf(stderr, "Strange error from connect (%d):", socket_errno()); + fprintf(stderr, "Strange error from connect (%d):", err); fflush(stdout); perror(""); /*falling through intentionally*/ } diff -u3 -Hb -r nmap-3.59ALPHA3\targets.cc .\targets.cc --- nmap-3.59ALPHA3\targets.cc Fri Aug 20 05:45:12 2004 +++ .\targets.cc Fri Aug 20 12:29:27 2004 @@ -632,7 +632,7 @@ struct timeval *time, struct pingtune *pt, struct timeout_info *to, int max_sockets) { - int res,i; + int res,sock_err,i; int tmpsd; int hostnum, trynum; struct sockaddr_storage sock; @@ -682,15 +682,16 @@ #endif //HAVE_IPV6 res = connect(tqi->sockets[probe_port_num][seq],(struct sockaddr *)&sock, socklen); + sock_err = socket_errno(); - if ((res != -1 || socket_errno() == ECONNREFUSED)) { + if ((res != -1 || sock_err == ECONNREFUSED)) { /* This can happen on localhost, successful/failing connection immediately in non-blocking mode */ hostupdate(hostbatch, target, HOST_UP, 1, trynum, to, &time[seq], NULL, pt, tqi, pingstyle_connecttcp); if (tqi->maxsd == tqi->sockets[probe_port_num][seq]) tqi->maxsd--; } - else if (socket_errno() == ENETUNREACH) { + else if (sock_err == ENETUNREACH) { if (o.debugging) error("Got ENETUNREACH from sendconnecttcpquery connect()"); hostupdate(hostbatch, target, HOST_DOWN, 1, trynum, to, @@ -861,6 +862,8 @@ for (decoy = 0; decoy < o.numdecoys; decoy++) { if (ptech.icmpscan && decoy == o.decoyturn) { + int sock_err = 0; + /* FIXME: If EHOSTUNREACH (Windows does that) then we were probably unable to obtain an arp response from the machine. We should just consider the host down rather than ignoring @@ -869,15 +872,15 @@ // PacketTrace::trace(PacketTrace::SENT, (u8 *) ping, icmplen); if ((res = sendto(sd,(char *) ping,icmplen,0,(struct sockaddr *)&sock, sizeof(struct sockaddr))) != icmplen && - socket_errno() != EHOSTUNREACH + (sock_err = socket_errno()) != EHOSTUNREACH #ifdef WIN32 // Windows (correctly) returns this if we scan an address that is // known to be nonsensical (e.g. myip & mysubnetmask) - && socket_errno() != WSAEADDRNOTAVAIL + && sock_err != WSAEADDRNOTAVAIL #endif ) { fprintf(stderr, "sendto in sendpingquery returned %d (should be 8)!\n", res); - perror("sendto"); + fprintf(stderr, "sendto: %s\n", strerror(sock_err)); } } else { send_ip_raw( rawsd, &o.decoys[decoy], target->v4hostip(), o.ttl, IPPROTO_ICMP, ping, icmplen); @@ -934,13 +937,14 @@ foundsomething = 0; res2 = recv(tqi->sockets[p][seq], buf, sizeof(buf) - 1, 0); if (res2 == -1) { - switch(socket_errno()) { + int sock_err = socket_errno(); + switch(sock_err) { case ECONNREFUSED: case EAGAIN: #ifdef WIN32 // case WSAENOTCONN: // needed? this fails around here on my system #endif - if (socket_errno() == EAGAIN && o.verbose) { + if (sock_err == EAGAIN && o.verbose) { log_write(LOG_STDOUT, "Machine %s MIGHT actually be listening on probe port %d\n", hostbatch[hostindex]->targetipstr(), o.ping_synprobes[p]); } foundsomething = 1; @@ -958,7 +962,7 @@ break; default: snprintf (buf, sizeof(buf), "Strange read error from %s", hostbatch[hostindex]->targetipstr()); - perror(buf); + fprintf(stderr, "%s: %s\n", buf, strerror(sock_err)); break; } } else { diff -u3 -Hb -r nmap-3.59ALPHA3\tcpip.cc .\tcpip.cc --- nmap-3.59ALPHA3\tcpip.cc Fri Aug 20 07:53:56 2004 +++ .\tcpip.cc Fri Aug 20 12:08:52 2004 @@ -2294,10 +2294,12 @@ sd, len, inet_ntoa(sin->sin_addr), tolen); } if ((res = sendto(sd, (const char *) packet, len, flags, to, tolen)) == -1) { + int err = socket_errno(); + error("sendto in %s: sendto(%d, packet, %d, 0, %s, %d) => %s", functionname, sd, len, inet_ntoa(sin->sin_addr), tolen, - strerror(socket_errno())); - if (retries > 2 || socket_errno() == EPERM || socket_errno() == EACCES || socket_errno() == EADDRNOTAVAIL) + strerror(err)); + if (retries > 2 || err == EPERM || err == EACCES || err == EADDRNOTAVAIL) return -1; sleeptime = 15 * (1 << (2 * retries)); error("Sleeping %d seconds then retrying", sleeptime); diff -u3 -Hb -r nmap-3.59ALPHA3\tcpip.h .\tcpip.h --- nmap-3.59ALPHA3\tcpip.h Thu Aug 19 23:29:12 2004 +++ .\tcpip.h Fri Aug 20 12:10:28 2004 @@ -218,15 +218,15 @@ } #endif -#include -#include -#include - #if HAVE_SYS_SOCKIO_H #include /* SIOCGIFCONF for Solaris */ #endif #endif /* WIN32 */ +#include +#include +#include + #include "nmap_error.h" #include "utils.h" #include "nmap.h"