I am trying to build LDPHello packets, but I am not able to add optional parameter like IPv4 Transport layer using scapy.
I have done this:
ip = IP(src=src_ipv4, dst= '224.0.0.2', proto=17, ttl=1)
udp = UDP(sport=646, dport=646)
hello = LDPHello(params=[180,0,0,0,0,"2.2.2.2",0])
packet = ip / udp / hello
Which gives me output like:
###[ IP ]###
version = 4
ihl = 5
tos = 0x0
len = 54
id = 1
flags =
frag = 0
ttl = 1
proto = udp
chksum = 0x6c44
src = 10.110.99.2
dst = 224.0.0.2
\options \
###[ UDP ]###
sport = 646
dport = 646
len = 34
chksum = 0xa34c
###[ LDP ]###
version = 1
len = 22
id = 2.2.2.2
space = 0
###[ LDPHello ]###
u = 0
type = 256
len = 12
id = 0
params = [180, 0, 0]
By LDPHello Definition from scapy:
class LDPHello(_LDP_Packet):
name = "LDPHello"
fields_desc = [BitField("u", 0, 1),
BitField("type", 0x0100, 15),
ShortField("len", None),
IntField("id", 0),
CommonHelloTLVField("params", [180, 0, 0])]
After CommonHelloTLVField
there is no field where we can add optional parameter like IPv4 transport Address.
While by RFC the total data structure is like:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|0| Hello (0x0100) | Message Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Message ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Common Hello Parameters TLV |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Optional Parameters |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
I don't know how to do get output like:Contains IPv4 Transport Layer