コード例 #1
0
ファイル: plt.py プロジェクト: barryirwin/pypy-libtrace
 def get_dst_prefix(self):
     version = self.check_inet(20, 40)
     if version == 4:
         return ipp.IPprefix(4, self.pi.l3p[16:20])
     elif version == 6:
         return ipp.IPprefix(6, self.pi.l3p[24:40])
     return None
コード例 #2
0
ファイル: plt.py プロジェクト: barryirwin/pypy-libtrace
 def get_src_prefix(self):
     version = self.check_inet(16, 24)
     if version == 4:
         return ipp.IPprefix(4, self.pi.l3p[12:16])
     elif version == 6:
         return ipp.IPprefix(6, self.pi.l3p[8:24])
     return None
コード例 #3
0
 def addr_in_home(self, a):
     apref = ipp.IPprefix(self.fkey.version, a)
     for p in self.prefixes:
         if p.version == self.fkey.version:  # Avoid PltError
             if p.is_prefix(apref):
                 return True
     return False
コード例 #4
0
 def get_src_prefix(self):
     return ipp.IPprefix(self.fkey.version, self.fkey.saddr)
コード例 #5
0
 def get_dst_prefix(self):
     return ipp.IPprefix(self.fkey.version, self.fkey.daddr)
コード例 #6
0
import ipp
import sys  # except handlers
from plt_testing import *
import binascii

bs = b'\x01\x02\x03\x04\x05\x06\x07\x08,0x09\x00\x81\x82'
ipp3 = ipp.IPprefix(6, bytearray(bs), 48)
test_println(
    '3: version={0}, addr={1}, length={2}'.format(ipp3.version,
                                                  binascii.hexlify(ipp3.addr),
                                                  ipp3.length), get_tag())

ipp2 = ipp.IPprefix(4, bytearray([192, 168]))
test_println(
    '2: version={0}, addr={1}'.format(ipp2.version,
                                      binascii.hexlify(ipp2.addr)), get_tag())

ipp1 = ipp.IPprefix(4, bytearray())
test_println(str('1: version={0}\n'.format(ipp1.version)), get_tag())

test_println(str("ipp3 = %s" % ipp3), get_tag())
test_println(str("ipp2 = %s" % ipp2), get_tag())
test_println(str("ipp1 = %s" % str(ipp1)), get_tag())

test_println(
    str("addrs: ipp3 = %s   ipp2 = %s" %
        (binascii.hexlify(ipp3.addr), binascii.hexlify(ipp2.addr))), get_tag())

ipp3.length = 7
test_println(
    str('len=7: version={0}, addr={1}, length={2}\n'.format(
コード例 #7
0
ファイル: demo-ipp.py プロジェクト: irl/python-libtrace
import ipp, resource

#a = bytearray(b"Hell")
a = bytearray([130, 216, 38, 7])
p = ipp.IPprefix(4, a, 32)
print "p = %s, type = %s" % (str(p), type(p))

for n in range(0, 100000):
    if (n % 10000):
        print "using %d" % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
コード例 #8
0
test_string("p63", "2001:df0:0:0:1:2::")
test_string("p64", "2001:df0:0:abcd::1")
test_string("p65", "2001:0:0df0::2")
test_string("p66", "2001::def0::2")
test_string("p67", "::ffff:1.2.3.4")  # From RFC 5952

test_string("\np41", "130.216.38.7/24")
test_string("p42", "130.256.0.0")
test_string("p43", "130.216.0.0/33")
test_string("p44", "130.216.0.0/-1")
test_string("p45", "130.216/24")

p4 = ipp.from_s("130.216.0.0/24")
print "\np4 = %s, type(p4) = %s" % (p4, type(p4))
ba = bytearray([130, 216, 128, 0])
q4 = ipp.IPprefix(4, ba, 25)
print "q4 = %s, type(q4) = %s\n" % (q4, type(q4))

print "p4 <  q4: result = %s, %s (T, F)" % (p4 < q4, q4 < p4)
print "p4 <= q4: result = %s, %s (T, F)" % (p4 <= q4, q4 <= p4)
print "p4 == q4: result = %s, %s (F, F)" % (p4 == q4, q4 == p4)
print "p4 != q4: result = %s, %s (T, T)" % (p4 != q4, q4 != p4)
print "p4 >= q4: result = %s, %s (F, T)" % (p4 >= q4, q4 >= p4)
print "p4 >  q4: result = %s, %s (F, T)" % (p4 > q4, q4 > p4)

print "\np4.is_prefix(q4):  result = %s, %s (T, F)" % (p4.is_prefix(q4),
                                                       q4.is_prefix(p4))
print "p4.is_prefix(p4):  result = %s, %s (T, T)\n" % (p4.is_prefix(p4),
                                                       q4.is_prefix(q4))

n1918_16 = ipp.from_s("192.169.1.1/24")
コード例 #9
0
ファイル: plt.py プロジェクト: barryirwin/pypy-libtrace
 def get_target_prefix(self):
     if self.pi.rem >= 24:
         return ipp.IPprefix(6, self.pi.dp[8:24])
     return None
コード例 #10
0
ファイル: plt.py プロジェクト: barryirwin/pypy-libtrace
 def get_gateway(self):
     if self.pi.rem >= 8:
         return ipp.IPprefix(4, self.pi.dp[4:8])
     return None
コード例 #11
0
ファイル: try-dict.py プロジェクト: barryirwin/pypy-libtrace
        test_dict[s] = 1
    else:
        test_dict[s] = v+1

    if n == 0:  # Zero-org
        break
        
print "EOF - - -"


#exit()

def ca2str(cdata_array):
    s = string.join(cdata_array, '')
    n = string.find(s, '\x00')
    return s[0:n]

keys = sorted(test_dict)
for k in keys:
    print "%8d  %s" % (test_dict[k], k)
    ka = k.split('*')
    for j in range(0,4):
        print "%02x" % ord(ka[0][j]),
    print
    psa = ipp.IPprefix(4, bytearray(ka[0]))
    print "psa = %s" % psa
    print "%8d  %s -> %s" % (test_dict[k], 
        ka[0], ka[1])

    
コード例 #12
0
ファイル: try-ipp.py プロジェクト: barryirwin/pypy-libtrace
#nba = ffi.new("uint8_t[4]")
#ffi.memmove(nba, ba, len(nba))
#for v in nba:
#    print "%02x" % v,
#print

#print "bp.version=%d, bp.addr=%s, bp.length=%d" % (
#    bp.version, bp.addr, bp.length)

s = "2001:df0::2006:20e:c6ff:fef7:1f9f/64"
p1 = ipp.from_s(s)
print "p1.version=%d, p1.addr=%s, p1.length=%s" % (p1.version, p1.addr,
                                                   p1.length)
print "p1 = %s" % p1

bp = ipp.IPprefix(4, ba, 24)
print "bp = %s (type = %s)" % (bp, bp.__class__.__name__)

try:
    xxx = ipp.IPprefix(4, "1.2.3.4")
except:
    pass
print

s = "2001:df0:0:2006:20e:c6ff:fef7:1f9f/64"
p6 = ipp.from_s(s)
print "p6 = %s" % p6

s = "130.213.88.99/23"
p = ipp.from_s(s)
print "p3 = %s" % p