diff -Nraupb nmap-4.10-orig/output.cc nmap-4.10-majek/output.cc --- nmap-4.10-orig/output.cc 2006-06-01 01:01:25.000000000 +0200 +++ nmap-4.10-majek/output.cc 2006-06-14 00:37:48.000000000 +0200 @@ -378,7 +378,7 @@ void printportoutput(Target *currenths, int i; int first = 1; struct protoent *proto; - Port *current; + Port *current, *currtcp, *currudp; char hostname[1200]; struct serviceDeductions sd; NmapOutputTable *Tbl = NULL; @@ -502,8 +502,15 @@ void printportoutput(Target *currenths, } } } else { + currtcp=NULL; + currudp=NULL; current = NULL; - while( (current=plist->nextPort(current, TCPANDUDP, 0))!=NULL ) { + while( (current = plist->nextPortNumSorted(currtcp,currudp, 0)) ) { + if(current->proto == IPPROTO_TCP) + currtcp = current; + else + currudp = current; + if (!plist->isIgnoredState(current->state)) { if (!first) log_write(LOG_MACHINE,", "); else first = 0; diff -Nraupb nmap-4.10-orig/portlist.cc nmap-4.10-majek/portlist.cc --- nmap-4.10-orig/portlist.cc 2006-05-16 00:43:17.000000000 +0200 +++ nmap-4.10-majek/portlist.cc 2006-06-14 00:37:48.000000000 +0200 @@ -592,6 +592,20 @@ Port *PortList::nextPort(Port *afterthis return(NULL); } +Port *PortList::nextPortNumSorted(Port *afterthisporttcp,Port *afterthisportudp, int allowed_state) { + Port *nxttcp = nextPort(afterthisporttcp, IPPROTO_TCP, allowed_state); + Port *nxtudp = nextPort(afterthisportudp, IPPROTO_UDP, allowed_state); + if(!nxtudp) + return(nxttcp); + if(!nxttcp) + return(nxtudp); + + if(nxtudp->portno < nxttcp->portno) + return(nxtudp); + else + return(nxttcp); +} + Port *PortList::getPortEntry(u16 portno, u8 protocol) { int proto = INPROTO2PORTLISTPROTO(protocol); int mapped_pno; @@ -633,6 +647,17 @@ void PortList::setPortEntry(u16 portno, port_list[proto][mapped_pno] = port; } +/* Just free memory used by PortList::port_map[]. Should be done somewhere + * before closing nmap. */ +void PortList::freePortMap(){ + int proto; + for(proto=0; proto < PORTLIST_PROTO_MAX; proto++) + if(port_map[proto]){ + free(port_map[proto]); + port_map[proto] = NULL; + } +} + u16 *PortList::port_map[PORTLIST_PROTO_MAX]; int PortList::port_list_count[PORTLIST_PROTO_MAX]; diff -Nraupb nmap-4.10-orig/portlist.h nmap-4.10-majek/portlist.h --- nmap-4.10-orig/portlist.h 2006-05-16 00:43:17.000000000 +0200 +++ nmap-4.10-majek/portlist.h 2006-06-14 00:37:48.000000000 +0200 @@ -266,6 +266,9 @@ class PortList { /* Set ports that will be scanned for each protocol. This function * must be called before any PortList object will be created. */ static void initializePortMap(int protocol, u16 *ports, int portcount); + /* Free memory used by port_map. It should be done somewhere before quitting*/ + static void PortList::freePortMap(); + /* Add a new port to this list. If the state has changed, it is OK to call this function to effect the change */ int addPort(u16 portno, u8 protocol, char *owner, int state); @@ -288,6 +291,9 @@ class PortList { Port *nextPort(Port *afterthisport, int allowed_protocol, int allowed_state); + Port *nextPortNumSorted(Port *afterthisporttcp, + Port *afterthisportudp, int allowed_state); + /* Get Port structure from PortList structure.*/ Port *getPortEntry(u16 portno, u8 protocol); /* Set Port structure to PortList structure.*/