dpkt icon indicating copy to clipboard operation
dpkt copied to clipboard

Calculate length automatically when packing UDP with upper layers

Open wmnsk opened this issue 8 years ago • 1 comments

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 :-)

wmnsk avatar Jan 17 '17 08:01 wmnsk

I found manual calculation is also used in examples/dhcprequest.py. We need to be sure of that when addressing this issue.

wmnsk avatar Jan 17 '17 09:01 wmnsk