时间:2010-07-26 13:35:48

标签: linux sockets raw-sockets

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:0)

请确保绑定到if_index

if (ioctl(sock, SIOCGIFINDEX, &stEthReq ) < 0 )
{
    printf( "failed to get IF index!" );
    return -1;
}
memset(&client_addr, 0, sizeof(client_addr));
client_addr.sll_family   = AF_PACKET;
client_addr.sll_ifindex  = stEthReq.ifr_ifru.ifru_ivalue;
client_addr.sll_protocol = VOS_HTONS(usEthType);
ret = bind(sock,(struct sockaddr *)(&client_addr), sizeof(client_addr));