dpkt
dpkt copied to clipboard
Calculate length automatically when packing UDP with upper layers
Hi,
When I was testing creating RADIUS packet with PR#320, I found UDP instance didn't add length of its .data to its .ulen automatically.
As shown in the line 99 and 105 in my test code snippet, we can set the appropriate value in the length field manually, but it's better if we can avoid it, isn't it?
I haven't tested yet but adding this method under the UDP class will fix this issue, I guess. If it doesn't matter, I'm willing to write codes, test it and open PR.
def pack_hdr(self):
self.ulen = self.__hdr_len__ + len(self.data)
Please advise :-)
I found manual calculation is also used in examples/dhcprequest.py. We need to be sure of that when addressing this issue.