FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

More. · python-zeroconf/python-zeroconf@b8baed3 · GitHub

Repository navigation

Commit b8baed3

Browse files
committed
More.
1 parent 173350e commit b8baed3

1 file changed

Lines changed: 20 additions & 30 deletions

File tree

‎Zeroconf.py‎

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -473,22 +473,16 @@ def unpack(self, format):
473473

474474
def readHeader(self):
475475
"""Reads header portion of packet"""
476-
info = self.unpack('!HHHHHH')
477-
478-
self.id = info[0]
479-
self.flags = info[1]
480-
self.numQuestions = info[2]
481-
self.numAnswers = info[3]
482-
self.numAuthorities = info[4]
483-
self.numAdditionals = info[5]
476+
(self.id, self.flags, self.numQuestions, self.numAnswers,
477+
self.numAuthorities, self.numAdditionals) = self.unpack('!HHHHHH')
484478

485479
def readQuestions(self):
486480
"""Reads questions section of packet"""
487-
for i in range(0, self.numQuestions):
481+
for i in xrange(self.numQuestions):
488482
name = self.readName()
489-
info = self.unpack('!HH')
483+
type, clazz = self.unpack('!HH')
490484

491-
question = DNSQuestion(name, info[0], info[1])
485+
question = DNSQuestion(name, type, clazz)
492486
self.questions.append(question)
493487

494488
def readInt(self):
@@ -515,35 +509,31 @@ def readOthers(self):
515509
"""Reads the answers, authorities and additionals section of the
516510
packet"""
517511
n = self.numAnswers + self.numAuthorities + self.numAdditionals
518-
for i in range(0, n):
512+
for i in xrange(n):
519513
domain = self.readName()
520-
info = self.unpack('!HHiH')
514+
type, clazz, ttl, length = self.unpack('!HHiH')
521515

522516
rec = None
523-
if info[0] == _TYPE_A:
524-
rec = DNSAddress(domain, info[0], info[1], info[2],
525-
self.readString(4))
526-
elif info[0] == _TYPE_CNAME or info[0] == _TYPE_PTR:
527-
rec = DNSPointer(domain, info[0], info[1], info[2],
528-
self.readName())
529-
elif info[0] == _TYPE_TXT:
530-
rec = DNSText(domain, info[0], info[1], info[2],
531-
self.readString(info[3]))
532-
elif info[0] == _TYPE_SRV:
533-
rec = DNSService(domain, info[0], info[1], info[2],
517+
if type == _TYPE_A:
518+
rec = DNSAddress(domain, type, clazz, ttl, self.readString(4))
519+
elif type == _TYPE_CNAME or type == _TYPE_PTR:
520+
rec = DNSPointer(domain, type, clazz, ttl, self.readName())
521+
elif type == _TYPE_TXT:
522+
rec = DNSText(domain, type, clazz, ttl, self.readString(length))
523+
elif type == _TYPE_SRV:
524+
rec = DNSService(domain, type, clazz, ttl,
534525
self.readUnsignedShort(), self.readUnsignedShort(),
535526
self.readUnsignedShort(), self.readName())
536-
elif info[0] == _TYPE_HINFO:
537-
rec = DNSHinfo(domain, info[0], info[1], info[2],
527+
elif type == _TYPE_HINFO:
528+
rec = DNSHinfo(domain, type, clazz, ttl,
538529
self.readCharacterString(), self.readCharacterString())
539-
elif info[0] == _TYPE_AAAA:
540-
rec = DNSAddress(domain, info[0], info[1], info[2],
541-
self.readString(16))
530+
elif type == _TYPE_AAAA:
531+
rec = DNSAddress(domain, type, clazz, ttl, self.readString(16))
542532
else:
543533
# Try to ignore types we don't know about
544534
# Skip the payload for the resource record so the next
545535
# records can be parsed correctly
546-
self.offset += info[3]
536+
self.offset += length
547537

548538
if rec is not None:
549539
self.answers.append(rec)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL