Nmap Development mailing list archives
Re: [NSE] firewalk.nse updated
From: Henri Doreau <henri.doreau () gmail com>
Date: Tue, 2 Nov 2010 21:15:03 +0100
2010/9/28 David Fifield <david () bamsoftware com>:
I want to suggest a different structure. Since you handle both TCP and UDP, many of the functions have the same if/else structure: local function func(proto) if proto == IPPROTO_TCP then ... elseif proto == IPPROTO_UDP then ... end end The problem here is that when someone adds a new protocol or makes a change in one place, they have to remember to change or at least check all the if/elses in the file. You can centralize the information better using "protocol objects" that have a list of all their functions. tcp_funcs = { func = function() ... end, -- More functions... } udp_funcs = { func = function() ... end, -- More functions... } protos = { tcp = tcp_funcs, udp = udp_funcs, } Then you would make calls like protos[proto].func() And of course you can cache protos[proto] if the protocol stays the same throughout the script execution.
Hello, I've followed David's nice advice about firewalk.nse. So please find attached the patch for this refactoring. Functions that depend of a given layer 4 protocol are now in separate arrays, broken down per protocol, and it should be easier to support new protocols. Regards -- Henri Doreau
Attachment:
firewalk.diff
Description:
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Re: [NSE] firewalk.nse updated Henri Doreau (Oct 04)
- <Possible follow-ups>
- Re: [NSE] firewalk.nse updated Henri Doreau (Nov 02)
- Re: [NSE] firewalk.nse updated David Fifield (Nov 05)