Subject: a small patch to ifconfig
To: 532bsd Mailing List <port-pc532@NetBSD.ORG>
From: Matthias Pfaller <leo@marco.de>
List: port-pc532
Date: 01/02/1995 15:34:59
Hi,

what follows is a small patch to src/sbin/ifconfig.c that allows to set
the mtu of an interface.

	Matthias

--- src/sbin/ifconfig/ifconfig.c	Wed Dec 21 11:10:00 1994
+++ ifconfig.c	Wed Dec 28 20:59:57 1994
@@ -74,7 +74,7 @@
 struct	iso_aliasreq	iso_addreq;
 struct	sockaddr_in	netmask;
 char	name[30];
-int	flags, metric, setaddr, setipdst, doalias;
+int	flags, metric, mtu, setaddr, setipdst, doalias;
 int	clearaddr, s;
 int	newaddr = 1;
 int	nsellength = 1;
@@ -88,6 +88,7 @@
 void 	setifbroadaddr __P((char *));
 void 	setifipdst __P((char *));
 void 	setifmetric __P((char *));
+void 	setifmtu __P((char *));
 void 	setifnetmask __P((char *));
 void 	setnsellength __P((char *));
 void 	setsnpaoffset __P((char *));
@@ -117,6 +118,7 @@
 #endif
 	{ "netmask",	NEXTARG,	setifnetmask },
 	{ "metric",	NEXTARG,	setifmetric },
+	{ "mtu", 	NEXTARG,	setifmtu },
 	{ "broadcast",	NEXTARG,	setifbroadaddr },
 	{ "ipdst",	NEXTARG,	setifipdst },
 	{ "snpaoffset",	NEXTARG,	setsnpaoffset },
@@ -181,11 +183,12 @@
 	int aflag = 0;
 
 	if (argc < 2) {
-		fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s",
-		    "\t[ af [ address [ dest_addr ] ] [ up ] [ down ] ",
-			    "[ netmask mask ] ]\n",
-		    "\t[ metric n ]\n",
-		    "\t[ arp | -arp ]\n",
+		fprintf(stderr, "usage: ifconfig interface\n"
+		    "\t[ af [ address [ dest_addr ] ] [ up ] [ down ] "
+			    "[ netmask mask ] ]\n"
+		    "\t[ metric n ]\n"
+		    "\t[ mtu n ]\n"
+		    "\t[ arp | -arp ]\n"
 		    "\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n");
 		exit(1);
 	}
@@ -300,6 +303,10 @@
 		metric = 0;
 	} else
 		metric = ifr->ifr_metric;
+	if (ioctl(s, SIOCGIFMTU, (caddr_t)ifr) < 0)
+		mtu = 0;
+	else
+		mtu = ifr->ifr_metric;
 	return (0);
 }
 
@@ -448,6 +455,16 @@
 }
 
 void
+setifmtu(val)
+	char *val;
+{
+	strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+	ifr.ifr_metric = atoi(val);
+	if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
+		warn("SIOCSIFMTU");
+}
+
+void
 setsnpaoffset(val)
 	char *val;
 {
@@ -471,6 +488,8 @@
 	printb("flags", flags, IFFBITS);
 	if (metric)
 		printf(" metric %d", metric);
+	if (mtu)
+		printf(" mtu %d", mtu);
 	putchar('\n');
 	if ((p = afp) != NULL) {
 		(*p->af_status)(1);