bin/65228: [Patch]Allow rup to parse hostnames from a defined file.

Liam Foy liamfoy at sepulcrum.org
Mon Apr 5 15:30:13 PDT 2004


>Number:         65228
>Category:       bin
>Synopsis:       [Patch]Allow rup to parse hostnames from a defined file.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 05 15:30:09 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator:     Liam Foy
>Release:        FreeBSD 5.2-RELEASE i386
>Organization:
Sepulcrum 
>Environment:


System: FreeBSD 5.2-RELEASE #2: Mon Mar 29 17:52:08 BST 2004
    liamfoy@:/usr/obj/usr/src/sys/Ecthelion



>Description:


I wrote this patch for my own benefit, but I thought it might be helpful. The patch will allow hostnames or IP addressed to be parsed from a file, specified on command line. This helps if you have many hosts you wish to query and a regular basis(ISP's), and will reduce all that noisy broadcast traffic on your network. 


>How-To-Repeat:





>Fix:


--- rup.diff begins here ---
diff -ru /usr/src/usr.bin/rup/rup.1 /hd3/rup/rup.1
--- /usr/src/usr.bin/rup/rup.1	Mon Apr  5 22:31:13 2004
+++ /hd3/rup/rup.1	Mon Apr  5 21:19:40 2004
@@ -42,6 +42,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Ar host ...
+.Op Ar -f <filename> 
 .Sh DESCRIPTION
 The
 .Nm
@@ -62,6 +63,11 @@
 .Nm
 utility uses an RPC protocol defined in
 .Pa /usr/include/rpcsvc/rstat.x .
+.Pp
+.Bl -tag -width Op
+.It Fl f Ar <filename> 
+This option specifies which file is read by rup to query the addresses/hostnames
+defined within it.
 .Sh EXAMPLES
 .Bd -literal
 example% rup otherhost
@@ -81,12 +87,12 @@
 daemon has terminated on the remote host.
 .It rup: RPC: Port mapper failure - RPC: Timed out
 The remote host is not running the portmapper (see
-.Xr portmap 8 ) ,
+.Xr rpcbind 8 ) ,
 and cannot accommodate any RPC-based services.  The host may be down.
 .El
 .Sh SEE ALSO
-.Xr portmap 8 ,
-.Xr rpc.rstatd 8
+.Xr rpc.rstatd 8 ,
+.Xr rpcbind 8
 .Sh HISTORY
 The
 .Nm
diff -ru /usr/src/usr.bin/rup/rup.c /hd3/rup/rup.c
--- /usr/src/usr.bin/rup/rup.c	Mon Apr  5 21:24:45 2004
+++ /hd3/rup/rup.c	Mon Apr  5 22:26:20 2004
@@ -57,6 +57,7 @@
 #include <unistd.h>
 
 #define HOST_WIDTH 15
+#define MAXBUF 512
 
 struct host_list {
 	struct host_list *next;
@@ -107,7 +108,7 @@
 
 	hp = gethostbyaddr((char *)&raddrp->sin_addr.s_addr,
 			   sizeof(struct in_addr), AF_INET);
-	if (hp)
+	if (hp == NULL)
 		host = hp->h_name;
 	else
 		host = inet_ntoa(raddrp->sin_addr);
@@ -220,21 +221,52 @@
 int
 main(int argc, char *argv[])
 {
-	int ch;
-
-	while ((ch = getopt(argc, argv, "?")) != -1)
-		switch (ch) {
-		default:
-			usage();
-			/*NOTREACHED*/
-		}
-
-	setlinebuf(stdout);
-	if (argc == optind)
-		allhosts();
-	else {
-		for (; optind < argc; optind++)
-			(void) onehost(argv[optind]);
-	}
-	exit(0);
+        int             ch, f_flag = 0, i = 0;
+        FILE           *fd;
+        char            file_buf[MAXBUF], *host;
+        
+        while ((ch = getopt(argc, argv, "f:")) != -1)
+                switch (ch) {
+                case 'f':
+                        f_flag = 1;
+                        break;
+                default:
+                        usage();
+                        /* NOTREACHED */
+                }
+        
+        if (!f_flag) {
+                setlinebuf(stdout);
+                if (argc == optind) {
+                        allhosts();
+                } else {
+                        for (; optind < argc; optind++)
+                                onehost(argv[optind]);
+                }
+        } else {
+                if ((fd = fopen(optarg, "r")) == NULL)
+                        err(1, "%s", optarg);
+                                   
+                while (!feof(fd)) {
+                        if (fgets(file_buf, sizeof(file_buf), fd) != NULL) {
+                                if ((host = malloc(sizeof(file_buf))) == NULL)
+                                        err(1, NULL);
+                                bzero(host, sizeof(file_buf));
+                                if (!ferror(fd)) {
+                                        for (i = 0; i < (int)sizeof(file_buf); i++) {
+                                                if (file_buf[i] == '#' || file_buf[i] == '\n' || file_buf[i] == ' ')
+                                                        break;
+        
+                                                host[i] = file_buf[i];
+                                        }
+                                        onehost(host);
+                                } else {
+                                        err(1, NULL);
+                                }
+                                free(host);
+                        }
+                }
+                fclose(fd);
+        }
+        return 0;
 }
--- rup.diff ends here ---



>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list