diff --git a/nmap_rpc.cc b/nmap_rpc.cc index a42a8d87c..6d0aa6fc1 100644 --- a/nmap_rpc.cc +++ b/nmap_rpc.cc @@ -317,7 +317,7 @@ int send_rpc_query(Target *target_host, unsigned short portno, /* Simply send this sucker we have created ... */ do { if (o.debugging > 1) - hdump((unsigned char *) rpch, sizeof(struct rpc_hdr)); + nmap_hexdump((unsigned char *) rpch, sizeof(struct rpc_hdr)); res = sendto(udp_rpc_socket, (char *)rpch, sizeof(struct rpc_hdr), 0, (struct sockaddr *) &sock, socklen); if (res == -1) diff --git a/scan_engine.cc b/scan_engine.cc index 5a0936bec..086d6d127 100644 --- a/scan_engine.cc +++ b/scan_engine.cc @@ -4264,9 +4264,9 @@ static bool get_pcap_result(UltraScanInfo *USI, struct timeval *stime) { break; default: - error("Unexpected ICMP type/code 3/%d unreachable packet:", + error("Unexpected ICMP type/code 3/%d unreachable packet:\n", icmp->icmp_code); - hdump((unsigned char *)icmp, ntohs(ip->ip_len) - + nmap_hexdump((unsigned char *)icmp, ntohs(ip->ip_len) - sizeof(struct ip)); break; } diff --git a/tcpip.cc b/tcpip.cc index d9cc25eda..235d62841 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -2223,7 +2223,7 @@ if (!pd) fatal("NULL packet device passed to %s", __func__); fatal("FATAL: %s: bogus caplen from libpcap (%d) on interface type %d", __func__, head.caplen, datalink); } error("FATAL: Unknown datalink type (%d). Caplen: %d; Packet:", datalink, head.caplen); - lamont_hdump(p, head.caplen); + nmap_hexdump((unsigned char*)p, head.caplen); exit(1); } diff --git a/utils.cc b/utils.cc index 372f26c9c..01cdbb647 100644 --- a/utils.cc +++ b/utils.cc @@ -137,89 +137,18 @@ int wildtest(char *wild, char *test) { } +/* Wrapper for nbase function hexdump() */ +void nmap_hexdump(unsigned char *cp, unsigned int length){ - -/* Hex dump */ -void hdump(unsigned char *packet, unsigned int len) { -unsigned int i=0, j=0; - -log_write(LOG_PLAIN, "Here it is:\n"); - -for(i=0; i < len; i++){ - j = (unsigned) (packet[i]); - log_write(LOG_PLAIN, "%-2X ", j); - if (!((i+1)%16)) - log_write(LOG_PLAIN, "\n"); - else if (!((i+1)%4)) - log_write(LOG_PLAIN, " "); -} -log_write(LOG_PLAIN, "\n"); + char *string=NULL; + string = hexdump((u8*)cp, length); + if(string){ + log_write(LOG_PLAIN, "%s", string); + free(string); + } + return; } -/* A better version of hdump, from Lamont Granquist. Modified slightly - by Fyodor (fyodor@insecure.org) */ -void lamont_hdump(char *cp, unsigned int length) { - - /* stolen from tcpdump, then kludged extensively */ - - static const char asciify[] = "................................ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................."; - - const u_short *sp; - const u_char *ap; - unsigned char *bp = (unsigned char *) cp; - u_int i, j; - int nshorts, nshorts2; - int padding; - - log_write(LOG_PLAIN, "\n\t"); - padding = 0; - sp = (u_short *)bp; - ap = (u_char *)bp; - nshorts = (u_int) length / sizeof(u_short); - nshorts2 = (u_int) length / sizeof(u_short); - i = 0; - j = 0; - while(1) { - while (--nshorts >= 0) { - log_write(LOG_PLAIN, " %04x", ntohs(*sp)); - sp++; - if ((++i % 8) == 0) - break; - } - if (nshorts < 0) { - if ((length & 1) && (((i-1) % 8) != 0)) { - log_write(LOG_PLAIN, " %02x ", *(u_char *)sp); - padding++; - } - nshorts = (8 - (nshorts2 - nshorts)); - while(--nshorts >= 0) { - log_write(LOG_PLAIN, " "); - } - if (!padding) log_write(LOG_PLAIN, " "); - } - log_write(LOG_PLAIN, " "); - - while (--nshorts2 >= 0) { - log_write(LOG_PLAIN, "%c%c", asciify[*ap], asciify[*(ap+1)]); - ap += 2; - if ((++j % 8) == 0) { - log_write(LOG_PLAIN, "\n\t"); - break; - } - } - if (nshorts2 < 0) { - if ((length & 1) && (((j-1) % 8) != 0)) { - log_write(LOG_PLAIN, "%c", asciify[*ap]); - } - break; - } - } - if ((length & 1) && (((i-1) % 8) == 0)) { - log_write(LOG_PLAIN, " %02x", *(u_char *)sp); - log_write(LOG_PLAIN, " %c", asciify[*ap]); - } - log_write(LOG_PLAIN, "\n"); -} #ifndef HAVE_STRERROR char *strerror(int errnum) { diff --git a/utils.h b/utils.h index b5aec3da4..a687d44be 100644 --- a/utils.h +++ b/utils.h @@ -173,8 +173,7 @@ template T box(T bmin, T bmax, T bnum) { int wildtest(char *wild, char *test); -void hdump(unsigned char *packet, unsigned int len); -void lamont_hdump(char *cp, unsigned int length); +void nmap_hexdump(unsigned char *cp, unsigned int length); /* Compare a canonical option name (e.g. "max-scan-delay") with a user-generated option such as "max_scan_delay" and returns 0 if the