#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include /* the L2 protocols */
#include
#define IFNAME "eth0"
int main()
{
struct ifreq interface;
int sock;
if((sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
{
printf("create socket error\n");
return -1;
}
strncpy(interface.ifr_ifrn.ifrn_name, IFNAME, IFNAMSIZ);
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, \
(char *)&interface, sizeof(interface)) < 0)
{
printf("SO_BINDTODEVICE failed");
}
return 0;
}
阅读(1333) | 评论(0) | 转发(0) |