add option -R for printing the routing table id is running under

ok?

diff --git usr.bin/id/id.1 usr.bin/id/id.1
index 35728ee53ee..c5727927bc6 100644
--- usr.bin/id/id.1
+++ usr.bin/id/id.1
@@ -55,6 +55,8 @@
 .Fl p
 .Op Ar user
 .Nm id
+.Fl R
+.Nm id
 .Fl u Op Fl nr
 .Op Ar user
 .Sh DESCRIPTION
@@ -115,6 +117,10 @@ If there is a login class specified for the user in the
 database, it is displayed, preceded by the keyword
 .Dq class .
 Each display is on a separate line.
+.It Fl R
+Display the default routing table of the
+.Nm
+process.
 .It Fl r
 Display the real ID for the
 .Fl g
diff --git usr.bin/id/id.c usr.bin/id/id.c
index ba107339794..139be7a7522 100644
--- usr.bin/id/id.c
+++ usr.bin/id/id.c
@@ -29,6 +29,9 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/types.h>
+#include <sys/socket.h>
+
 #include <err.h>
 #include <errno.h>
 #include <grp.h>
@@ -47,13 +50,14 @@ void        usage(void);
 void   user(struct passwd *);
 struct passwd *
        who(char *);
+void   rdomain(void);
 
 int
 main(int argc, char *argv[])
 {
        struct group *gr;
        struct passwd *pw;
-       int ch, cflag, Gflag, gflag, nflag, pflag, rflag, uflag;
+       int ch, cflag, Gflag, gflag, nflag, pflag, Rflag, rflag, uflag;
        uid_t uid;
        gid_t gid;
        const char *opts;
@@ -61,7 +65,7 @@ main(int argc, char *argv[])
        if (pledge("stdio getpw", NULL) == -1)
                err(1, "pledge");
 
-       cflag = Gflag = gflag = nflag = pflag = rflag = uflag = 0;
+       cflag = Gflag = gflag = nflag = pflag = Rflag = rflag = uflag = 0;
 
        if (strcmp(getprogname(), "groups") == 0) {
                Gflag = 1;
@@ -76,7 +80,7 @@ main(int argc, char *argv[])
                if (argc > 1)
                        usage();
        } else
-               opts = "cGgnpru";
+               opts = "cGgnpRru";
 
        while ((ch = getopt(argc, argv, opts)) != -1)
                switch(ch) {
@@ -95,6 +99,9 @@ main(int argc, char *argv[])
                case 'p':
                        pflag = 1;
                        break;
+               case 'R':
+                       Rflag = 1;
+                       break;
                case 'r':
                        rflag = 1;
                        break;
@@ -157,6 +164,11 @@ main(int argc, char *argv[])
                exit(0);
        }
 
+       if (Rflag) {
+               rdomain();
+               exit(0);
+       }
+
        if (pflag) {
                pretty(pw);
                exit(0);
@@ -338,6 +350,12 @@ who(char *u)
 }
 
 void
+rdomain(void)
+{
+       (void)printf("%d\n", getrtable());
+}
+
+void
 usage(void)
 {
        if (strcmp(getprogname(), "groups") == 0) {
@@ -350,6 +368,7 @@ usage(void)
                (void)fprintf(stderr, "       id -G [-n] [user]\n");
                (void)fprintf(stderr, "       id -g [-nr] [user]\n");
                (void)fprintf(stderr, "       id -p [user]\n");
+               (void)fprintf(stderr, "       id -R\n");
                (void)fprintf(stderr, "       id -u [-nr] [user]\n");
        }
        exit(1);

Reply via email to