Skip to content

Latest commit

 

History

History
45 lines (40 loc) · 1.05 KB

200511221009.txt.md

File metadata and controls

45 lines (40 loc) · 1.05 KB

10.18 Linux下网卡重命名

A: lgx@nsfocus 2005-11-22 10:09


/*

  • gcc -Wall -pipe -O3 -s -o ifname ifname.c */ #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if.h> #include <netinet/ether.h> #include <errno.h>

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

if ( 3 != argc )
{
    fprintf( stderr, "Usage: %s old_name new_name\n", argv[0] );
    return( -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 );

} /* end of main */

ifconfig eth1 down

./ifname eth1 lgx

ifconfig lgx up