MCPcopy
hub / github.com/shadowsocks/shadowsocks / parse_response

Function parse_response

shadowsocks/asyncdns.py:186–224  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

184
185
186def parse_response(data):
187 try:
188 if len(data) >= 12:
189 header = parse_header(data)
190 if not header:
191 return None
192 res_id, res_qr, res_tc, res_ra, res_rcode, res_qdcount, \
193 res_ancount, res_nscount, res_arcount = header
194
195 qds = []
196 ans = []
197 offset = 12
198 for i in range(0, res_qdcount):
199 l, r = parse_record(data, offset, True)
200 offset += l
201 if r:
202 qds.append(r)
203 for i in range(0, res_ancount):
204 l, r = parse_record(data, offset)
205 offset += l
206 if r:
207 ans.append(r)
208 for i in range(0, res_nscount):
209 l, r = parse_record(data, offset)
210 offset += l
211 for i in range(0, res_arcount):
212 l, r = parse_record(data, offset)
213 offset += l
214 response = DNSResponse()
215 if qds:
216 response.hostname = qds[0][0]
217 for an in qds:
218 response.questions.append((an[1], an[2], an[3]))
219 for an in ans:
220 response.answers.append((an[1], an[2], an[3]))
221 return response
222 except Exception as e:
223 shell.print_exception(e)
224 return None
225
226
227def is_valid_hostname(hostname):

Callers 1

_handle_dataMethod · 0.85

Calls 3

parse_recordFunction · 0.85
DNSResponseClass · 0.85
parse_headerFunction · 0.70

Tested by

no test coverage detected