一、应用层

 

uint16 data16;

if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)

 {

       printf("socket failed\n\r");

}   

if(ioctl(fd, SIOCSIFVLAN_PVID_PRI, &data16) < 0)

 {

       printf("ioctl pvid failed\n\r");

}   

 

二、linux内核

1、 sockios.h中定义

   #define SIOCSIFVLAN_PVID_PRI     0x8985         /* Set 802.1Q VLAN pvid  */

 

 

2、在af_inet.c

    添加

        extern int VLAN1QEN(unsigned int ,void *arg);

inet_ioctl()函数中添加

       case SIOCSIFVLAN_PVID_PRI:

               return VLAN1QEN(cmd, arg);

 

3、另外定义:

static unsigned int VLAN_PVID_PRI = 0;

int VLAN1QEN(unsigned int cmd,void *arg)

{

            unsigned int data;

              if (copy_from_user(&data, arg, sizeof(int)))

                     return -EFAULT;

            switch (cmd) {

             case SIOCSIFVLAN_PVID_PRI:

                   VLAN_PVID_PRI = data;

                 break;

            default:

                     return -EINVAL;

              }

}