예제 #1
0
파일: dns.py 프로젝트: mattall/pox
 def get_rddata(self, l, type, dlen, beg_index):
     if beg_index + dlen > len(l):
         raise Trunc('(dns) truncated rdata')
     # A
     if type == 1:
         if dlen != 4:
             raise Exception('(dns) invalid a data size', system='packet')
         return IPAddr(l[beg_index:beg_index + 4])
     # AAAA
     elif type == 28:
         if dlen != 16:
             raise Exception('(dns) invalid a data size', system='packet')
         return IPAddr6.from_raw(l[beg_index:beg_index + dlen])
     # NS
     elif type == 2:
         return self.read_dns_name_from_index(l, beg_index)[1]
     # PTR
     elif type == 12:
         return self.read_dns_name_from_index(l, beg_index)[1]
     # CNAME
     elif type == 5:
         return self.read_dns_name_from_index(l, beg_index)[1]
     # MX
     elif type == 15:
         #TODO: Save priority (don't just jump past it)
         return self.read_dns_name_from_index(l, beg_index + 2)[1]
     else:
         return l[beg_index:beg_index + dlen]
예제 #2
0
파일: dns.py 프로젝트: caibitim/MyPOX
 def get_rddata(self, l, type, dlen, beg_index):
     if beg_index + dlen > len(l):
         raise Trunc('(dns) truncated rdata')
     # A
     if type == 1:
         if dlen != 4:
             raise Exception('(dns) invalid a data size',system='packet')
         return IPAddr(l[beg_index : beg_index + 4])
     # AAAA
     elif type == 28:
         if dlen != 16:
             raise Exception('(dns) invalid a data size',system='packet')
         return IPAddr6.from_raw(l[beg_index : beg_index + dlen])
     # NS
     elif type == 2:
         return self.read_dns_name_from_index(l, beg_index)[1]
     # PTR
     elif type == 12:
         return  self.read_dns_name_from_index(l, beg_index)[1]
     # CNAME
     elif type == 5:
         return self.read_dns_name_from_index(l, beg_index)[1]
     # MX
     elif type == 15:
         #TODO: Save priority (don't just jump past it)
         return self.read_dns_name_from_index(l, beg_index + 2)[1]
     else:
         return l[beg_index : beg_index + dlen]
 def ip6(addr):
     if addr is None:
         return None
     return IPAddr6.from_raw(addr)
예제 #4
0
파일: __init__.py 프로젝트: RunNJump/cs168
 def ip6(addr):
     if addr is None: return None
     return IPAddr6.from_raw(addr)