diff --git a/bin/tomcat.exe b/bin/tomcat.exe index 1aed9d1..5d8a520 100644 Binary files a/bin/tomcat.exe and b/bin/tomcat.exe differ diff --git a/src/scan.cc b/src/scan.cc index f6cfeae..596b35d 100644 --- a/src/scan.cc +++ b/src/scan.cc @@ -163,20 +163,19 @@ int ping_host(char *host, int timeout, int *latency, char *info) { if (hIcmpFile == INVALID_HANDLE_VALUE) { if (DEBUG) { fprintf(stderr, "\tUnable to open handle.\n"); - fprintf(stderr, "IcmpCreatefile returned error: %ld\n", GetLastError() ); + fprintf(stderr, "IcmpCreatefile returned error: %ld\n", GetLastError()); } return 1; } ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); ReplyBuffer = (VOID*) malloc(ReplySize); - if (ReplyBuffer == NULL) { - if (DEBUG) fprintf(stderr, "\tUnable to allocate memory\n"); - return 1; - } dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData), NULL, ReplyBuffer, ReplySize, timeout); + + int return_code = 0; + if (dwRetVal != 0) { PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer; struct in_addr ReplyAddr; @@ -184,12 +183,14 @@ int ping_host(char *host, int timeout, int *latency, char *info) { *latency = pEchoReply->RoundTripTime; reverse_dns_lookup(info, host); - } - else { + } else { /* ICMP echo request failed */ - return 1; + + return_code = 1;; } - return 0; + + free(ReplyBuffer); + return return_code; } int send_arp(char *dest, char *dotted) { @@ -209,6 +210,10 @@ int send_arp(char *dest, char *dotted) { dwRetVal = SendARP(DestIp, SrcIp, &MacAddr, &PhysAddrLen); + if (dwRetVal == ERROR_BAD_NET_NAME) { + if (DEBUG) fprintf(stderr, "Error: Cannot send Arp request to a network on different subnet\n"); + } + if (dwRetVal == NO_ERROR) { bPhysAddr = (BYTE *) & MacAddr; if (PhysAddrLen) { @@ -241,7 +246,7 @@ void display_ping_result(char *host, char *result, int latency) { if (!send_arp(mac, host)) { fprintf(stdout, "\tMAC: %s", mac); } - */ + */ fprintf(stdout, "\n"); } diff --git a/src/server.cc b/src/server.cc index d62da80..2c14a64 100644 --- a/src/server.cc +++ b/src/server.cc @@ -79,7 +79,7 @@ int server(char *port, char *filename, int keep_listening) { if (keep_listening) { - while (1) { + for (;;) { ClientSocket = accept(ListenSocket, NULL, NULL); if (ClientSocket == INVALID_SOCKET) { diff --git a/src/tomcat.cc b/src/tomcat.cc index 955c642..1c4add7 100644 --- a/src/tomcat.cc +++ b/src/tomcat.cc @@ -24,6 +24,7 @@ TomCat::TomCat(char *filename) { } TomCat::~TomCat() { + free(filename); close_pipes(pipes); _setmode(fileno(stdout), _O_TEXT); } @@ -81,7 +82,7 @@ int TomCat::Process(SOCKET ClientSocket) { memset(sendbuf, '\0', DEFAULT_BUFLEN); /* Main run-forever loop: */ - while(1) { + for(;;) { FD_ZERO(&readfds); FD_ZERO(&writefds);