Exemplo n.º 1
0
 def get_ifindex_from_ifname(fd, ifname):
     p = lltype.malloc(_c.ifreq, flavor="raw")
     iflen = rffi.str2chararray(ifname, rffi.cast(rffi.CCHARP, p.c_ifr_name), PacketAddress.ifr_name_size - 1)
     p.c_ifr_name[iflen] = "\0"
     err = _c.ioctl(fd, _c.SIOCGIFINDEX, p)
     ifindex = p.c_ifr_ifindex
     lltype.free(p, flavor="raw")
     if err != 0:
         raise RSocketError("invalid interface name")
     return ifindex
Exemplo n.º 2
0
 def get_ifname(self, fd):
     ifname = ""
     a = self.lock(_c.sockaddr_ll)
     ifindex = rffi.getintfield(a, "c_sll_ifindex")
     if ifindex:
         p = lltype.malloc(_c.ifreq, flavor="raw")
         rffi.setintfield(p, "c_ifr_ifindex", ifindex)
         if _c.ioctl(fd, _c.SIOCGIFNAME, p) == 0:
             ifname = rffi.charp2strn(rffi.cast(rffi.CCHARP, p.c_ifr_name), PacketAddress.ifr_name_size)
         lltype.free(p, flavor="raw")
     self.unlock()
     return ifname
Exemplo n.º 3
0
 def get_ifname(self, fd):
     a = self.lock(_c.sockaddr_ll)
     p = lltype.malloc(_c.ifreq, flavor='raw')
     rffi.setintfield(p, 'c_ifr_ifindex',
                      rffi.getintfield(a, 'c_sll_ifindex'))
     if (_c.ioctl(fd, _c.SIOCGIFNAME, p) == 0):
         # eh, the iface name is a constant length array
         i = 0
         d = []
         while p.c_ifr_name[i] != '\x00' and i < len(p.c_ifr_name):
             d.append(p.c_ifr_name[i])
             i += 1
         ifname = ''.join(d)
     else:
         ifname = ""
     lltype.free(p, flavor='raw')
     self.unlock()
     return ifname
Exemplo n.º 4
0
 def get_ifname(self, fd):
     a = self.lock(_c.sockaddr_ll)
     p = lltype.malloc(_c.ifreq, flavor='raw')
     rffi.setintfield(p, 'c_ifr_ifindex',
                      rffi.getintfield(a, 'c_sll_ifindex'))
     if (_c.ioctl(fd, _c.SIOCGIFNAME, p) == 0):
         # eh, the iface name is a constant length array
         i = 0
         d = []
         while p.c_ifr_name[i] != '\x00' and i < len(p.c_ifr_name):
             d.append(p.c_ifr_name[i])
             i += 1
         ifname = ''.join(d)
     else:
         ifname = ""
     lltype.free(p, flavor='raw')
     self.unlock()
     return ifname