XINU
xsh_udpdump.c
Go to the documentation of this file.
1 /* xsh_udpdump.c - xsh_udpdump */
2 
3 #include <xinu.h>
4 #include <stdio.h>
5 #include <string.h>
6 
7 /*------------------------------------------------------------------------
8  * xsh_udpdump - shell command to dump the UDP registered ports
9  *------------------------------------------------------------------------
10  */
11 shellcmd xsh_udpdump(int nargs, char *args[])
12 {
13  int32 i; /* index into udptab */
14  char *udpstate[] = { /* names for entry states */
15  "free ", "used ", "recv "};
16  struct udpentry *uptr; /* ptr to entry in udptab */
17  uint32 remip; /* variables to hold the info */
18  int32 r1,r2,r3,r4; /* from an entry for printing */
19  int32 remprt, locprt;
20  int32 state;
21  pid32 pid;
22 
23 
24  /* For argument '--help', emit help about the 'udpdump' command */
25 
26  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
27  printf("Use: %s\n\n", args[0]);
28  printf("Description:\n");
29  printf("\tDisplays registerd UDP ports\n");
30  printf("Options:\n");
31  printf("\t--help\t display this help and exit\n");
32  return 0;
33  }
34 
35  /* Check for valid number of arguments */
36 
37  if (nargs > 1) {
38  fprintf(stderr, "%s: no argumentd expected\n", args[0]);
39  fprintf(stderr, "Try '%s --help' for more information\n",
40  args[0]);
41  return 1;
42  }
43 
44  /* Print header for items from UDP table */
45 
46  printf("%5s %5s %5s %9s %8s %8s %3s %4s\n",
47  "Entry", "Iface", "State", "Remote IP", "Rem Port",
48  "Loc Port", "Pid", "Pkts");
49  printf("%5s %5s %5s %15s %8s %8s %3s %4s\n",
50  "-----", "-----", "-----", "---------------", "--------",
51  "--------", "---", "----");
52 
53  /* Output information for each valid entry in udptab */
54  for (i = 0; i < UDP_SLOTS; i++) {
55  uptr = &udptab[i];
56  if (uptr->udstate == UDP_FREE) { /* skip unused slots */
57  printf("%3d ---- slot is free ---\n", i);
58  continue;
59  }
60  remip = uptr->udremip;
61  r1 = (remip >> 24) & 0xff;
62  r2 = (remip >> 16) & 0xff;
63  r3 = (remip >> 8) & 0xff;
64  r4 = (remip ) & 0xff;
65  remprt = uptr->udremport;
66  locprt = uptr->udlocport;
67  pid = uptr->udpid;
68  state = uptr->udstate;
69  printf(" %4s %3d.%3d.%3d.%3d %5d %6d%5d%6d\n",
70  udpstate[state], r1, r2, r3, r4, remprt, locprt, pid,
71  uptr->udcount);
72  }
73  return 0;
74 }
uint16 udremport
Definition: udp.h:24
int32 strncmp(const char *, const char *, int32)
全てのシステムヘッダファイルをインクルードする。
uint32 udremip
Definition: udp.h:22
int32 udcount
Definition: udp.h:28
#define stderr
Definition: stdio.h:17
#define UDP_SLOTS
Definition: udp.h:3
int32 printf(const char *,...)
Definition: printf.c:13
pid32 udpid
Definition: udp.h:29
Definition: udp.h:20
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 udlocport
Definition: udp.h:25
struct udpentry udptab[]
Definition: udp.c:6
int32 udstate
Definition: udp.h:21
int32 pid32
プロセスID
Definition: kernel.h:26
shellcmd xsh_udpdump(int nargs, char *args[])
Definition: xsh_udpdump.c:11
int32 shellcmd
シェルコール関数 返り値の型
Definition: kernel.h:51
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
#define UDP_FREE
Definition: udp.h:11