Previous proposal is good, however i2m() does not always return bytes
i2m()
bytes
As a consequence, this will work better
def get_field_bytes(pkt, name): fld, val = pkt.getfield_and_val(name) return fld.addfield(pkt, b"", val)