arpprint.c,v

来自「TCP-IP红宝书源代码」· C,V 代码 · 共 145 行

C,V
145
字号
head	1.2;
access;
symbols;
locks
	dls:1.2; strict;
comment	@ * @;


1.2
date	97.09.21.19.22.42;	author dls;	state Dist;
branches;
next	1.1;

1.1
date	94.09.24.17.58.32;	author dls;	state Old;
branches;
next	;


desc
@@


1.2
log
@*** empty log message ***
@
text
@/* arpprint - arpprint */

#include <conf.h>
#include <kernel.h>
#include <network.h>

#define HDR1 \
"Intf.   IP address     Physical Address   HW  Proto   State       TTL\n"
#define HDR2 \
"----- ---------------  -----------------  --  -----  --------  ---------\n"

static int	printone();

/*------------------------------------------------------------------------
 * arpprint - print the ARP table on descriptor fd
 *------------------------------------------------------------------------
 */
int
arpprint(fd)
int	fd;
{
	int	i;

	write(fd, HDR1, strlen(HDR1));
	write(fd, HDR2, strlen(HDR2));
	for (i = 0; i<ARP_TSIZE; ++i)
		if (arptable[i].ae_state != AS_FREE)
			printone(fd, &arptable[i]);
	return OK;
}

char	*index();

/*------------------------------------------------------------------------
 * printone - print one entry in the ARP table
 *------------------------------------------------------------------------
 */
static int
printone(fd, pae)
int	fd;
struct	arpentry	*pae;
{
	char	line[128], *p;
	int	i;

	sprintf(line, " %2d    ", pae->ae_pni - &nif[0]);
	p = index(line, '\0');

	for (i=0; i<pae->ae_prlen-1; ++i) {
		sprintf(p, "%u.", pae->ae_pra[i] & 0xff);
		p = index(p, '\0');
	}
	sprintf(p, "%u", pae->ae_pra[i]);
	for (i=strlen(line); i<23; ++i)
		line[i] = ' ';
	p = &line[23];

	for (i=0; i<pae->ae_hwlen-1; ++i) {
		sprintf(p, "%02x:", pae->ae_hwa[i] & 0xff);
		p = index(p, '\0');
	}
	sprintf(p, "%02x  %2d   %04x  %8s  ", pae->ae_hwa[i] & 0xff,
		pae->ae_hwtype, pae->ae_prtype,
		(pae->ae_state == AS_RESOLVED) ? "RESOLVED" : "PENDING");
	p = index(p, '\0');

	if (pae->ae_ttl == ARP_INF)
		strcpy(p, "(permanent)\n");
	else
		sprintf(p, "%8d s\n", pae->ae_ttl);
	return write(fd, line, strlen(line));
}
@


1.1
log
@Initial revision
@
text
@d7 6
a12 1
static	printone();
d18 1
d24 2
d38 1
a38 1
static
d44 1
a44 1
	int	i, inum;
d46 1
a46 4
	if (pae->ae_state == AS_RESOLVED)
		strcpy(line, "RESOLVED ");
	else
		strcpy(line, "PENDING  ");
d53 4
a56 4
	sprintf(p, "%u ", pae->ae_pra[i] & 0xff);
	p = index(p, '\0');

	inum = pae->ae_pni - &nif[0];
d62 5
d68 1
a68 3
		sprintf(p, "%x  hw %d pr %x inum %d ttl (permanent)\n",
		    pae->ae_hwa[i]&0xff, pae->ae_hwtype, pae->ae_prtype,
		    inum);
d70 1
a70 4
		sprintf(p, "%x  hw %d pr %x inum %d ttl %d s\n",
		    pae->ae_hwa[i]&0xff, pae->ae_hwtype, pae->ae_prtype,
		    inum, pae->ae_ttl);
	p = index(p, '\0');
@

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?