Linux 下網卡重命名


#include 
#include
#include
#include
#include <<span style="margin: 0px; padding: 0px; font-family: 'Courier New'; color: rgb(0, 0, 255);">string.h>
#include if.h>
#include

int main(int argc,char **argv)
{
int s;
struct ifreq ifr;

if (argc != 3)
{
fprintf(stderr,"Usage: %s old_name new_name\n",argv[0]);
exit(-1);
}

s = socket(PF_INET, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name,argv[1]);
strcpy(ifr.ifr_newname,argv[2]);
if (ioctl(s, SIOCSIFNAME, &ifr) < 0)
{
perror("SIOCSIFNAME");
}

close(s);
return 0;
}



轉自:http://www.cnblogs.com/moonflow/archive/2012/02/19/2358564.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章