aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2022-04-04 16:36:55 -0500
committerRob Landley <rob@landley.net>2022-04-04 16:36:55 -0500
commitf22bec1f33c5de69c20321097cb01dbad7ce5ac6 (patch)
tree34ae51387ec916891c1691692d91d140f4f91e72
parentfb3c28fe89f9ca056404c14998f81a8ae46f7529 (diff)
downloadtoybox-f22bec1f33c5de69c20321097cb01dbad7ce5ac6.tar.gz
Add "ifconfig eth0 rename NEWNAME".
-rw-r--r--toys/net/ifconfig.c9
1 files 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 {