Home | History | Annotate | Line # | Download | only in mrinfo
mrinfo.c revision 1.2
      1  1.1  mycroft /*
      2  1.1  mycroft  * This tool requests configuration info from a multicast router
      3  1.1  mycroft  * and prints the reply (if any).  Invoke it as:
      4  1.1  mycroft  *
      5  1.1  mycroft  *	mrinfo router-name-or-address
      6  1.1  mycroft  *
      7  1.1  mycroft  * Written Wed Mar 24 1993 by Van Jacobson (adapted from the
      8  1.1  mycroft  * multicast mapper written by Pavel Curtis).
      9  1.1  mycroft  *
     10  1.1  mycroft  * The lawyers insist we include the following UC copyright notice.
     11  1.1  mycroft  * The mapper from which this is derived contained a Xerox copyright
     12  1.1  mycroft  * notice which follows the UC one.  Try not to get depressed noting
     13  1.1  mycroft  * that the legal gibberish is larger than the program.
     14  1.1  mycroft  *
     15  1.1  mycroft  * Copyright (c) 1993 Regents of the University of California.
     16  1.1  mycroft  * All rights reserved.
     17  1.1  mycroft  *
     18  1.1  mycroft  * Redistribution and use in source and binary forms, with or without
     19  1.1  mycroft  * modification, are permitted provided that the following conditions
     20  1.1  mycroft  * are met:
     21  1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     22  1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     23  1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     24  1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     25  1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     26  1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     27  1.1  mycroft  *    must display the following acknowledgement:
     28  1.1  mycroft  *	This product includes software developed by the Computer Systems
     29  1.1  mycroft  *	Engineering Group at Lawrence Berkeley Laboratory.
     30  1.1  mycroft  * 4. Neither the name of the University nor of the Laboratory may be used
     31  1.1  mycroft  *    to endorse or promote products derived from this software without
     32  1.1  mycroft  *    specific prior written permission.
     33  1.1  mycroft  *
     34  1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     35  1.1  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     36  1.1  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     37  1.1  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     38  1.1  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     39  1.1  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     40  1.1  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     41  1.1  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     42  1.1  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     43  1.1  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     44  1.1  mycroft  * SUCH DAMAGE.
     45  1.1  mycroft  * ---------------------------------
     46  1.1  mycroft  * Copyright (c) Xerox Corporation 1992. All rights reserved.
     47  1.1  mycroft  *
     48  1.1  mycroft  * License is granted to copy, to use, and to make and to use derivative works
     49  1.1  mycroft  * for research and evaluation purposes, provided that Xerox is acknowledged
     50  1.1  mycroft  * in all documentation pertaining to any such copy or derivative work. Xerox
     51  1.1  mycroft  * grants no other licenses expressed or implied. The Xerox trade name should
     52  1.1  mycroft  * not be used in any advertising without its written permission.
     53  1.1  mycroft  *
     54  1.1  mycroft  * XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
     55  1.1  mycroft  * MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE FOR
     56  1.1  mycroft  * ANY PARTICULAR PURPOSE.  The software is provided "as is" without express
     57  1.1  mycroft  * or implied warranty of any kind.
     58  1.1  mycroft  *
     59  1.1  mycroft  * These notices must be retained in any copies of any part of this software.
     60  1.1  mycroft  */
     61  1.1  mycroft 
     62  1.1  mycroft #ifndef lint
     63  1.1  mycroft static char rcsid[] =
     64  1.2      cgd     "@(#) $Id: mrinfo.c,v 1.2 1995/06/07 17:38:35 cgd Exp $";
     65  1.1  mycroft /*  original rcsid:
     66  1.1  mycroft     "@(#) Header: mrinfo.c,v 1.6 93/04/08 15:14:16 van Exp (LBL)";
     67  1.1  mycroft */
     68  1.1  mycroft #endif
     69  1.1  mycroft 
     70  1.2      cgd #include <string.h>
     71  1.1  mycroft #include <netdb.h>
     72  1.1  mycroft #include <sys/time.h>
     73  1.1  mycroft #include "defs.h"
     74  1.1  mycroft #include <arpa/inet.h>
     75  1.1  mycroft 
     76  1.1  mycroft #define DEFAULT_TIMEOUT	4	/* How long to wait before retrying requests */
     77  1.1  mycroft #define DEFAULT_RETRIES 3	/* How many times to ask each router */
     78  1.1  mycroft 
     79  1.1  mycroft u_int32_t	our_addr, target_addr = 0;	/* in NET order */
     80  1.1  mycroft int     debug = 0;
     81  1.1  mycroft int	nflag = 0;
     82  1.1  mycroft int     retries = DEFAULT_RETRIES;
     83  1.1  mycroft int     timeout = DEFAULT_TIMEOUT;
     84  1.1  mycroft int	target_level;
     85  1.1  mycroft vifi_t  numvifs;		/* to keep loader happy */
     86  1.1  mycroft 				/* (see COPY_TABLES macro called in kern.c) */
     87  1.1  mycroft 
     88  1.1  mycroft char   *
     89  1.1  mycroft inet_name(addr)
     90  1.1  mycroft 	u_int32_t  addr;
     91  1.1  mycroft {
     92  1.1  mycroft 	struct hostent *e;
     93  1.1  mycroft 	struct in_addr in;
     94  1.1  mycroft 
     95  1.1  mycroft 	if (addr == 0)
     96  1.1  mycroft 		return "local";
     97  1.1  mycroft 
     98  1.1  mycroft 	if (nflag ||
     99  1.1  mycroft 	    (e = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET)) == NULL) {
    100  1.1  mycroft 		in.s_addr = addr;
    101  1.1  mycroft 		return (inet_ntoa(in));
    102  1.1  mycroft 	}
    103  1.1  mycroft 	return (e->h_name);
    104  1.1  mycroft }
    105  1.1  mycroft 
    106  1.1  mycroft /*
    107  1.1  mycroft  * Log errors and other messages to stderr, according to the severity of the
    108  1.1  mycroft  * message and the current debug level.  For errors of severity LOG_ERR or
    109  1.1  mycroft  * worse, terminate the program.
    110  1.1  mycroft  */
    111  1.1  mycroft void
    112  1.1  mycroft log(severity, syserr, format, a, b, c, d, e)
    113  1.1  mycroft 	int     severity, syserr;
    114  1.1  mycroft 	char   *format;
    115  1.1  mycroft 	int     a, b, c, d, e;
    116  1.1  mycroft {
    117  1.1  mycroft 	char    fmt[100];
    118  1.1  mycroft 
    119  1.1  mycroft 	switch (debug) {
    120  1.1  mycroft 	case 0:
    121  1.1  mycroft 		if (severity > LOG_WARNING)
    122  1.1  mycroft 			return;
    123  1.1  mycroft 	case 1:
    124  1.1  mycroft 		if (severity > LOG_NOTICE)
    125  1.1  mycroft 			return;
    126  1.1  mycroft 	case 2:
    127  1.1  mycroft 		if (severity > LOG_INFO)
    128  1.1  mycroft 			return;
    129  1.1  mycroft 	default:
    130  1.1  mycroft 		fmt[0] = '\0';
    131  1.1  mycroft 		if (severity == LOG_WARNING)
    132  1.1  mycroft 			strcat(fmt, "warning - ");
    133  1.1  mycroft 		strncat(fmt, format, 80);
    134  1.1  mycroft 		fprintf(stderr, fmt, a, b, c, d, e);
    135  1.1  mycroft 		if (syserr == 0)
    136  1.1  mycroft 			fprintf(stderr, "\n");
    137  1.1  mycroft 		else if (syserr < sys_nerr)
    138  1.1  mycroft 			fprintf(stderr, ": %s\n", sys_errlist[syserr]);
    139  1.1  mycroft 		else
    140  1.1  mycroft 			fprintf(stderr, ": errno %d\n", syserr);
    141  1.1  mycroft 	}
    142  1.1  mycroft 
    143  1.1  mycroft 	if (severity <= LOG_ERR)
    144  1.1  mycroft 		exit(-1);
    145  1.1  mycroft }
    146  1.1  mycroft 
    147  1.1  mycroft /*
    148  1.1  mycroft  * Send a neighbors-list request.
    149  1.1  mycroft  */
    150  1.1  mycroft void
    151  1.1  mycroft ask(dst)
    152  1.1  mycroft 	u_int32_t  dst;
    153  1.1  mycroft {
    154  1.1  mycroft 	send_igmp(our_addr, dst, IGMP_DVMRP, DVMRP_ASK_NEIGHBORS,
    155  1.1  mycroft 			htonl(MROUTED_LEVEL), 0);
    156  1.1  mycroft }
    157  1.1  mycroft 
    158  1.1  mycroft void
    159  1.1  mycroft ask2(dst)
    160  1.1  mycroft 	u_int32_t  dst;
    161  1.1  mycroft {
    162  1.1  mycroft 	send_igmp(our_addr, dst, IGMP_DVMRP, DVMRP_ASK_NEIGHBORS2,
    163  1.1  mycroft 			htonl(MROUTED_LEVEL), 0);
    164  1.1  mycroft }
    165  1.1  mycroft 
    166  1.1  mycroft /*
    167  1.1  mycroft  * Process an incoming neighbor-list message.
    168  1.1  mycroft  */
    169  1.1  mycroft void
    170  1.1  mycroft accept_neighbors(src, dst, p, datalen)
    171  1.1  mycroft 	u_int32_t  src, dst;
    172  1.1  mycroft 	u_char *p;
    173  1.1  mycroft 	int     datalen;
    174  1.1  mycroft {
    175  1.1  mycroft 	u_char *ep = p + datalen;
    176  1.1  mycroft #define GET_ADDR(a) (a = ((u_int32_t)*p++ << 24), a += ((u_int32_t)*p++ << 16),\
    177  1.1  mycroft 		     a += ((u_int32_t)*p++ << 8), a += *p++)
    178  1.1  mycroft 
    179  1.1  mycroft 	printf("%s (%s):\n", inet_fmt(src, s1), inet_name(src));
    180  1.1  mycroft 	while (p < ep) {
    181  1.1  mycroft 		register u_int32_t laddr;
    182  1.1  mycroft 		register u_char metric;
    183  1.1  mycroft 		register u_char thresh;
    184  1.1  mycroft 		register int ncount;
    185  1.1  mycroft 
    186  1.1  mycroft 		GET_ADDR(laddr);
    187  1.1  mycroft 		laddr = htonl(laddr);
    188  1.1  mycroft 		metric = *p++;
    189  1.1  mycroft 		thresh = *p++;
    190  1.1  mycroft 		ncount = *p++;
    191  1.1  mycroft 		while (--ncount >= 0) {
    192  1.1  mycroft 			register u_int32_t neighbor;
    193  1.1  mycroft 			GET_ADDR(neighbor);
    194  1.1  mycroft 			neighbor = htonl(neighbor);
    195  1.1  mycroft 			printf("  %s -> ", inet_fmt(laddr, s1));
    196  1.1  mycroft 			printf("%s (%s) [%d/%d]\n", inet_fmt(neighbor, s1),
    197  1.1  mycroft 			       inet_name(neighbor), metric, thresh);
    198  1.1  mycroft 		}
    199  1.1  mycroft 	}
    200  1.1  mycroft }
    201  1.1  mycroft 
    202  1.1  mycroft void
    203  1.1  mycroft accept_neighbors2(src, dst, p, datalen)
    204  1.1  mycroft 	u_int32_t  src, dst;
    205  1.1  mycroft 	u_char *p;
    206  1.1  mycroft 	int     datalen;
    207  1.1  mycroft {
    208  1.1  mycroft 	u_char *ep = p + datalen;
    209  1.1  mycroft 	u_int broken_cisco = ((target_level & 0xffff) == 0x020a); /* 10.2 */
    210  1.1  mycroft 	/* well, only possibly_broken_cisco, but that's too long to type. */
    211  1.1  mycroft 
    212  1.1  mycroft 	printf("%s (%s) [version %d.%d]:\n", inet_fmt(src, s1), inet_name(src),
    213  1.1  mycroft 	       target_level & 0xff, (target_level >> 8) & 0xff);
    214  1.1  mycroft 
    215  1.1  mycroft 	while (p < ep) {
    216  1.1  mycroft 		register u_char metric;
    217  1.1  mycroft 		register u_char thresh;
    218  1.1  mycroft 		register u_char flags;
    219  1.1  mycroft 		register int ncount;
    220  1.1  mycroft 		register u_int32_t laddr = *(u_int32_t*)p;
    221  1.1  mycroft 
    222  1.1  mycroft 		p += 4;
    223  1.1  mycroft 		metric = *p++;
    224  1.1  mycroft 		thresh = *p++;
    225  1.1  mycroft 		flags = *p++;
    226  1.1  mycroft 		ncount = *p++;
    227  1.1  mycroft 		if (broken_cisco && ncount == 0)	/* dumb Ciscos */
    228  1.1  mycroft 			ncount = 1;
    229  1.1  mycroft 		if (broken_cisco && ncount > 15)	/* dumb Ciscos */
    230  1.1  mycroft 			ncount = ncount & 0xf;
    231  1.1  mycroft 		while (--ncount >= 0 && p < ep) {
    232  1.1  mycroft 			register u_int32_t neighbor = *(u_int32_t*)p;
    233  1.1  mycroft 			p += 4;
    234  1.1  mycroft 			printf("  %s -> ", inet_fmt(laddr, s1));
    235  1.1  mycroft 			printf("%s (%s) [%d/%d", inet_fmt(neighbor, s1),
    236  1.1  mycroft 			       inet_name(neighbor), metric, thresh);
    237  1.1  mycroft 			if (flags & DVMRP_NF_TUNNEL)
    238  1.1  mycroft 				printf("/tunnel");
    239  1.1  mycroft 			if (flags & DVMRP_NF_SRCRT)
    240  1.1  mycroft 				printf("/srcrt");
    241  1.1  mycroft 			if (flags & DVMRP_NF_PIM)
    242  1.1  mycroft 				printf("/pim");
    243  1.1  mycroft 			if (flags & DVMRP_NF_QUERIER)
    244  1.1  mycroft 				printf("/querier");
    245  1.1  mycroft 			if (flags & DVMRP_NF_DISABLED)
    246  1.1  mycroft 				printf("/disabled");
    247  1.1  mycroft 			if (flags & DVMRP_NF_DOWN)
    248  1.1  mycroft 				printf("/down");
    249  1.1  mycroft 			if (flags & DVMRP_NF_LEAF)
    250  1.1  mycroft 				printf("/leaf");
    251  1.1  mycroft 			printf("]\n");
    252  1.1  mycroft 		}
    253  1.1  mycroft 	}
    254  1.1  mycroft }
    255  1.1  mycroft 
    256  1.1  mycroft int
    257  1.1  mycroft get_number(var, deflt, pargv, pargc)
    258  1.1  mycroft 	int    *var, *pargc, deflt;
    259  1.1  mycroft 	char ***pargv;
    260  1.1  mycroft {
    261  1.1  mycroft 	if ((*pargv)[0][2] == '\0') {	/* Get the value from the next
    262  1.1  mycroft 					 * argument */
    263  1.1  mycroft 		if (*pargc > 1 && isdigit((*pargv)[1][0])) {
    264  1.1  mycroft 			(*pargv)++, (*pargc)--;
    265  1.1  mycroft 			*var = atoi((*pargv)[0]);
    266  1.1  mycroft 			return 1;
    267  1.1  mycroft 		} else if (deflt >= 0) {
    268  1.1  mycroft 			*var = deflt;
    269  1.1  mycroft 			return 1;
    270  1.1  mycroft 		} else
    271  1.1  mycroft 			return 0;
    272  1.1  mycroft 	} else {		/* Get value from the rest of this argument */
    273  1.1  mycroft 		if (isdigit((*pargv)[0][2])) {
    274  1.1  mycroft 			*var = atoi((*pargv)[0] + 2);
    275  1.1  mycroft 			return 1;
    276  1.1  mycroft 		} else {
    277  1.1  mycroft 			return 0;
    278  1.1  mycroft 		}
    279  1.1  mycroft 	}
    280  1.1  mycroft }
    281  1.1  mycroft 
    282  1.1  mycroft u_int32_t
    283  1.1  mycroft host_addr(name)
    284  1.1  mycroft 	char   *name;
    285  1.1  mycroft {
    286  1.1  mycroft 	struct hostent *e;
    287  1.1  mycroft 	u_int32_t		addr;
    288  1.1  mycroft 
    289  1.1  mycroft 	addr = inet_addr(name);
    290  1.1  mycroft 	if ((int)addr == -1) {
    291  1.1  mycroft 		e = gethostbyname(name);
    292  1.1  mycroft 		if (e == NULL || e->h_length != sizeof(addr))
    293  1.1  mycroft 			return (0);
    294  1.1  mycroft 		memcpy(&addr, e->h_addr_list[0], e->h_length);
    295  1.1  mycroft 	}
    296  1.1  mycroft 	return(addr);
    297  1.1  mycroft }
    298  1.1  mycroft 
    299  1.1  mycroft void
    300  1.1  mycroft usage()
    301  1.1  mycroft {
    302  1.1  mycroft 	fprintf(stderr,
    303  1.1  mycroft 	    "Usage: mrinfo [-n] [-t timeout] [-r retries] [router]\n");
    304  1.1  mycroft 	exit(1);
    305  1.1  mycroft }
    306  1.1  mycroft 
    307  1.1  mycroft int
    308  1.1  mycroft main(argc, argv)
    309  1.1  mycroft 	int     argc;
    310  1.1  mycroft 	char   *argv[];
    311  1.1  mycroft {
    312  1.1  mycroft 	setlinebuf(stderr);
    313  1.1  mycroft 
    314  1.1  mycroft 	if (geteuid() != 0) {
    315  1.1  mycroft 		fprintf(stderr, "mrinfo: must be root\n");
    316  1.1  mycroft 		exit(1);
    317  1.1  mycroft 	}
    318  1.1  mycroft 	argv++, argc--;
    319  1.1  mycroft 	while (argc > 0 && argv[0][0] == '-') {
    320  1.1  mycroft 		switch (argv[0][1]) {
    321  1.1  mycroft 		case 'd':
    322  1.1  mycroft 			if (!get_number(&debug, DEFAULT_DEBUG, &argv, &argc))
    323  1.1  mycroft 				usage();
    324  1.1  mycroft 			break;
    325  1.1  mycroft 		case 'n':
    326  1.1  mycroft 			++nflag;
    327  1.1  mycroft 			break;
    328  1.1  mycroft 		case 'r':
    329  1.1  mycroft 			if (!get_number(&retries, -1, &argv, &argc))
    330  1.1  mycroft 				usage();
    331  1.1  mycroft 			break;
    332  1.1  mycroft 		case 't':
    333  1.1  mycroft 			if (!get_number(&timeout, -1, &argv, &argc))
    334  1.1  mycroft 				usage();
    335  1.1  mycroft 			break;
    336  1.1  mycroft 		default:
    337  1.1  mycroft 			usage();
    338  1.1  mycroft 		}
    339  1.1  mycroft 		argv++, argc--;
    340  1.1  mycroft 	}
    341  1.1  mycroft 	if (argc > 1)
    342  1.1  mycroft 		usage();
    343  1.1  mycroft 	if (argc == 1)
    344  1.1  mycroft 		target_addr = host_addr(argv[0]);
    345  1.1  mycroft 	else
    346  1.1  mycroft 		target_addr = host_addr("127.0.0.1");
    347  1.1  mycroft 
    348  1.1  mycroft 	if (target_addr == 0) {
    349  1.1  mycroft 		fprintf(stderr, "mrinfo: %s: no such host\n", argv[0]);
    350  1.1  mycroft 		exit(1);
    351  1.1  mycroft 	}
    352  1.1  mycroft 	if (debug)
    353  1.1  mycroft 		fprintf(stderr, "Debug level %u\n", debug);
    354  1.1  mycroft 
    355  1.1  mycroft 	init_igmp();
    356  1.1  mycroft 
    357  1.1  mycroft 	{			/* Find a good local address for us. */
    358  1.1  mycroft 		int     udp;
    359  1.1  mycroft 		struct sockaddr_in addr;
    360  1.1  mycroft 		int     addrlen = sizeof(addr);
    361  1.1  mycroft 
    362  1.1  mycroft 		addr.sin_family = AF_INET;
    363  1.1  mycroft #if (defined(BSD) && (BSD >= 199103))
    364  1.1  mycroft 		addr.sin_len = sizeof addr;
    365  1.1  mycroft #endif
    366  1.1  mycroft 		addr.sin_addr.s_addr = target_addr;
    367  1.1  mycroft 		addr.sin_port = htons(2000);	/* any port over 1024 will
    368  1.1  mycroft 						 * do... */
    369  1.1  mycroft 		if ((udp = socket(AF_INET, SOCK_DGRAM, 0)) < 0
    370  1.1  mycroft 		|| connect(udp, (struct sockaddr *) & addr, sizeof(addr)) < 0
    371  1.1  mycroft 		    || getsockname(udp, (struct sockaddr *) & addr, &addrlen) < 0) {
    372  1.1  mycroft 			perror("Determining local address");
    373  1.1  mycroft 			exit(-1);
    374  1.1  mycroft 		}
    375  1.1  mycroft 		close(udp);
    376  1.1  mycroft 		our_addr = addr.sin_addr.s_addr;
    377  1.1  mycroft 	}
    378  1.1  mycroft 
    379  1.1  mycroft 	ask(target_addr);
    380  1.1  mycroft 
    381  1.1  mycroft 	/* Main receive loop */
    382  1.1  mycroft 	for (;;) {
    383  1.1  mycroft 		fd_set  fds;
    384  1.1  mycroft 		struct timeval tv;
    385  1.1  mycroft 		int     count, recvlen, dummy = 0;
    386  1.1  mycroft 		register u_int32_t src, dst, group;
    387  1.1  mycroft 		struct ip *ip;
    388  1.1  mycroft 		struct igmp *igmp;
    389  1.1  mycroft 		int     ipdatalen, iphdrlen, igmpdatalen;
    390  1.1  mycroft 
    391  1.1  mycroft 		FD_ZERO(&fds);
    392  1.1  mycroft 		FD_SET(igmp_socket, &fds);
    393  1.1  mycroft 
    394  1.1  mycroft 		tv.tv_sec = timeout;
    395  1.1  mycroft 		tv.tv_usec = 0;
    396  1.1  mycroft 
    397  1.1  mycroft 		count = select(igmp_socket + 1, &fds, 0, 0, &tv);
    398  1.1  mycroft 
    399  1.1  mycroft 		if (count < 0) {
    400  1.1  mycroft 			if (errno != EINTR)
    401  1.1  mycroft 				perror("select");
    402  1.1  mycroft 			continue;
    403  1.1  mycroft 		} else if (count == 0) {
    404  1.1  mycroft 			log(LOG_DEBUG, 0, "Timed out receiving neighbor lists");
    405  1.1  mycroft 			if (--retries < 0)
    406  1.1  mycroft 				exit(1);
    407  1.1  mycroft 			if (target_level == 0)
    408  1.1  mycroft 				ask(target_addr);
    409  1.1  mycroft 			else
    410  1.1  mycroft 				ask2(target_addr);
    411  1.1  mycroft 			continue;
    412  1.1  mycroft 		}
    413  1.1  mycroft 		recvlen = recvfrom(igmp_socket, recv_buf, RECV_BUF_SIZE,
    414  1.1  mycroft 				   0, NULL, &dummy);
    415  1.1  mycroft 		if (recvlen <= 0) {
    416  1.1  mycroft 			if (recvlen && errno != EINTR)
    417  1.1  mycroft 				perror("recvfrom");
    418  1.1  mycroft 			continue;
    419  1.1  mycroft 		}
    420  1.1  mycroft 
    421  1.1  mycroft 		if (recvlen < sizeof(struct ip)) {
    422  1.1  mycroft 			log(LOG_WARNING, 0,
    423  1.1  mycroft 			    "packet too short (%u bytes) for IP header",
    424  1.1  mycroft 			    recvlen);
    425  1.1  mycroft 			continue;
    426  1.1  mycroft 		}
    427  1.1  mycroft 		ip = (struct ip *) recv_buf;
    428  1.1  mycroft 		if (ip->ip_p == 0)
    429  1.1  mycroft 			continue;	/* Request to install cache entry */
    430  1.1  mycroft 		src = ip->ip_src.s_addr;
    431  1.1  mycroft 		dst = ip->ip_dst.s_addr;
    432  1.1  mycroft 		iphdrlen = ip->ip_hl << 2;
    433  1.1  mycroft 		ipdatalen = ip->ip_len;
    434  1.1  mycroft 		if (iphdrlen + ipdatalen != recvlen) {
    435  1.1  mycroft 			log(LOG_WARNING, 0,
    436  1.1  mycroft 			    "packet shorter (%u bytes) than hdr+data length (%u+%u)",
    437  1.1  mycroft 			    recvlen, iphdrlen, ipdatalen);
    438  1.1  mycroft 			continue;
    439  1.1  mycroft 		}
    440  1.1  mycroft 		igmp = (struct igmp *) (recv_buf + iphdrlen);
    441  1.1  mycroft 		group = igmp->igmp_group.s_addr;
    442  1.1  mycroft 		igmpdatalen = ipdatalen - IGMP_MINLEN;
    443  1.1  mycroft 		if (igmpdatalen < 0) {
    444  1.1  mycroft 			log(LOG_WARNING, 0,
    445  1.1  mycroft 			    "IP data field too short (%u bytes) for IGMP, from %s",
    446  1.1  mycroft 			    ipdatalen, inet_fmt(src, s1));
    447  1.1  mycroft 			continue;
    448  1.1  mycroft 		}
    449  1.1  mycroft 		if (igmp->igmp_type != IGMP_DVMRP)
    450  1.1  mycroft 			continue;
    451  1.1  mycroft 
    452  1.1  mycroft 		switch (igmp->igmp_code) {
    453  1.1  mycroft 		case DVMRP_NEIGHBORS:
    454  1.1  mycroft 		case DVMRP_NEIGHBORS2:
    455  1.1  mycroft 			if (src != target_addr) {
    456  1.1  mycroft 				fprintf(stderr, "mrinfo: got reply from %s",
    457  1.1  mycroft 					inet_fmt(src, s1));
    458  1.1  mycroft 				fprintf(stderr, " instead of %s\n",
    459  1.1  mycroft 					inet_fmt(target_addr, s1));
    460  1.1  mycroft 				/*continue;*/
    461  1.1  mycroft 			}
    462  1.1  mycroft 			break;
    463  1.1  mycroft 		default:
    464  1.1  mycroft 			continue;	/* ignore all other DVMRP messages */
    465  1.1  mycroft 		}
    466  1.1  mycroft 
    467  1.1  mycroft 		switch (igmp->igmp_code) {
    468  1.1  mycroft 
    469  1.1  mycroft 		case DVMRP_NEIGHBORS:
    470  1.1  mycroft 			if (group) {
    471  1.1  mycroft 				/* knows about DVMRP_NEIGHBORS2 msg */
    472  1.1  mycroft 				if (target_level == 0) {
    473  1.1  mycroft 					target_level = ntohl(group);
    474  1.1  mycroft 					ask2(target_addr);
    475  1.1  mycroft 				}
    476  1.1  mycroft 			} else {
    477  1.1  mycroft 				accept_neighbors(src, dst, (char *)(igmp + 1),
    478  1.1  mycroft 						 igmpdatalen);
    479  1.1  mycroft 				exit(0);
    480  1.1  mycroft 			}
    481  1.1  mycroft 			break;
    482  1.1  mycroft 
    483  1.1  mycroft 		case DVMRP_NEIGHBORS2:
    484  1.1  mycroft 			accept_neighbors2(src, dst, (char *)(igmp + 1),
    485  1.1  mycroft 					  igmpdatalen);
    486  1.1  mycroft 			exit(0);
    487  1.1  mycroft 		}
    488  1.1  mycroft 	}
    489  1.1  mycroft }
    490  1.1  mycroft 
    491  1.1  mycroft /* dummies */
    492  1.1  mycroft void accept_probe()
    493  1.1  mycroft {
    494  1.1  mycroft }
    495  1.1  mycroft void accept_group_report()
    496  1.1  mycroft {
    497  1.1  mycroft }
    498  1.1  mycroft void accept_neighbor_request2()
    499  1.1  mycroft {
    500  1.1  mycroft }
    501  1.1  mycroft void accept_report()
    502  1.1  mycroft {
    503  1.1  mycroft }
    504  1.1  mycroft void accept_neighbor_request()
    505  1.1  mycroft {
    506  1.1  mycroft }
    507  1.1  mycroft void accept_prune()
    508  1.1  mycroft {
    509  1.1  mycroft }
    510  1.1  mycroft void accept_graft()
    511  1.1  mycroft {
    512  1.1  mycroft }
    513  1.1  mycroft void accept_g_ack()
    514  1.1  mycroft {
    515  1.1  mycroft }
    516  1.1  mycroft void add_table_entry()
    517  1.1  mycroft {
    518  1.1  mycroft }
    519  1.1  mycroft void check_vif_state()
    520  1.1  mycroft {
    521  1.1  mycroft }
    522  1.1  mycroft void accept_leave_message()
    523  1.1  mycroft {
    524  1.1  mycroft }
    525  1.1  mycroft void accept_mtrace()
    526  1.1  mycroft {
    527  1.1  mycroft }
    528  1.1  mycroft void accept_membership_query()
    529  1.1  mycroft {
    530  1.1  mycroft }
    531