Penguin
Annotated edit history of SIOCSIFNAME version 3 showing authors affecting page license. View with all changes included.
Rev Author # Line
1 PerryLorier 1 This allows you to rename an interface. Beware that a renamed interface will keep it's new name even after it's downed, the interface must be destroyed (by for example removing the module) to "undo" this. (of course you can just rename it back...)
2
3 example:
4 #include <linux/sockios.h>
5 #include <sys/ioctl.h>
6 #include <net/route.h>
7 #include <net/if.h>
8 #include <sys/socket.h>
9 #include <stdio.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include <string.h>
13
14
15 int main(int argc,char **argv)
16 {
17 int fd;
18 struct ifreq ifr;
19
20 if (argc<3) {
21 fprintf(stderr,"Usage: ifmv oldname newname\n");
22 return 1;
23 }
24
25 if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
26 perror("socket(PF_INET, SOCK_DGRAM, 0)");
27 return -1;
28 }
29
30 strncpy(ifr.ifr_name,argv[[1],sizeof(ifr.ifr_name));
31 strncpy(ifr.ifr_newname,argv[[2],sizeof(ifr.ifr_newname));
32
33 if (ioctl(fd, SIOCSIFNAME, &ifr)==-1) {
34 perror("ioctl(SIOCSIFNAME)");
35 return 1;
36 }
37
38 return 0;
39 }