MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / decodeIPQueryPacket

Method decodeIPQueryPacket

pager_lib/nmb/base.py:149–177  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

147 # Contributed by Jason Anderson
148 #
149 def decodeIPQueryPacket(self, data):
150 if len(data) < self.HEADER_STRUCT_SIZE:
151 raise Exception
152
153 trn_id, code, question_count, answer_count, authority_count, additional_count = struct.unpack(self.HEADER_STRUCT_FORMAT, data[:self.HEADER_STRUCT_SIZE])
154
155 is_response = bool((code >> 15) & 0x01)
156 opcode = (code >> 11) & 0x0F
157 flags = (code >> 4) & 0x7F
158 rcode = code & 0x0F
159
160 try:
161 numnames = data[self.HEADER_STRUCT_SIZE + 44]
162
163 if numnames > 0:
164 ret = [ ]
165 offset = self.HEADER_STRUCT_SIZE + 45
166
167 for i in range(0, numnames):
168 mynme = data[offset:offset + 15]
169 mynme = mynme.strip()
170 ret.append(( str(mynme, 'ascii'), data[offset+15] ))
171 offset += 18
172
173 return trn_id, ret
174 except IndexError:
175 pass
176
177 return trn_id, None
178
179 #
180 # Contributed by Jason Anderson

Callers 2

datagramReceivedMethod · 0.80
_pollForQueryPacketMethod · 0.80

Calls 2

rangeFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected