XINU
xsh_arp.c
Go to the documentation of this file.
1 /* xsh_arp.c - xsh_arp */
2 
3 #include <xinu.h>
4 #include <stdio.h>
5 #include <string.h>
6 
7 static void arp_dmp();
8 /*------------------------------------------------------------------------
9  * xsh_arp - display the current ARP cache for an interface
10  *------------------------------------------------------------------------
11  */
12 shellcmd xsh_arp(int nargs, char *args[])
13 {
14  /* For argument '--help', emit help about the 'arp' command */
15 
16  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
17  printf("Use: %s\n\n", args[0]);
18  printf("Description:\n");
19  printf("\tDisplays information from the ARP cache\n");
20  printf("Options:\n");
21  printf("\t--help\t display this help and exit\n");
22  return 0;
23  }
24 
25  /* Dump the Entire ARP cache */
26  printf("\n");
27  arp_dmp();
28 
29  return 0;
30 }
31 
32 
33 /*------------------------------------------------------------------------
34  * arp_dmp - dump the ARP cache
35  *------------------------------------------------------------------------
36  */
37 static void arp_dmp ()
38 {
39  int32 i, j; /* index into the ARP table */
40  struct arpentry *arptr; /* pointer to entry in cache */
41 
42  /* Print entries from the ARP table */
43 
44  printf("ARP cache:\n");
45  printf(" State Pid IP Address Hardware Address\n");
46  printf(" ----- --- --------------- -----------------\n");
47  for (i = 0; i < ARP_SIZ; i++) {
48  arptr = &arpcache[i];
49  if (arptr->arstate == AR_FREE) {
50  continue;
51  }
52  switch(arptr->arstate) {
53  case AR_PENDING: printf(" PEND "); break;
54  case AR_RESOLVED: printf(" RESLV"); break;
55  default: printf(" ?????"); break;
56  }
57  if (arptr->arstate == AR_PENDING) {
58  printf("%4d ", arptr->arpid);
59  } else {
60  printf(" ");
61  }
62  printf("%3d.", (arptr->arpaddr & 0xFF000000) >> 24);
63  printf("%3d.", (arptr->arpaddr & 0x00FF0000) >> 16);
64  printf("%3d.", (arptr->arpaddr & 0x0000FF00) >> 8);
65  printf("%3d", (arptr->arpaddr & 0x000000FF));
66 
67  printf(" %02X", arptr->arhaddr[0]);
68  for (j = 1; j < ARP_HALEN; j++) {
69  printf(":%02X", arptr->arhaddr[j]);
70  }
71  printf("\n");
72  }
73  printf("\n");
74  return;
75 }
#define AR_FREE
ARPキャッシュエントリ状態:スロットが未使用
Definition: arp.h:27
#define ARP_SIZ
キャシュ中のエントリ数
Definition: arp.h:20
int32 strncmp(const char *, const char *, int32)
全てのシステムヘッダファイルをインクルードする。
int32 printf(const char *,...)
Definition: printf.c:13
int32 arstate
エントリの状態
Definition: arp.h:75
struct arpentry arpcache[]
ARPキャッシュエントリテーブル
Definition: arp.c:5
uint32 arpaddr
エントリのIPアドレス
Definition: arp.h:77
#define ARP_HALEN
EthernetのMACアドレスサイズ
Definition: arp.h:8
ARPキャッシュエントリ
Definition: arp.h:72
shellcmd xsh_arp(int nargs, char *args[])
Definition: xsh_arp.c:12
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
byte arhaddr[ARP_HALEN]
エントリのEthernetアドレス
Definition: arp.h:81
static void arp_dmp()
Definition: xsh_arp.c:37
#define AR_RESOLVED
ARPキャッシュエントリ状態:エントリが正常
Definition: arp.h:31
int32 shellcmd
シェルコール関数 返り値の型
Definition: kernel.h:51
pid32 arpid
待機中プロセスか-1
Definition: arp.h:79
#define AR_PENDING
ARPキャッシュエントリ状態:解決中
Definition: arp.h:29