) query_record = Struct( "query_record", DnsStringAdapter( RepeatUntil(lambda obj, ctx: obj == "", PascalString("name"))), dns_record_type, dns_record_class, ) rdata = Field("rdata", lambda ctx: ctx.rdata_length) resource_record = Struct( "resource_record", CString("name", terminators=b"\xc0\x00"), Padding(1), dns_record_type, dns_record_class, UBInt32("ttl"), UBInt16("rdata_length"), IfThenElse("data", lambda ctx: ctx.type == "IPv4", IpAddressAdapter(rdata), rdata)) dns = Struct( "dns", UBInt16("id"), BitStruct( "flags", Enum( Bit("type"), QUERY=0, RESPONSE=1, ), Enum( Nibble("opcode"), STANDARD_QUERY=0,
def ProtoAddress(name): return IfThenElse( name, lambda ctx: ctx.protocol_type == "IP", IpAddressAdapter(Field("data", lambda ctx: ctx.protoaddr_length)), Field("data", lambda ctx: ctx.protoaddr_length))
), dns_record_type, dns_record_class, ) rdata = Field("rdata", lambda ctx: ctx.rdata_length) resource_record = Struct("resource_record", CString("name", terminators = "\xc0\x00"), Padding(1), dns_record_type, dns_record_class, UBInt32("ttl"), UBInt16("rdata_length"), IfThenElse("data", lambda ctx: ctx.type == "IPv4", IpAddressAdapter(rdata), rdata ) ) dns = Struct("dns", UBInt16("id"), BitStruct("flags", Enum(Bit("type"), QUERY = 0, RESPONSE = 1, ), Enum(Nibble("opcode"), STANDARD_QUERY = 0, INVERSE_QUERY = 1, SERVER_STATUS_REQUEST = 2,