コード例 #1
0
ファイル: LinuxTap.cs プロジェクト: arjunprakash84/ipop
        public LinuxTap(string dev)
        {
            int TUNSETIFF = GetIOCtlWrite('T', 202, 4); /* size of int 4, from if_tun.h */

              ifreq1 ifr1 = new ifreq1();
              int fd;

              if ((fd = Syscall.open("/dev/net/tun", OpenFlags.O_RDWR)) < 0) {
            throw new Exception("Failed to open /dev/net/tun");
              }

              ifr1.ifru_flags = IFF_TAP | IFF_NO_PI;
              ifr1.ifrn_name = dev;
              if (ioctl(fd, TUNSETIFF, ref ifr1) < 0) {
            Syscall.close(fd);
            throw new Exception("TUNSETIFF failed");
              }
              _fd = fd;

              int ctrl_fd = socket(AF_INET, SOCK_DGRAM, 0);
              if(ctrl_fd == -1) {
            Syscall.close(fd);
            throw new Exception("Unable to open CTL_FD");
              }

              ifreq2 ifr2 = new ifreq2();
              ifr2.ifrn_name = dev; // ioctl changed the name?
              if(ioctl(ctrl_fd, SIOCGIFHWADDR, ref ifr2) <0) {
            Console.WriteLine("Failed to get hw addr.");
            Syscall.close(ctrl_fd);
            throw new Exception("Failed to get hw addr.");
              }
              _addr =  MemBlock.Reference(ASCIIEncoding.UTF8.GetBytes(ifr2.ifr_hwaddr.sa_data));
        }
コード例 #2
0
ファイル: LinuxTap.cs プロジェクト: ikaragkiozoglou/brunet
        public LinuxTap(string dev)
        {
            int TUNSETIFF = GetIOCtlWrite('T', 202, 4); /* size of int 4, from if_tun.h */

            ifreq1 ifr1 = new ifreq1();
            int    fd;

            if ((fd = Syscall.open("/dev/net/tun", OpenFlags.O_RDWR)) < 0)
            {
                throw new Exception("Failed to open /dev/net/tun");
            }

            ifr1.ifru_flags = IFF_TAP | IFF_NO_PI;
            ifr1.ifrn_name  = dev;
            if (ioctl(fd, TUNSETIFF, ref ifr1) < 0)
            {
                Syscall.close(fd);
                throw new Exception("TUNSETIFF failed");
            }
            _fd = fd;

            int ctrl_fd = socket(AF_INET, SOCK_DGRAM, 0);

            if (ctrl_fd == -1)
            {
                Syscall.close(fd);
                throw new Exception("Unable to open CTL_FD");
            }

            ifreq2 ifr2 = new ifreq2();

            ifr2.ifrn_name = dev; // ioctl changed the name?
            if (ioctl(ctrl_fd, SIOCGIFHWADDR, ref ifr2) < 0)
            {
                Console.WriteLine("Failed to get hw addr.");
                Syscall.close(ctrl_fd);
                throw new Exception("Failed to get hw addr.");
            }
            _addr = MemBlock.Reference(ASCIIEncoding.UTF8.GetBytes(ifr2.ifr_hwaddr.sa_data));
        }
コード例 #3
0
ファイル: LinuxTap.cs プロジェクト: ikaragkiozoglou/brunet
 private extern static int ioctl(int fd, int request, ref ifreq1 arg);
コード例 #4
0
ファイル: LinuxTap.cs プロジェクト: arjunprakash84/ipop
 private static extern int ioctl(int fd, int request, ref ifreq1 arg);