From owner-freebsd-bugs@FreeBSD.ORG Mon Apr 5 15:30:13 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1D07B16A4CE for ; Mon, 5 Apr 2004 15:30:13 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 138AA43D60 for ; Mon, 5 Apr 2004 15:30:13 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i35MUAbv011381 for ; Mon, 5 Apr 2004 15:30:10 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i35MUA6r011380; Mon, 5 Apr 2004 15:30:10 -0700 (PDT) (envelope-from gnats) Resent-Date: Mon, 5 Apr 2004 15:30:10 -0700 (PDT) Resent-Message-Id: <200404052230.i35MUA6r011380@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "Liam Foy" Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5300B16A4CE for ; Mon, 5 Apr 2004 15:23:51 -0700 (PDT) Received: from moutvdomng.kundenserver.de (moutvdom.kundenserver.de [212.227.126.249]) by mx1.FreeBSD.org (Postfix) with ESMTP id 86A5743D58 for ; Mon, 5 Apr 2004 15:23:50 -0700 (PDT) (envelope-from liamfoy@sepulcrum.org) Received: from [212.227.126.221] (helo=mrvdomng.kundenserver.de) by moutvdomng.kundenserver.de with esmtp (Exim 3.35 #1) id 1BAcVR-0006pH-00 for FreeBSD-gnats-submit@freebsd.org; Tue, 06 Apr 2004 00:23:49 +0200 Received: from [217.43.131.141] (helo=liamfoy) by mrvdomng.kundenserver.de with esmtp (Exim 3.35 #1) id 1BAcVR-0005G9-00 for FreeBSD-gnats-submit@freebsd.org; Tue, 06 Apr 2004 00:23:49 +0200 Message-Id: <1081203819.0@liamfoy> Date: Mon, 5 Apr 2004 23:23:39 +0100 From: "Liam Foy" To: "FreeBSD gnats submit" X-Send-Pr-Version: gtk-send-pr 0.3.3 Subject: bin/65228: [Patch]Allow rup to parse hostnames from a defined file. X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Apr 2004 22:30:13 -0000 >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 .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 +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 #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: