Ethernet problems

BostonU SysMgr root%bostonu.csnet at CSNET-RELAY.ARPA
Tue Oct 22 00:51:43 AEST 1985


Re: Hedrick's suggestion that the problem may be with your ARP tables:

Here's a hack I use to examine the arp tables on my systems, I think
half of it or more is from something else, but it seems to do the job
(4.2bsd):

---------arpdump.c---------------
#include <stdio.h>
#include <nlist.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

char *fcore = "/dev/kmem", *fnlist = "/vmunix" ;
struct nlist nl[] = {
#define ARPTAB	0
	{ "_arptab" },
	{ "" }
} ;
struct	arptab {
	struct	in_addr at_iaddr;	/* internet address */
	u_char	at_enaddr[6];		/* ethernet address */
	struct	mbuf *at_hold;		/* last packet until resolved/timeout */
	u_char	at_timer;		/* minutes since last reference */
	u_char	at_flags;		/* flags */
};
/* at_flags field values */
#define	ATF_INUSE	1		/* entry in use */
#define ATF_COM		2		/* completed entry (enaddr valid) */

#define	ARPTAB_BSIZ	5		/* bucket size */
#define	ARPTAB_NB	19		/* number of buckets */
#define	ARPTAB_SIZE	(ARPTAB_BSIZ * ARPTAB_NB)
struct	arptab *arptab, atab ;
main(argc,argv) int argc ; char **argv ;
{
	int fc ;
	int i,j ;
	int secs ;
	char *ap ;
	struct hostent *gethostbyaddr(), *hp ;

	if((fc = open(fcore,0)) < 0)
	{
		perror(fcore) ;
		exit(1) ;
	}
	nlist(fnlist,nl) ;
	arptab = (struct arptab *) nl[ARPTAB].n_value ;
	if(nl[0].n_type == 0)
	{
		fprintf(stderr,"No name list %s\n",fnlist) ;
		exit(1) ;
	}
	if(argc > 1) secs = atoi(argv[1]) ;
	else secs = 0 ;
	printf("\t\tACTIVE ARP TABLE DUMP\n") ;
loop:
	printf("Index\tAddr\t\tEthernet Interface\tHostName\n") ;
	lseek(fc,(int) arptab,0) ;
	ap = (char *) &atab.at_iaddr ;
	for(i=0 ; i < ARPTAB_SIZE ; i++)
	{
		if(read(fc,&atab,sizeof atab) != (sizeof atab))
		{
			fprintf(stderr,"Error reading arp table\n") ;
			exit(1) ;
		}
		if(inet_netof(atab.at_iaddr) == 0) continue ;
		printf("%2d:\t",i) ;
		printf("%s\t",ap = (char *) inet_ntoa(atab.at_iaddr)) ;
		for(j=0 ; j < 6 ; j++)
			printf("%02x",atab.at_enaddr[j]) ;
		if((hp = gethostbyaddr(&atab.at_iaddr.s_addr,
					sizeof atab.at_iaddr.s_addr,
					AF_INET)) == NULL)
			printf("\t\t(unknown)") ;
		else printf("\t\t%s",hp->h_name) ;
		printf("\n") ;
	}
	if(secs <= 0) exit(0) ;
	sleep(secs) ;
	goto loop ;
}

	-Barry Shein, Boston University



More information about the Comp.unix.wizards mailing list