指定PING的网卡
1 struct ifreq ifr; 2 3 4 // 绑定在eth0上 5 memset( &ifr, 0, sizeof( struct ifreq ) ); 6 snprintf( ifr.ifr_name, sizeof( ifr.ifr_name ), "%s", ifname ); 7 if ( setsockopt( fd, SOL_SOCKET, SO_BINDTODEVICE, ( const void* )&ifr, sizeof( struct ifreq ) ) == -1 ) 8 { 9 perror( "setsockopt[SO_BINDTODEVICE]" ); 10 goto err_exit; 11 }