From f22bec1f33c5de69c20321097cb01dbad7ce5ac6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 4 Apr 2022 16:36:55 -0500 Subject: Add "ifconfig eth0 rename NEWNAME". --- toys/net/ifconfig.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/toys/net/ifconfig.c b/toys/net/ifconfig.c index e2944579..818c5932 100644 --- a/toys/net/ifconfig.c +++ b/toys/net/ifconfig.c @@ -42,6 +42,7 @@ config IFCONFIG broadcast ADDR - Set broadcast address pointopoint ADDR - PPP and PPPOE use this instead of "route add default gw" hw TYPE ADDR - set hardware (mac) address (type = ether|infiniband) + rename NEWNAME - rename interface Flags you can set on an interface (or -remove by prefixing with -): @@ -405,6 +406,7 @@ void ifconfig_main(void) {"netmask", 0, SIOCSIFNETMASK}, {"dstaddr", 0, SIOCSIFDSTADDR}, {"mtu", IFREQ_OFFSZ(ifr_mtu), SIOCSIFMTU}, + {"rename", IFREQ_OFFSZ(ifr_newname), SIOCSIFNAME}, {"keepalive", IFREQ_OFFSZ(ifr_data), SIOCDEVPRIVATE}, // SIOCSKEEPALIVE {"outfill", IFREQ_OFFSZ(ifr_data), SIOCDEVPRIVATE+2}, // SIOCSOUTFILL {"metric", IFREQ_OFFSZ(ifr_metric), SIOCSIFMETRIC}, @@ -493,6 +495,7 @@ void ifconfig_main(void) struct argh *t = try+i; int on = t->on, off = t->off; + // First entry in list assigns address to interface (no command name) if (!t->name) { if (isdigit(**argv) || !strcmp(*argv, "default")) argv--; else continue; @@ -505,11 +508,11 @@ void ifconfig_main(void) // Assign value to ifre field and call ioctl? (via IFREQ_OFFSZ.) if (on < 0) { - long l = strtoul(*argv, 0, 0); + void *dest = ((on = -on)>>16)+(char *)&ifre; if (off == SIOCSIFMAP) xioctl(TT.sockfd, SIOCGIFMAP, &ifre); - on = -on; - poke((on>>16) + (char *)&ifre, l, on&15); + if (SIOCSIFNAME) xstrncpy(dest, *argv, on&0xffff); + else poke(dest, strtoul(*argv, 0, 0), on&15); xioctl(TT.sockfd, off, &ifre); break; } else { -- cgit v1.2.3