diff options
author | wollman <wollman@FreeBSD.org> | 1995-06-15 19:23:08 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 1995-06-15 19:23:08 +0000 |
commit | 7264dc39d63f8dae8d75b031d578ec8c8f78fc8f (patch) | |
tree | f11b139aefc540e95202bc24954c9e09eb9f8779 /usr.sbin/mrouted | |
parent | f2633333178ca2e9cbb032c2bab3a4f323cde737 (diff) | |
download | FreeBSD-src-7264dc39d63f8dae8d75b031d578ec8c8f78fc8f.zip FreeBSD-src-7264dc39d63f8dae8d75b031d578ec8c8f78fc8f.tar.gz |
Add a little program to test the functionality of RSRR by getting
a vif list and printing it a la netstat -g (but simpler). This
doesn't get installed, so there's no man page.
Diffstat (limited to 'usr.sbin/mrouted')
-rw-r--r-- | usr.sbin/mrouted/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/mrouted/testrsrr/Makefile | 14 | ||||
-rw-r--r-- | usr.sbin/mrouted/testrsrr/testrsrr.c | 124 |
3 files changed, 140 insertions, 2 deletions
diff --git a/usr.sbin/mrouted/Makefile b/usr.sbin/mrouted/Makefile index c77b1fb..68f553d 100644 --- a/usr.sbin/mrouted/Makefile +++ b/usr.sbin/mrouted/Makefile @@ -1,5 +1,5 @@ -# $Id$ +# $Id: Makefile,v 1.1 1994/09/08 02:51:09 wollman Exp $ -SUBDIR= common mrouted mrinfo map-mbone mtrace +SUBDIR= common mrouted mrinfo map-mbone mtrace testrsrr .include <bsd.subdir.mk> diff --git a/usr.sbin/mrouted/testrsrr/Makefile b/usr.sbin/mrouted/testrsrr/Makefile new file mode 100644 index 0000000..9e710ff --- /dev/null +++ b/usr.sbin/mrouted/testrsrr/Makefile @@ -0,0 +1,14 @@ +# $Id: Makefile,v 1.1 1994/09/08 02:51:37 wollman Exp $ + +PROG= testrsrr + +S= ${.CURDIR}/.. +.PATH: $S +CFLAGS+= -I$S + +SRCS= testrsrr.c +NOMAN= + +install: + +.include <bsd.prog.mk> diff --git a/usr.sbin/mrouted/testrsrr/testrsrr.c b/usr.sbin/mrouted/testrsrr/testrsrr.c new file mode 100644 index 0000000..b99b593 --- /dev/null +++ b/usr.sbin/mrouted/testrsrr/testrsrr.c @@ -0,0 +1,124 @@ +/* + * Copyright 1995 Massachusetts Institute of Technology + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that both the above copyright notice and this + * permission notice appear in all copies, that both the above + * copyright notice and this permission notice appear in all + * supporting documentation, and that the name of M.I.T. not be used + * in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. M.I.T. makes + * no representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS + * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT + * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ +#include <stddef.h> +#include <stdlib.h> +#include <stdio.h> +#include <err.h> +#include <sysexits.h> + +#include <sys/param.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/socket.h> +#include <sys/un.h> + +#include <netinet/in.h> +#include <arpa/inet.h> + +#include "rsrr.h" + +char sunpath[MAXPATHLEN]; +int s; + +void exitfn(void) { + close(s); + unlink(sunpath); +} + +int main(void) { + struct sockaddr_un sun; + char buf[RSRR_MAX_LEN]; + struct rsrr_header *rh; + struct rsrr_vif *rvp; + int i; + + s = socket(PF_LOCAL, SOCK_DGRAM, 0); + if (s < 0) { + err(EX_OSERR, "socket(PF_LOCAL, SOCK_DGRAM, 0)"); + } + + sun.sun_family = AF_LOCAL; + snprintf(sunpath, sizeof sun.sun_path, "/tmp/testrsrr.%lu", + (unsigned long)getpid()); + strcpy(sun.sun_path, sunpath); + sun.sun_len = (offsetof(struct sockaddr_un, sun_path) + + strlen(sunpath)); + + if (bind(s, (struct sockaddr *)&sun, sun.sun_len) < 0) { + err(EX_OSERR, "bind: %s", sunpath); + } + + atexit(exitfn); /* clean up if we exit on error */ + + strcpy(sun.sun_path, RSRR_SERV_PATH); + sun.sun_len = (offsetof(struct sockaddr_un, sun_path) + + strlen(sunpath)); + + if (connect(s, (struct sockaddr *)&sun, sun.sun_len) < 0) { + err(EX_OSERR, "connect: %s", RSRR_SERV_PATH); + } + + rh = (struct rsrr_header *)buf; + rh->version = RSRR_MAX_VERSION; + rh->type = RSRR_INITIAL_QUERY; + rh->flags = 0; + rh->num = 0; + + if (write(s, rh, sizeof *rh) == (ssize_t)-1) { + err(EX_OSERR, "write(initial query)"); + } + + if (read(s, buf, sizeof buf) == (ssize_t)-1) { + err(EX_OSERR, "read(initial reply)"); + } + + if (rh->version != RSRR_MAX_VERSION) { + errx(EX_PROTOCOL, "bad remote version %d", rh->version); + } + + if (rh->type != RSRR_INITIAL_REPLY) { + errx(EX_PROTOCOL, "remote returned unexpected message type %d", + rh->type); + } + + if (rh->flags) { + printf("confusing flags: %d\n", rh->flags); + } + + printf("There are %d vifs configured:\n", rh->num); + + printf(" Vif Thresh Status Local address\n"); + for(i = 0, rvp = (struct rsrr_vif *)(rh + 1); i < rh->num; i++,rvp++) { + printf(" %3d %6d %6d %s\n", rvp->id, rvp->threshold, + rvp->status, inet_ntoa(rvp->local_addr)); + } + exit(0); +} |