指定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 }

 

posted on 2016-11-23 15:09  郁郁思扬  阅读(1264)  评论(0编辑  收藏  举报

导航