一、应用层
[code]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");
}[/code]
二、linux内核
1、 在sockios.h中定义
[code]#define SIOCSIFVLAN_PVID_PRI 0x8985 /* Set 802.1Q VLAN pvid */[/code]
2、在af_inet.c中
添加
[code]extern int VLAN1QEN(unsigned int ,void *arg);[/code]
在inet_ioctl()函数中添加
[code]case SIOCSIFVLAN_PVID_PRI:
return VLAN1QEN(cmd, arg);[/code]
3、另外定义:
[code]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;
}
}[/code]