Nmap Development mailing list archives
[PATCH] Use switch() instead of if/else if in tcpip.cc
From: "Kris Katterjohn" <kjak () ispwest com>
Date: Tue, 21 Feb 2006 11:22:41 -0800
This uses a switch statement instead of multiple if/else if statements which often seems to be, at least with gcc/g++, better performance-wise. On my box it slightly decreases the nmap binary size: -rwxr-xr-x 1 kjak root 1963697 2006-02-21 13:08 nmap* -rwxr-xr-x 1 kjak root 1963785 2006-02-21 12:33 nmap.orig* Thanks, Kris Katterjohn --- tcpip.cc.orig 2006-02-21 13:05:49.000000000 -0600 +++ tcpip.cc 2006-02-21 13:07:38.000000000 -0600 @@ -527,40 +527,42 @@ case 0: strcpy(icmptype, "Echo reply"); break; case 3: - if (ping->code == 0) - strcpy(icmptype, "network unreachable"); - else if (ping->code == 1) - strcpy(icmptype, "host unreachable"); - else if (ping->code == 2) - strcpy(icmptype, "protocol unreachable"); - else if (ping->code == 3) - strcpy(icmptype, "port unreachable"); - else if (ping->code == 4) - strcpy(icmptype, "fragmentation required"); - else if (ping->code == 5) - strcpy(icmptype, "source route failed"); - else if (ping->code == 6) - strcpy(icmptype, "destination network unknown"); - else if (ping->code == 7) - strcpy(icmptype, "destination host unknown"); - else if (ping->code == 8) - strcpy(icmptype, "source host isolated"); - else if (ping->code == 9) - strcpy(icmptype, "destination network administratively prohibited"); - else if (ping->code == 10) - strcpy(icmptype, "destination host administratively prohibited"); - else if (ping->code == 11) - strcpy(icmptype, "network unreachable for TOS"); - else if (ping->code == 12) - strcpy(icmptype, "host unreachable for TOS"); - else if (ping->code == 13) - strcpy(icmptype, "communication administratively prohibited by filtering"); - else if (ping->code == 14) - strcpy(icmptype, "host precedence violation"); - else if (ping->code == 15) - strcpy(icmptype, "precedence cutoff in effect"); - else - strcpy(icmptype, "unknown unreachable code"); + switch (ping->code) { + case 0: + strcpy(icmptype, "network unreachable"); break; + case 1: + strcpy(icmptype, "host unreachable"); break; + case 2: + strcpy(icmptype, "protocol unreachable"); break; + case 3: + strcpy(icmptype, "port unreachable"); break; + case 4: + strcpy(icmptype, "fragmentation required"); break; + case 5: + strcpy(icmptype, "source route failed"); break; + case 6: + strcpy(icmptype, "destination network unknown"); break; + case 7: + strcpy(icmptype, "destination host unknown"); break; + case 8: + strcpy(icmptype, "source host isolated"); break; + case 9: + strcpy(icmptype, "destination network administratively prohibited"); break; + case 10: + strcpy(icmptype, "destination host administratively prohibited"); break; + case 11: + strcpy(icmptype, "network unreachable for TOS"); break; + case 12: + strcpy(icmptype, "host unreachable for TOS"); break; + case 13: + strcpy(icmptype, "communication administratively prohibited by filtering"); break; + case 14: + strcpy(icmptype, "host precedence violation"); break; + case 15: + strcpy(icmptype, "precedence cutoff in effect"); break; + default: + strcpy(icmptype, "unknown unreachable code"); break; + } break; case 4: strcpy(icmptype, "source quench"); break; _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev
Current thread:
- [PATCH] Use switch() instead of if/else if in tcpip.cc Kris Katterjohn (Feb 21)
- Re: [PATCH] Use switch() instead of if/else if in tcpip.cc Fyodor (Feb 21)