util/Zeroconf.py
changeset 1737 a39c2918c015
parent 1736 7e61baa047f0
child 1739 ec153828ded2
equal deleted inserted replaced
1736:7e61baa047f0 1737:a39c2918c015
   103 # Some DNS constants
   103 # Some DNS constants
   104 
   104 
   105 _MDNS_ADDR = '224.0.0.251'
   105 _MDNS_ADDR = '224.0.0.251'
   106 _MDNS_PORT = 5353;
   106 _MDNS_PORT = 5353;
   107 _DNS_PORT = 53;
   107 _DNS_PORT = 53;
   108 _DNS_TTL = 60 * 60; # one hour default TTL
   108 _DNS_TTL = 60 * 60;  # one hour default TTL
   109 
   109 
   110 _MAX_MSG_TYPICAL = 1460 # unused
   110 _MAX_MSG_TYPICAL = 1460  # unused
   111 _MAX_MSG_ABSOLUTE = 8972
   111 _MAX_MSG_ABSOLUTE = 8972
   112 
   112 
   113 _FLAGS_QR_MASK = 0x8000 # query response mask
   113 _FLAGS_QR_MASK = 0x8000  # query response mask
   114 _FLAGS_QR_QUERY = 0x0000 # query
   114 _FLAGS_QR_QUERY = 0x0000  # query
   115 _FLAGS_QR_RESPONSE = 0x8000 # response
   115 _FLAGS_QR_RESPONSE = 0x8000  # response
   116 
   116 
   117 _FLAGS_AA = 0x0400 # Authorative answer
   117 _FLAGS_AA = 0x0400  # Authorative answer
   118 _FLAGS_TC = 0x0200 # Truncated
   118 _FLAGS_TC = 0x0200  # Truncated
   119 _FLAGS_RD = 0x0100 # Recursion desired
   119 _FLAGS_RD = 0x0100  # Recursion desired
   120 _FLAGS_RA = 0x8000 # Recursion available
   120 _FLAGS_RA = 0x8000  # Recursion available
   121 
   121 
   122 _FLAGS_Z = 0x0040 # Zero
   122 _FLAGS_Z = 0x0040   # Zero
   123 _FLAGS_AD = 0x0020 # Authentic data
   123 _FLAGS_AD = 0x0020  # Authentic data
   124 _FLAGS_CD = 0x0010 # Checking disabled
   124 _FLAGS_CD = 0x0010  # Checking disabled
   125 
   125 
   126 _CLASS_IN = 1
   126 _CLASS_IN = 1
   127 _CLASS_CS = 2
   127 _CLASS_CS = 2
   128 _CLASS_CH = 3
   128 _CLASS_CH = 3
   129 _CLASS_HS = 4
   129 _CLASS_HS = 4
   753         self.size += 2
   753         self.size += 2
   754         record.write(self)
   754         record.write(self)
   755         self.size -= 2
   755         self.size -= 2
   756 
   756 
   757         length = len(''.join(self.data[index:]))
   757         length = len(''.join(self.data[index:]))
   758         self.insertShort(index, length) # Here is the short we adjusted for
   758         self.insertShort(index, length)  # Here is the short we adjusted for
   759 
   759 
   760     def packet(self):
   760     def packet(self):
   761         """Returns a string containing the packet's bytes
   761         """Returns a string containing the packet's bytes
   762 
   762 
   763         No further parts should be added to the packet once this
   763         No further parts should be added to the packet once this
   851     """
   851     """
   852 
   852 
   853     def __init__(self, zeroconf):
   853     def __init__(self, zeroconf):
   854         threading.Thread.__init__(self)
   854         threading.Thread.__init__(self)
   855         self.zeroconf = zeroconf
   855         self.zeroconf = zeroconf
   856         self.readers = {} # maps socket to reader
   856         self.readers = {}  # maps socket to reader
   857         self.timeout = 5
   857         self.timeout = 5
   858         self.condition = threading.Condition()
   858         self.condition = threading.Condition()
   859         self.start()
   859         self.start()
   860 
   860 
   861     def run(self):
   861     def run(self):