dev->open = henbin_open;
dev->stop = henbin_close;
如有需要透過sockets呼叫custom ioctl,可增加一個如下的ioctl function
int henbin_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd){
switch (cmd){
SIOCDEVPRIVATE:
SIOCDEVPRIVATE+1:
...
SIOCDEVPRIVATE+15:
}
return 0;
}
dev->do_ioct = henbin_ioctl;
可使用的custom command的範圍從SIOCDEVPRIVATE到SIOCDEVPRIVATE+15, 此為Device private ioctl calls
如此即可透過下列方式去呼叫ioctl
{
...
struct ifreq ifr;
int skfd;
struct sockaddr_in *info;
skfd = socket(PF_INET, SOCK_DGRAM, 0 );
memset(&ifr,0,sizeof(struct ifreq));
strcpy(ifr.ifr_name, "eth0");
ifr.ifr_hwaddr.sa_family = AF_INET;
ioctl(skfd, SIOCDEVPRIVATE+1, &ifr);
}
另外還有SIOCPROTOPRIVATE到SIOCPROTOPRIVATE+15, 這就是protocol private, 可以在af_inet.c內增加一個OEM ioctl command,
再利用下面方式去呼叫即可
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
int s = socket(AF_INET, SOCK_DGRAM, 0);
ioctl(s, (SIOCPROTOPRIVATE+1));
close(s);
return 0;
}
沒有留言:
張貼留言