Nmap Development mailing list archives

Re: [PATCH] Make new UDP-payload code reusable.


From: David Fifield <david () bamsoftware com>
Date: Tue, 7 Jul 2009 10:42:48 -0600

On Tue, Jul 07, 2009 at 06:02:30PM +0200, Luis M. wrote:
I've been having a look at David's new UDP-payload code and I've seen
that it depends on the NmapOps class so the code is not reusable by
other apps. The thing is that at some point I would like to include that
functionality to nping. For that, the best thing would be to move
UDP-payload-related code to nbase (same thing Fyodor and I are planning
to do with many other functions that nmap and nping share).

So the thing is that function get_udp_payload() has this:

const char *get_udp_payload(u16 dport, size_t *length) {
  const char *payload;

  if (o.extra_payload_length > 0) {
    *length = o.extra_payload_length;
    return o.extra_payload;
  }

In my opinion, it should be the caller's responsibility to ensure that
the user has not specified a custom payload. I've checked which parts of
nmap actually call get_udp_payload() and I've found that only
sendIPScanProbe() uses it. Moving that if sentence to sendIPScanProbe()
is trivial and should make get_udp_payload() reusable by other apps so
we can move it to nbase at some point.

If you're going to do that, I would prefer another layer of abstraction
in order to keep the calling code simple. In other words, I want a
function like get_udp_payload that does both 1) check if
o.extra_payload_length is set, and 2) looks up a payload if it is not.
So I would prefer, rather than moving part of the function into the
caller, rather to factor the port-specific payload lookup into its own
function, which get_udp_payload would call.

The function that checks o.extra_payload_length would be Nmap-specific,
and the sub-function could be shared between Nmap and Nping.

David Fifield

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: