--- tethereal.c	2003-10-21 07:51:54.000000000 -0500
+++ tethereal.c	2003-10-21 07:54:43.000000000 -0500
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include <locale.h>
 #include <limits.h>
+#include <pwd.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -117,6 +118,10 @@
 static gboolean print_hex;
 static gboolean line_buffered;
 static guint32 cul_bytes = 0;
+uid_t nuid = 0;
+char *nusr = NULL;
+struct passwd *pwent;
+
 
 #ifdef HAVE_LIBPCAP
 typedef struct _loop_data {
@@ -903,7 +908,7 @@
   get_runtime_version_info(runtime_info_str);
 
   /* Now get our args */
-  while ((opt = getopt(argc, argv, "a:b:c:d:Df:F:hi:lnN:o:pqr:R:s:St:vw:Vxz:")) != -1) {
+  while ((opt = getopt(argc, argv, "a:b:c:d:Df:F:hi:lnN:o:pqr:R:s:St:u:vw:Vxz:")) != -1) {
     switch (opt) {
       case 'a':        /* autostop criteria */
 #ifdef HAVE_LIBPCAP
@@ -1141,6 +1146,28 @@
           exit(1);
         }
         break;
+        case 'u':               /* Change the UID that tethereal runs as */
+          if ((nuid = atoi (optarg)) == 0) {
+              nusr = strdup (optarg);
+              pwent = getpwnam (nusr);
+              if (pwent == (struct passwd *) NULL) {
+                  fprintf (stderr, "Error user unknown\n");
+                  exit (8);
+              }
+
+              nuid = pwent->pw_uid;
+
+              } else {
+
+              pwent = getpwuid (nuid);
+              if (pwent == (struct passwd *) NULL) {
+                  fprintf (stderr,
+                           "Error cannot resolve user name for uid.\n");
+                  exit (8);
+               }
+              nusr = strdup (pwent->pw_name);
+            }
+          break;
       case 'v':        /* Show version and exit */
         printf("t%s %s\n%s\n%s\n", PACKAGE, VERSION, comp_info_str->str,
                runtime_info_str->str);
@@ -1664,6 +1691,11 @@
     ld.packet_count = 0;
   } else
     ld.go = FALSE;
+
+ /* XXX only good for capture. Is there a better place for this? */
+  if ((nusr != NULL) && (setuid (nuid) < 0)) 
+     fprintf (stderr, "Failed to change to user id %d\n", nuid);
+
   while (ld.go) {
     /* We need to be careful with automatic variables defined in the
        outer scope which are changed inside the loop.  Most compilers
