def get_route(self,addr=None,table=254): """ Get a particular route. About implementation: there is a mechanism to retrieve only one record from the kernel; but it is unreliable, so get all records and filter it here """ if addr is None: return self.get_all_routes(table) ret = self.get_all_routes(table) result = {} dst = dqn_to_int(addr) for i in ret: if ('dst_prefix' in i.keys()) and ('dst_len' in i.keys()): if dqn_to_int(i['dst_prefix']) == get_base(dst,i['dst_len']): result['static'] = i elif ('dst_len' in i.keys()) and ('src_len' in i.keys()): if i['dst_len'] == 0 and i['src_len'] == 0: result['default'] = i if 'static' in result.keys(): ret = [result['static'],] elif 'default' in result.keys(): ret = [result['default'],] else: ret = [] return ret
def __init__(self, address='0.0.0.0',port=10001): """ Create and bind socket structure """ self.fd = libc.socket(AF_INET,SOCK_STREAM,0) libc.setsockopt(self.fd, SOL_SOCKET, SO_REUSEADDR, byref(c_uint32(1)), sizeof(c_uint32)) sa = sockaddr_in() sa.sin_family = AF_INET sa.sin_port = htons(port) sa.sin_addr = htonl(dqn_to_int(address)) self.sa = sa l = libc.bind(self.fd, byref(sa), sizeof(sa)) if l != 0: self.close() raise Exception("libc.bind(): errcode %i" % (l))
def __init__(self, address='0.0.0.0', port=10001): """ Create and bind socket structure """ self.fd = libc.socket(AF_INET, SOCK_STREAM, 0) libc.setsockopt(self.fd, SOL_SOCKET, SO_REUSEADDR, byref(c_uint32(1)), sizeof(c_uint32)) sa = sockaddr_in() sa.sin_family = AF_INET sa.sin_port = htons(port) sa.sin_addr = htonl(dqn_to_int(address)) self.sa = sa l = libc.bind(self.fd, byref(sa), sizeof(sa)) if l != 0: self.close() raise Exception("libc.bind(): errcode %i" % (l)) for i in range(QTHREADS): p9socketworker(self).start()
def r_ip4ad(text): return c_uint32(htonl(dqn_to_int(text)))