[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ifconfig default to -a
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: ifconfig default to -a
- From: Ian Darwin <ian_(_at_)_darwinsys_(_dot_)_com>
- Date: Wed, 1 Dec 2004 22:52:09 -0500 (EST)
Several other *nixes including at least Linux, Mac OS X, and FreeBSD
have an ifconfig that assumes -a instead of printing usage if no
arguments are given. This patch makes ours print -a, and adds -h
to print the usage nicely. Has been in my tree for a while, and tested
lighly on macppc and i386, but none of these systems has more than 2
actual network cards.
Adds an int param to usage() so -h can exit 0, invalid flags can exit 1.
This replaces a patch I sent to some people previously, which was buggy
(sorry).
Index: ifconfig.8
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v
retrieving revision 1.93
diff -u -r1.93 ifconfig.8
--- ifconfig.8 1 Dec 2004 22:30:53 -0000 1.93
+++ ifconfig.8 2 Dec 2004 03:51:23 -0000
@@ -123,6 +123,7 @@
If a protocol family is specified,
.Nm
will report only the details specific to that protocol family.
+If no parameters are provided, a summary of all interfaces is provided.
.Pp
Only the superuser may modify the configuration of a network interface.
.Pp
Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.121
diff -u -r1.121 ifconfig.c
--- ifconfig.c 1 Dec 2004 15:57:44 -0000 1.121
+++ ifconfig.c 2 Dec 2004 03:51:24 -0000
@@ -348,7 +348,7 @@
void printif(struct ifreq *, int);
void printb(char *, unsigned short, char *);
void status(int, struct sockaddr_dl *);
-void usage(void);
+void usage(int);
const char *get_string(const char *, const char *, u_int8_t *, int *);
void print_string(const u_int8_t *, int);
char *sec2str(time_t);
@@ -428,9 +428,16 @@
int Cflag = 0;
int i;
- if (argc < 2)
- usage();
+ /* If no args at all, print all interfaces. */
+ if (argc < 2) {
+ printif(NULL, ifaliases);
+ exit(0);
+ }
argc--, argv++;
+ if (!strcmp(*argv, "-h")) {
+ usage(0);
+ exit(0);
+ }
if (!strcmp(*argv, "-a"))
aflag = 1;
else if (!strcmp(*argv, "-A")) {
@@ -447,7 +454,7 @@
mflag = 1;
argc--, argv++;
if (argc < 1)
- usage();
+ usage(1);
if (strlcpy(name, *argv, sizeof(name)) >= IFNAMSIZ)
errx(1, "interface name '%s' too long", *argv);
} else if (!strcmp(*argv, "-C")) {
@@ -468,13 +475,13 @@
}
if (Cflag) {
if (argc > 0 || mflag || aflag)
- usage();
+ usage(1);
list_cloners();
exit(0);
}
if (aflag) {
if (argc > 0)
- usage();
+ usage(0);
printif(NULL, ifaliases);
exit(0);
}
@@ -2693,8 +2700,9 @@
printf("Attempt to set IPX netmask will be ineffectual\n");
}
+/* Print usage, exit(value) if value is non-zero. */
void
-usage(void)
+usage(int value)
{
fprintf(stderr,
"usage: ifconfig interface [address_family] [address [dest_address]]\n"
@@ -2724,7 +2732,8 @@
" ifconfig -m interface [address_family]\n"
" ifconfig interface create\n"
" ifconfig interface destroy\n");
- exit(1);
+ if (value)
+ exit(value);
}
static int __tag = 0;
Visit your host, monkey.org