UDP Options with Scapy

I am working on an implementation of the UDP Options draft at work, this morning I got the udp_input side of processing building. This needs to be test and gotten working before moving on, before setting up some VMs to test this I need a way to generate packets with UDP Option data appended.

This seemed like a great occasion to use go a little more. There is the gopacket library from google that provides raw packet stuff.


I tried for ages to put together a send example that didn't depend on linux. Eventually I got to the point where I could form crazy malformed arp packets. I got to the point of generating the above traces in wireshark , for some reason go was sticking 16 bytes into the address fields and creating madness. You will note in the above arp packet that the length is much longer, that is because go is appending some extra data for shits and giggles.

Giving up on go I had a look at the python libraries for generating packets, they are all about the same level of insanity. The pathspider project has some test probes for UDP Options using scapy .

pathspider is a lot of stuff to pull in to generate UDP datagrams, I extracted out the relevant stuff to use with scapy directly:

from scapy.all import IP
from scapy.all import UDP 
from scapy.all import *

if __name__ == "__main__":

    ip = IP(src="", dst="")
    udp = UDP(sport=2600, dport=2600)

    pkt = ip/udp/"Hello world"

    pkt.getlayer(1).len = len(pkt.getlayer(1)) #force UDP len

You can add the numbers together to find that the extra option space is include, you can also see the 01 01 01 00 bytes at the end of the packet which are the options I add.

Reading: Gun Machine, The Difference Engine