-def open_tap(vif_name, vif_type, pi):
- flags = 0
- flags |= vif_type
-
- if not pi:
- flags |= IFF_NO_PI
-
- fd = os.open("/dev/net/tun", os.O_RDWR)
-
- err = fcntl.ioctl(fd, TUNSETIFF, struct.pack("16sH", vif_name, flags))
- if err < 0:
- os.close(fd)
- raise RuntimeError("Could not configure device %s" % vif_name)
+def get_fd(socket_name):
+ # Socket to recive the file descriptor
+ fdsock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ fdsock.bind("")
+ address = fdsock.getsockname()
+
+ # Socket to connect to the pl-vif-create process
+ # and send the PASSFD message
+ sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ sock.connect(socket_name)
+ emsg = base64.b64encode(PASSFD_MSG)
+ eargs = base64.b64encode(address)
+ encoded = "%s|%s\n" % (emsg, eargs)
+ sock.send(encoded)
+
+ # Receive fd
+ (fd, msg) = passfd.recvfd(fdsock)
+
+ # Receive reply
+ reply = sock.recv(1024)
+ reply = base64.b64decode(reply)