Nmap Development mailing list archives

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


From: "Luis M." <luis.mgarc () gmail com>
Date: Tue, 07 Jul 2009 19:09:12 +0200

David Fifield wrote:
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

  

Yes, that makes sense. I enclose another patch. It uses function
udp_port2payload(), that can be reused, while keeping the original
behavior in get_udp_payload(). Let me know what you think.

Regards,

Luis.


Index: payload.cc
===================================================================
--- payload.cc  (revision 14088)
+++ payload.cc  (working copy)
@@ -92,6 +92,7 @@
 #include "NmapOps.h"
 
 #include "nbase.h"
+#include "payload.h"
 
 extern NmapOps o;
 
@@ -131,18 +132,28 @@
 
 static const char payload_null[] = "";
 
+
 /* Get a payload appropriate for the given UDP port. If --data-length was used,
    returns the global random payload. Otherwise, for certain selected ports a
    payload is returned, and for others a zero-length payload is returned. The
    length is returned through the length pointer. */
 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;
   }
+  else
+    return udp_port2payload(dport, length);
+}
 
+
+/* Get a payload appropriate for the given UDP port. For certain selected 
+   ports a payload is returned, and for others a zero-length payload is 
+   returned. The length is returned through the length pointer.*/
+const char *udp_port2payload(u16 dport, size_t *length){
+  const char *payload;
+  
 #define SET_PAYLOAD(p) do { *length = sizeof(p) - 1; payload = (p); } while (0)
 
   switch (dport) {
@@ -172,4 +183,6 @@
   }
 
   return payload;
+    
 }
+
Index: payload.h
===================================================================
--- payload.h   (revision 14088)
+++ payload.h   (working copy)
@@ -90,3 +90,4 @@
 /* $Id$ */
 
 const char *get_udp_payload(u16 dport, size_t *length);
+const char *udp_port2payload(u16 dport, size_t *length);

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

Current thread: