XINU
Functions
shprototypes.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

shellcmd xsh_argecho (int32, char *[])
 引数を順に表示する。 More...
 
shellcmd xsh_arp (int32, char *[])
 
shellcmd xsh_bingid (int32, char *[])
 
shellcmd xsh_cat (int32, char *[])
 
shellcmd xsh_clear (int32, char *[])
 ディスプレイウィンドウをクリアする(xtermやVT100を想定している) More...
 
shellcmd xsh_date (int32, char *[])
 
shellcmd xsh_devdump (int32, char *[])
 
shellcmd xsh_echo (int32, char *[])
 STDOUT(標準出力)に引数に指定した文字列を出力する。 More...
 
shellcmd xsh_ethstat (int32, char *[])
 
shellcmd xsh_exit (int32, char *[])
 exitコマンドとして、シェル終了を引き起こす終了コードを返す。 More...
 
shellcmd xsh_help (int32, char *[])
 
shellcmd xsh_kill (int32, char *[])
 
shellcmd xsh_led (int32, char *[])
 
shellcmd xsh_ls (int32, char *[])
 
shellcmd xsh_memdump (int32, char *[])
 
shellcmd xsh_memstat (int32, char *[])
 
shellcmd xsh_netinfo (int32, char *[])
 
shellcmd xsh_nvram (int32, char *[])
 
shellcmd xsh_ping (int32, char *[])
 
shellcmd xsh_ps (int32, char *[])
 
shellcmd xsh_sleep (int32, char *[])
 
shellcmd xsh_udpdump (int32, char *[])
 
shellcmd xsh_udpecho (int32, char *[])
 
shellcmd xsh_udpeserver (int32, char *[])
 
shellcmd xsh_uptime (int32, char *[])
 

Function Documentation

◆ xsh_argecho()

shellcmd xsh_argecho ( int  nargs,
char *  args[] 
)

引数を順に表示する。

「引数番号」と「引数番号に対応する引数(文字列として扱う)」が1行単位で出力される。

Parameters
[in]nargs引数の数
[in]args引数(引数を持つ配列)
Returns
0を返す。

Definition at line 15 of file xsh_argecho.c.

References printf().

16 {
17  int32 i;
18 
19  printf("\n\nThe %d arguments are:\n", nargs);
20  for (i = 0; i < nargs; i++)
21  {
22  printf(" %2d: %s\n", i, args[i]);
23  }
24  printf("\n");
25 
26  return 0;
27 }
int32 printf(const char *,...)
Definition: printf.c:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
Here is the call graph for this function:

◆ xsh_arp()

shellcmd xsh_arp ( int32  ,
char *  [] 
)

Definition at line 12 of file xsh_arp.c.

References arp_dmp(), printf(), and strncmp().

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 }
int32 strncmp(const char *, const char *, int32)
int32 printf(const char *,...)
Definition: printf.c:13
static void arp_dmp()
Definition: xsh_arp.c:37
Here is the call graph for this function:

◆ xsh_bingid()

shellcmd xsh_bingid ( int32  ,
char *  [] 
)

◆ xsh_cat()

shellcmd xsh_cat ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_cat.c.

References close(), EOF, fprintf(), getc(), NAMESPACE, NULLCH, open(), printf(), putc(), stderr, stdin, stdout, strncmp(), and SYSERR.

12 {
13  int32 i; /* index into proctabl */
14  int32 nextch; /* character read from file */
15  did32 descr; /* descriptor for a file */
16  char *argptr; /* pointer to next arg string */
17 
18 
19  /* For argument '--help', emit help about the 'cat' command */
20 
21  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
22  printf("Use: %s [file...]\n\n", args[0]);
23  printf("Description:\n");
24  printf("\twrites contents of files or stdin to stdout\n");
25  printf("Options:\n");
26  printf("\tfile...\tzero or more file names\n");
27  printf("\t--help\t display this help and exit\n");
28  return 0;
29  }
30 
31  if (nargs == 1) {
32  nextch = getc(stdin);
33  while (nextch != EOF) {
34  putc(stdout, nextch);
35  nextch = getc(stdin);
36  }
37  return 0;
38  }
39  for (i = 1; i < nargs; i++) {
40  argptr = args[i];
41  if ( (argptr[0] == '-') && (argptr[1] == NULLCH) ) {
42  descr = stdin;
43  } else {
44  descr = open(NAMESPACE, argptr, "ro");
45  if (descr == (did32)SYSERR) {
46  fprintf(stderr, "%s: cannot open file %s\n",
47  args[0], argptr);
48  return 1;
49  }
50  }
51  nextch = getc(descr);
52  while (nextch != EOF) {
53  putc(stdout, nextch);
54  nextch = getc(descr);
55  }
56  close(descr);
57  }
58  return 0;
59 }
int32 strncmp(const char *, const char *, int32)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
syscall close(did32)
Definition: close.c:9
#define stderr
Definition: stdio.h:17
#define EOF
ファイルの終端(End of File)に達した場合(読み込み処理に用いる)
Definition: kernel.h:81
#define stdout
Definition: stdio.h:16
int32 printf(const char *,...)
Definition: printf.c:13
syscall getc(did32)
Definition: getc.c:9
syscall putc(did32, char)
デバイスへ文字1Byteを送信する。
Definition: putc.c:18
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
#define stdin
Definition: stdio.h:15
int32 did32
デバイスID
Definition: kernel.h:28
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
syscall open(did32, char *, char *)
Definition: open.c:9
#define NAMESPACE
Definition: conf.h:35
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ xsh_clear()

shellcmd xsh_clear ( int  nargs,
char *  args[] 
)

ディスプレイウィンドウをクリアする(xtermやVT100を想定している)

Parameters
[in]nargs引数の数
[in]args引数(引数を持つ配列)
Returns
成功時は0、コマンド名以外の引数が存在する場合は1を返す。
Note
printf()で使用されているエスケープシーケンスは、以下の意味を持つ。
・\033[0m :エスケープシーケンス指定をリセットして、未指定状態に戻す。 ・\033[2J\:画面クリアを行う。 ・\033[H :カーソルを画面の左上隅(最初の行、最初の列)に移動させる。

Definition at line 18 of file xsh_clear.c.

References fprintf(), printf(), and stderr.

19 {
20 
21  /* Insure no arguments were passed */
22 
23  if (nargs > 1)
24  {
25  fprintf(stderr, "use is: %s\n", args[0]);
26  return 1;
27  }
28 
29  printf("\033[0m\033[2J\033[H\n");
30  return 0;
31 }
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
Here is the call graph for this function:

◆ xsh_date()

shellcmd xsh_date ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_date.c.

References ascdate(), Date, DATE_DST_AUTO, DATE_DST_OFF, DATE_DST_ON, dateinfo::dt_bootvalid, dateinfo::dt_daylight, FALSE, fprintf(), gettime(), printf(), stderr, strncmp(), and SYSERR.

11  {
12 
13  int32 retval; /* return value */
14  uint32 now; /* current local time */
15  char datestr[64]; /* printable date in ascii */
16 
17  /* Output info for '--help' argument */
18 
19  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
20  printf("Usage: %s\n\n", args[0]);
21  printf("Description:\n");
22  printf("\tDisplays the current date and time\n");
23  printf("Options (one per invocation):\n");
24  printf("\t-f\tforce a time server request to be sent\n");
25  printf("\t-d\tset daylight savings time on\n");
26  printf("\t-s\tset standard time (not daylight savings)\n");
27  printf("\t-a\tset daylight savings to automatic\n");
28  printf("\t--help\tdisplay this help and exit\n");
29  return 0;
30  }
31 
32  /* Check argument count */
33 
34  if (nargs > 2) {
35  fprintf(stderr, "%s: too many arguments\n", args[0]);
36  fprintf(stderr, "Try '%s --help' for more information\n",
37  args[0]);
38  return 1;
39  }
40 
41  if (nargs == 2) {
42  if (strncmp(args[1], "-f", 3) == 0) {
44  } else if (strncmp(args[1], "-d", 3) == 0) {
46  } else if (strncmp(args[1], "-s", 3) == 0) {
48  } else if (strncmp(args[1], "-a", 3) == 0) {
50  } else {
51  fprintf(stderr, "%s: invalid argument\n", args[0]);
53  "Try '%s --help' for more information\n",
54  args[0]);
55  return 1;
56  }
57  }
58 
59  retval = gettime(&now);
60  if (retval == SYSERR) {
62  "%s: could not obtain the current date\n",
63  args[0]);
64  return 1;
65  }
66  ascdate(now, datestr);
67  printf("%s\n", datestr);
68  return 0;
69 }
int32 strncmp(const char *, const char *, int32)
bool8 dt_bootvalid
Definition: date.h:30
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define DATE_DST_OFF
Definition: date.h:20
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
struct dateinfo Date
Definition: ascdate.c:6
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
#define DATE_DST_AUTO
Definition: date.h:22
status ascdate(uint32, char *)
Definition: ascdate.c:16
#define DATE_DST_ON
Definition: date.h:21
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
int32 dt_daylight
Definition: date.h:31
status gettime(uint32 *)
1970年1月1日からの経過時間(秒単位)にロケーション(時差)を反映した時間を返す。
Definition: gettime.c:13
Here is the call graph for this function:

◆ xsh_devdump()

shellcmd xsh_devdump ( int32  ,
char *  [] 
)

Definition at line 10 of file xsh_devdump.c.

References devtab, dentry::dvminor, dentry::dvname, fprintf(), NDEVS, printf(), and stderr.

14 {
15  struct dentry *devptr; /* pointer to device entry */
16  int32 i; /* walks through device table */
17 
18  /* No arguments are expected */
19 
20  if (nargs > 1) {
21  fprintf(stderr, "No arguments allowed\n");
22  return 1;
23  }
24 
25  /* Walk through device table */
26 
27  printf("Device Name Minor\n");
28  printf("------ ------------ -----\n");
29 
30  for (i = 0; i < NDEVS; i++) {
31  devptr = &devtab[i];
32  printf("%4d %-12s %3d\n", i, devptr->dvname,
33  devptr->dvminor);
34  }
35  return 0;
36 }
#define NDEVS
Definition: conf.h:74
int32 dvminor
Definition: conf.h:8
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
char * dvname
Definition: conf.h:9
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
Here is the call graph for this function:

◆ xsh_echo()

shellcmd xsh_echo ( int  nargs,
char *  args[] 
)

STDOUT(標準出力)に引数に指定した文字列を出力する。

複数の引数がある場合は、改行せずにスペース区切りで引数が続けて出力される。

Parameters
[in]nargs引数の数
[in]args引数(引数を持つ配列)
Returns
0を返す。

Definition at line 15 of file xsh_echo.c.

References printf().

16 {
17  int32 i; /* walks through args array */
18 
19  if (nargs > 1)
20  {
21  printf("%s", args[1]);
22 
23  for (i = 2; i < nargs; i++)
24  {
25  printf(" %s", args[i]);
26  }
27  }
28  printf("\n");
29 
30  return 0;
31 }
int32 printf(const char *,...)
Definition: printf.c:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
Here is the call graph for this function:

◆ xsh_ethstat()

shellcmd xsh_ethstat ( int32  ,
char *  [] 
)

◆ xsh_exit()

shellcmd xsh_exit ( int  nargs,
char *  args[] 
)

exitコマンドとして、シェル終了を引き起こす終了コードを返す。

Parameters
[in]nargs引数の数(使用しない)
[in]args引数(使用しない)
Returns
SHELL_EXITを返す。

Definition at line 17 of file xsh_exit.c.

References SHELL_EXIT.

18 {
19  return SHELL_EXIT;
20 }
#define SHELL_EXIT
XINUシェルを終了させる返り値
Definition: shell.h:88

◆ xsh_help()

shellcmd xsh_help ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_help.c.

References cmdent::cfunc, cmdtab, cmdent::cname, fprintf(), ncmd, NULLCH, printf(), stderr, strncmp(), and strnlen().

12 {
13  int32 i;
14  char *argv[2]; /* argument vector for call */
15  char *src, *cmp; /* used for string compare */
16  int32 len; /* length of a command name */
17  int32 maxlen; /* maximum length of all */
18  /* command names */
19  int32 cols; /* number of columns in the */
20  /* formatted command list */
21  int32 spac; /* space per column in the */
22  /* formatted command list */
23  int32 lines; /* total lines of output in the */
24  /* formatted command list */
25  int32 j; /* index of commands across one */
26  /* line of formatted output */
27 
28  /* For argument '--help', emit help about the 'help' command */
29 
30  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
31 
32  printf("Use:\n");
33  printf("\t%s [command]\n", args[0]);
34  printf("Description:\n");
35  printf("\tProvides a list of shell commands or\n");
36  printf("\thelp information for a specific command\n");
37  printf("Options:\n");
38  printf("\tcommand\tspecific command for which to\n");
39  printf("\t\tdisplay help information\n");
40  printf("\t--help\tdisplay this help and exit\n");
41  return 0;
42  }
43 
44  /* Check for valid number of arguments */
45 
46  if (nargs > 2) {
47  fprintf(stderr, "%s: too many arguments\n", args[0]);
48  fprintf(stderr, "Try '%s --help' for more information\n",
49  args[0]);
50  return 1;
51  }
52 
53  /* Output help for specific command given as an argument */
54 
55  if (nargs == 2) {
56  for (i = 0; i < ncmd; i++) {
57  src = cmdtab[i].cname;
58  cmp = args[1];
59  while (*src != NULLCH) {
60  if (*src != *cmp) {
61  break;
62  }
63  src++;
64  cmp++;
65  }
66  if ( (*src != NULLCH) || (*cmp != NULLCH) ) {
67  continue;
68  }
69 
70  /* prepare args for shell command */
71 
72  argv[0] = args[1];
73  argv[1] = "--help";
74  (*cmdtab[i].cfunc) (2, argv);
75  return 0;
76  }
77  printf("%s: no such command as '%s'\n", args[0], args[1]);
78  return 1;
79  }
80 
81  /* No arguments -- print a list of shell commands */
82 
83  printf("\nshell commands are:\n\n");
84 
85  /* Calculate the maximum length of a command name */
86 
87  maxlen = 0;
88  for (i = 0; i < ncmd; i++) {
89  len = strnlen(cmdtab[i].cname, 80);
90  if (len > maxlen) {
91  maxlen = len;
92  }
93  }
94 
95  /* Calculate the number of command names per line */
96 
97  cols = 80/(maxlen+1);
98  if (cols > 6) {
99  cols = 6;
100  }
101 
102  /* Calculate the width of a column */
103 
104  spac = 80/cols;
105 
106  /* Calculate the number of lines of output */
107 
108  lines = (ncmd+(cols-1))/cols;
109 
110  /* print the lines of command names */
111 
112  for (i=0; i<lines; i++) {
113  for (j=i; j<ncmd; j+=lines) {
114  len = strnlen(cmdtab[j].cname,80);
115  printf("%s", cmdtab[j].cname);
116  while (len < spac) {
117  printf(" ");
118  len++;
119  }
120  }
121  printf("\n");
122  }
123  return 0;
124 }
int32 strncmp(const char *, const char *, int32)
uint32 ncmd
XINUシェルが提供するコマンドの数
Definition: shell.c:35
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
char * cname
コマンド名称
Definition: shell.h:100
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
const struct cmdent cmdtab[]
XINUシェルが提供するコマンドを管理する配列
Definition: shell.c:10
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
int32(* cfunc)(int32, char *[])
コマンドの機能を提供する関数(正確には関数ポインタ)
Definition: shell.h:104
int32 strnlen(const char *, uint32)
NULL終端された文字列の長さを返す。NULL終端は長さに含まない。
Definition: strnlen.c:14
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ xsh_kill()

shellcmd xsh_kill ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_kill.c.

References fprintf(), kill(), NULLCH, OK, printf(), stderr, strncmp(), and SYSERR.

11  {
12 
13  int32 retval; /* return value */
14  pid32 pid; /* ID of process to kill */
15  char ch; /* next character of argument */
16  char *chptr; /* walks along argument string */
17 
18  /* Output info for '--help' argument */
19 
20  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
21  printf("Usage: %s PID\n\n", args[0]);
22  printf("Description:\n");
23  printf("\tterminates a process\n");
24  printf("Options:\n");
25  printf("\tPID \tthe ID of a process to terminate\n");
26  printf("\t--help\tdisplay this help and exit\n");
27  return OK;
28  }
29 
30  /* Check argument count */
31 
32  if (nargs != 2) {
33  fprintf(stderr, "%s: incorrect argument\n", args[0]);
34  fprintf(stderr, "Try '%s --help' for more information\n",
35  args[0]);
36  return SYSERR;
37  }
38 
39  /* compute process ID from argument string */
40 
41  chptr = args[1];
42  ch = *chptr++;
43  pid = 0;
44  while(ch != NULLCH) {
45  if ( (ch < '0') || (ch > '9') ) {
46  fprintf(stderr, "%s: non-digit in process ID\n",
47  args[0]);
48  return 1;
49  }
50  pid = 10*pid + (ch - '0');
51  ch = *chptr++;
52  }
53  if (pid == 0) {
54  fprintf(stderr, "%s: cannot kill the null process\n",
55  args[0]);
56  return 1;
57  }
58 
59  retval = kill(pid);
60  if (retval == SYSERR) {
61  fprintf(stderr, "%s: cannot kill process %d\n",
62  args[0], pid);
63  return 1;
64  }
65  return 0;
66 }
int32 strncmp(const char *, const char *, int32)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define stderr
Definition: stdio.h:17
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 printf(const char *,...)
Definition: printf.c:13
syscall kill(pid32)
指定のプロセスを終了させ、システムから終了させたプロセス情報を取り除く。
Definition: kill.c:31
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 pid32
プロセスID
Definition: kernel.h:26
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ xsh_led()

shellcmd xsh_led ( int32  ,
char *  [] 
)

◆ xsh_ls()

shellcmd xsh_ls ( int32  ,
char *  [] 
)

Definition at line 10 of file xsh_ls.c.

References fprintf(), ldentry::ld_name, LF_AREA_DIR, Lf_data, lfdata::lf_dir, lfdata::lf_dirpresent, lfdata::lf_dskdev, lfdata::lf_mutex, lfdir::lfd_files, lfdir::lfd_nfiles, lfscheck(), printf(), read(), signal(), stderr, strncmp(), SYSERR, TRUE, and wait().

11 {
12  struct lfdir *dirptr; /* Ptr to in-memory directory */
13  int32 i;
14  struct ldentry *ldptr; /* Ptr to an entry in directory */
15 
16  /* For argument '--help', emit help about the 'ls' command */
17 
18  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
19  printf("Use: %s\n\n", args[0]);
20  printf("Description:\n");
21  printf("\tlists the names of files\n");
22  printf("Options:\n");
23  printf("\t--help\t display this help and exit\n");
24  return 0;
25  }
26 
27  if (nargs != 1) {
28  printf("illegal option: try --help for more information\n");
29  return 1;
30  }
31 
32  /* Obtain copy of directory if not already present in memory */
33 
34  dirptr = &Lf_data.lf_dir;
36  if (! Lf_data.lf_dirpresent) {
37  if (read(Lf_data.lf_dskdev, (char *)dirptr, LF_AREA_DIR) == SYSERR ) {
39  fprintf(stderr,"cannot read the directory\n");
40  }
41  if (lfscheck(dirptr) == SYSERR ) {
42  fprintf(stderr, "THe disk does not contain a Xinu file system\n");
44  return 1;
45  }
47  }
49 
50  /* Search directory and list the file names */
51 
52  for (i=0; i<dirptr->lfd_nfiles; i++) {
53  ldptr = &dirptr->lfd_files[i];
54  printf("%s\n", ldptr->ld_name);
55  }
56  return 0;
57 }
int32 strncmp(const char *, const char *, int32)
sid32 lf_mutex
Definition: lfilesys.h:132
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
#define stderr
Definition: stdio.h:17
syscall read(did32, char *, uint32)
Definition: read.c:9
did32 lf_dskdev
Definition: lfilesys.h:131
int32 printf(const char *,...)
Definition: printf.c:13
bool8 lf_dirpresent
Definition: lfilesys.h:135
#define LF_AREA_DIR
Definition: lfilesys.h:67
struct lfdir lf_dir
Definition: lfilesys.h:134
char ld_name[LF_NAME_LEN]
Definition: lfilesys.h:101
#define TRUE
Boolean True(1)
Definition: kernel.h:65
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
status lfscheck(struct lfdir *)
Definition: lfscheck.c:10
Here is the call graph for this function:

◆ xsh_memdump()

shellcmd xsh_memdump ( int32  ,
char *  [] 
)

Definition at line 15 of file xsh_memdump.c.

References FALSE, fprintf(), maxheap, parseval(), printf(), start, stderr, stop(), strncmp(), and TRUE.

16 {
17  bool8 force = FALSE; /* ignore address sanity checks */
18  uint32 begin; /* begining address */
19  uint32 stop; /* last address to dump */
20  uint32 length; /* length of region to dump */
21  int32 arg; /* index into args array */
22  uint32 l; /* counts length during dump */
23  int32 i; /* counts words during dump */
24  uint32 *addr; /* address to dump */
25  char *chptr; /* character address to dump */
26  char ch; /* next character to print */
27 
28  /* For argument '--help', emit help about the 'memdump' command */
29 
30  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
31  printf("Use: %s [-f] Address Length\n\n", args[0]);
32  printf("Description:\n");
33  printf("\tDumps Length bytes of memory begining at the\n");
34  printf("\tspecified starting address (both the address\n");
35  printf("\tand length can be specified in decimal or hex)\n");
36  printf("Options:\n");
37  printf("\t-f ignore sanity checks for addresses\n");
38  printf("\tAddress memory address at which to start\n");
39  printf("\tLength the number of bytes to dump\n");
40  printf("\t--help display this help and exit\n");
41  return 0;
42  }
43 
44  /* Check for valid number of arguments */
45 
46  if (nargs < 3 || nargs > 4) {
47  fprintf(stderr, "%s: incorrect number of arguments\n",
48  args[0]);
49  fprintf(stderr, "Try '%s --help' for more information\n",
50  args[0]);
51  return 1;
52  }
53 
54  arg = 1;
55  if (strncmp(args[arg], "-f", 2) == 0) {
56  force = TRUE;
57  arg++;
58  nargs --;
59  }
60 
61  if (nargs != 3) {
62  fprintf(stderr, "%s: too few arguments\n", args[0]);
63  fprintf(stderr, "Try '%s --help' for more information\n",
64  args[0]);
65  return 1;
66  }
67 
68  if ( (begin=parseval(args[arg])) == 0 ) {
69  fprintf(stderr, "%s: invalid begining address\n",
70  args[0]);
71  return 1;
72  }
73  if ( (length =parseval(args[arg+1])) == 0 ) {
74  fprintf(stderr, "%s: invalid length address\n",
75  args[0]);
76  return 1;
77  }
78 
79  /* Round begining address down to multiple of four and round */
80  /* length up to a multiple of four */
81 
82  begin &= ~0x3;
83  length = (length + 3) & ~0x3;
84 
85  /* Add length to begin address */
86 
87  stop = begin + length;
88 
89  /* verify that the address and length are reasonable */
90 
91  if ( force || ( (begin >= (uint32)&start) && (stop > begin) &&
92  (((void *)stop) < maxheap)) ) {
93 
94  /* values are valid; perform dump */
95 
96  chptr = (char *)begin;
97  for (l=0; l<length; l+=16) {
98  printf("%08x: ", begin);
99  addr = (uint32 *)begin;
100  for (i=0; i<4; i++) {
101  printf("%08x ",*addr++);
102  }
103  printf(" *");
104  for (i=0; i<16; i++) {
105  ch = *chptr++;
106  if ( (ch >= 0x20) && (ch <= 0x7e) ) {
107  printf("%c",ch);
108  } else {
109  printf(".");
110  }
111  }
112  printf("*\n");
113  begin += 16;
114  }
115  return 0;
116  } else {
117  printf("Values are out of range; use -f to force\n");
118  }
119  return 1;
120 }
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
byte bool8
Boolean値
Definition: kernel.h:36
int32 printf(const char *,...)
Definition: printf.c:13
int32 stop(char *s)
処理を停止させる。無限ループによる停止のため、復帰にはリセットが必要である。
Definition: initialize.c:249
#define FALSE
Boolean False(0)
Definition: kernel.h:63
uint32 start
#define TRUE
Boolean True(1)
Definition: kernel.h:65
void * maxheap
最上位かつ正常なヒープアドレス
Definition: meminit.c:10
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
static uint32 parseval(char *)
Definition: xsh_memdump.c:126
Here is the call graph for this function:

◆ xsh_memstat()

shellcmd xsh_memstat ( int32  ,
char *  [] 
)

Definition at line 14 of file xsh_memstat.c.

References fprintf(), printf(), printFreeList(), printMemUse(), stderr, and strncmp().

15 {
16 
17  /* For argument '--help', emit help about the 'memstat' command */
18 
19  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
20  printf("use: %s \n\n", args[0]);
21  printf("Description:\n");
22  printf("\tDisplays the current memory use and prints the\n");
23  printf("\tfree list.\n");
24  printf("Options:\n");
25  printf("\t--help\t\tdisplay this help and exit\n");
26  return 0;
27  }
28 
29  /* Check for valid number of arguments */
30 
31  if (nargs > 1) {
32  fprintf(stderr, "%s: too many arguments\n", args[0]);
33  fprintf(stderr, "Try '%s --help' for more information\n",
34  args[0]);
35  return 1;
36  }
37 
38  printMemUse();
39  printFreeList();
40 
41  return 0;
42 }
int32 strncmp(const char *, const char *, int32)
static void printMemUse(void)
Definition: xsh_memstat.c:74
static void printFreeList(void)
Definition: xsh_memstat.c:50
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
Here is the call graph for this function:

◆ xsh_netinfo()

shellcmd xsh_netinfo ( int32  ,
char *  [] 
)

Definition at line 12 of file xsh_netinfo.c.

References network::dnsserver, network::ethbcast, network::ethucast, FALSE, fprintf(), getlocalip(), network::ipbcast, network::ipmask, network::ipprefix, network::iprouter, network::ipucast, network::ipvalid, NetData, network::ntpserver, OK, printf(), sprintf(), stderr, strncmp(), and SYSERR.

12  {
13 
14  uint32 ipaddr; /* An IP address in binary */
15  uint32 ipbcast; /* IP broadcast addr. in binary */
16  uint32 ipprefix; /* IP network prefix in binary */
17  uint32 router; /* Router address in binary */
18  uint32 tserver; /* NTP server address in binary */
19  uint32 dserver; /* DNS server address in binary */
20  char str[40]; /* Temporary used for formatting*/
21  uint32 ipmask; /* Subnet mask in binary */
22 
23  /* Output info for '--help' argument */
24 
25  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
26  printf("Usage: %s\n\n", args[0]);
27  printf("Description:\n");
28  printf("\tDisplays IP address information\n");
29  printf("Options:\n");
30  printf("\t-f\tforce a new DHCP request\n");
31  printf("\t--help\tdisplay this help and exit\n");
32  return OK;
33  }
34 
35  /* Check argument count */
36 
37  if (nargs > 2) {
38  fprintf(stderr, "%s: too many arguments\n", args[0]);
39  fprintf(stderr, "Try '%s --help' for more information\n",
40  args[0]);
41  return SYSERR;
42  }
43 
44  if (nargs == 2) {
45  if (strncmp(args[1], "-f", 3) != 0) {
46  fprintf(stderr, "%s: invalid argument\n", args[0]);
48  "Try '%s --help' for more information\n",
49  args[0]);
50  return 1;
51  }
53  getlocalip();
54  }
55 
56 
57  /* IP unicast address in dotted decimal and hex */
58 
59  ipaddr = NetData.ipucast;
60  sprintf(str, "%d.%d.%d.%d",
61  (ipaddr>>24)&0xff, (ipaddr>>16)&0xff,
62  (ipaddr>>8)&0xff, ipaddr&0xff);
63  printf(" %-16s %-16s 0x%08x\n",
64  "IP address:", str, ipaddr);
65 
66  /* IP network broadcast address in dotted decimal & hex */
67 
68  ipbcast = NetData.ipbcast;
69  sprintf(str, "%d.%d.%d.%d",
70  (ipbcast>>24)&0xff, (ipbcast>>16)&0xff,
71  (ipbcast>>8)&0xff, ipbcast&0xff);
72  printf(" %-16s %-16s 0x%08x\n",
73  "IP broadcast:", str, ipbcast);
74 
75  /* IP network prefix in dotted decimal & hex */
76 
77  ipprefix = NetData.ipprefix;
78  sprintf(str, "%d.%d.%d.%d",
79  (ipprefix>>24)&0xff, (ipprefix>>16)&0xff,
80  (ipprefix>>8)&0xff, ipprefix&0xff);
81  printf(" %-16s %-16s 0x%08x\n",
82  "IP prefix:", str, ipprefix);
83 
84  /* IP network mask in dotted decimal & hex */
85 
86  ipmask = NetData.ipmask;
87  ipaddr = NetData.ipucast;
88  sprintf(str, "%d.%d.%d.%d",
89  (ipmask>>24)&0xff, (ipmask>>16)&0xff,
90  (ipmask>>8)&0xff, ipmask&0xff);
91  printf(" %-16s %-16s 0x%08x\n",
92  "Address mask:", str, ipmask);
93 
94  /* Default router in dotted decimal & hex */
95 
96  router = NetData.iprouter;
97  sprintf(str, "%d.%d.%d.%d",
98  (router>>24)&0xff, (router>>16)&0xff,
99  (router>>8)&0xff, router&0xff);
100  printf(" %-16s %-16s 0x%08x\n",
101  "IP router:", str, router);
102 
103  /* NTP time server in dotted decimal & hex */
104 
105  tserver = NetData.ntpserver;
106  if (tserver != 0) {
107  sprintf(str, "%d.%d.%d.%d",
108  (tserver>>24)&0xff, (tserver>>16)&0xff,
109  (tserver>>8)&0xff, tserver&0xff);
110  printf(" %-16s %-16s 0x%08x\n",
111  "NTP time server:", str, tserver);
112  }
113 
114  /* DNS server in dotted decimal & hex */
115 
116  dserver = NetData.dnsserver;
117  if (dserver != 0) {
118  sprintf(str, "%d.%d.%d.%d",
119  (dserver>>24)&0xff, (dserver>>16)&0xff,
120  (dserver>>8)&0xff, dserver&0xff);
121  printf(" %-16s %-16s 0x%08x\n",
122  "DNS server:", str, dserver);
123  }
124 
125  printf(" %-16s %02x:%02x:%02x:%02x:%02x:%02x\n",
126  "MAC unicast:",
127  0xff & NetData.ethucast[0],
128  0xff & NetData.ethucast[1],
129  0xff & NetData.ethucast[2],
130  0xff & NetData.ethucast[3],
131  0xff & NetData.ethucast[4],
132  0xff & NetData.ethucast[5]);
133 
134  printf(" %-16s %02x:%02x:%02x:%02x:%02x:%02x\n",
135  "MAC broadcast:",
136  0xff & NetData.ethbcast[0],
137  0xff & NetData.ethbcast[1],
138  0xff & NetData.ethbcast[2],
139  0xff & NetData.ethbcast[3],
140  0xff & NetData.ethbcast[4],
141  0xff & NetData.ethbcast[5]);
142 
143  return OK;
144 }
uint32 ipucast
Definition: net.h:55
int32 strncmp(const char *, const char *, int32)
uint32 ipmask
Definition: net.h:57
struct network NetData
Definition: net.c:6
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define stderr
Definition: stdio.h:17
#define OK
処理が成功した場合
Definition: kernel.h:77
int32 sprintf(char *, char *,...)
Definition: sprintf.c:12
int32 printf(const char *,...)
Definition: printf.c:13
byte ethucast[ETH_ADDR_LEN]
Definition: net.h:64
#define FALSE
Boolean False(0)
Definition: kernel.h:63
uint32 iprouter
Definition: net.h:59
uint32 ipprefix
Definition: net.h:58
uint32 ipbcast
Definition: net.h:56
byte ethbcast[ETH_ADDR_LEN]
Definition: net.h:65
uint32 getlocalip(void)
Definition: dhcp.c:142
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
uint32 ntpserver
Definition: net.h:62
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
uint32 dnsserver
Definition: net.h:61
bool8 ipvalid
Definition: net.h:63
Here is the call graph for this function:

◆ xsh_nvram()

shellcmd xsh_nvram ( int32  ,
char *  [] 
)

◆ xsh_ping()

shellcmd xsh_ping ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_ping.c.

References dnslookup(), dot2ip(), FALSE, fprintf(), ICMP_ECHOREQST, icmp_recv(), icmp_register(), icmp_release(), icmp_send(), printf(), stderr, strlen(), strncmp(), SYSERR, TIMEOUT, and TRUE.

12 {
13  uint32 ipaddr; /* IP address in binary */
14  int32 retval; /* return value */
15  int32 slot; /* Slot in ICMP to use */
16  static int32 seq = 0; /* sequence number */
17  char buf[56]; /* buffer of chars */
18  int32 i; /* index into buffer */
19  int32 nextval; /* next value to use */
20  bool8 dname;
21 
22  /* For argument '--help', emit help about the 'ping' command */
23 
24  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
25  printf("Use: %s address\n\n", args[0]);
26  printf("Description:\n");
27  printf("\tUse ICMP Echo to ping a remote host\n");
28  printf("Options:\n");
29  printf("\t--help\t display this help and exit\n");
30  printf("\taddress\t an IP address in dotted decimal\n");
31  return 0;
32  }
33 
34  /* Check for valid number of arguments */
35 
36  if (nargs != 2) {
37  fprintf(stderr, "%s: invalid arguments\n", args[0]);
38  fprintf(stderr, "Try '%s --help' for more information\n",
39  args[0]);
40  return 1;
41  }
42 
43  dname = FALSE;
44  for(i = 0; i < strlen(args[1]); i++) {
45  if( ( (args[1][i] >= 65) && (args[1][i] <= 90) ) ||
46  ( (args[1][i] >= 97) && (args[1][i] <= 122)) ) {
47  dname = TRUE;
48  break;
49  }
50  }
51 
52  if(dname == TRUE) {
53  ipaddr = dnslookup(args[1]);
54  if((int32)ipaddr == SYSERR) {
55  fprintf(stderr, "DNS cannot resolve %s\n", args[1]);
56  return 1;
57  }
58  printf("Pinging %d.%d.%d.%d\n", (ipaddr>>24)&0xff,
59  (ipaddr>>16)&0xff,
60  (ipaddr>>8)&0xff,
61  (ipaddr)&0xff);
62  }
63  else {
64  /* convert argument to binary */
65 
66  retval = dot2ip(args[1], &ipaddr);
67  if ((int32)retval == SYSERR) {
68  fprintf(stderr, "%s: invalid IP address\n", args[0]);
69  return 1;
70  }
71  }
72 
73  /* Register to receive an ICMP Echo Reply */
74 
75  slot = icmp_register(ipaddr);
76  if (slot == SYSERR) {
77  fprintf(stderr,"%s: ICMP registration failed\n", args[0]);
78  return 1;
79  }
80 
81  /* Fill the buffer with values - start with low-order byte of */
82  /* the sequence number and increment */
83 
84  nextval = seq;
85  for (i = 0; i<sizeof(buf); i++) {
86  buf[i] = 0xff & nextval++;
87  }
88 
89  /* Send an ICMP Echo Request */
90  retval = icmp_send(ipaddr, ICMP_ECHOREQST, slot,
91  seq++, buf, sizeof(buf));
92  if (retval == SYSERR) {
93  fprintf(stderr, "%s: no response from host %s\n", args[0], args[1]);
94  icmp_release(slot);
95  return 1;
96  }
97 
98  /* Read a reply */
99 
100  retval = icmp_recv(slot, buf, sizeof(buf), 3000);
101  icmp_release(slot);
102  if (retval == TIMEOUT) {
103  fprintf(stderr, "%s: no response from host %s\n", args[0],
104  args[1]);
105  return 1;
106  }
107 
108  if (retval != sizeof(buf)) {
109  fprintf(stderr,"expected %d bytes but got back %d\n",
110  sizeof(buf), retval);
111  }
112  fprintf(stderr, "host %s is alive\n", args[1]);
113  return 0;
114 }
status icmp_release(int32)
Definition: icmp.c:312
int32 strncmp(const char *, const char *, int32)
#define ICMP_ECHOREQST
Definition: icmp.h:17
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define stderr
Definition: stdio.h:17
int strlen(char *str)
NULL終端された文字列の長さを返す。NULL終端は長さに含まない。
Definition: strlen.c:11
byte bool8
Boolean値
Definition: kernel.h:36
int32 printf(const char *,...)
Definition: printf.c:13
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
status icmp_send(uint32, uint16, uint16, uint16, char *, int32)
Definition: icmp.c:225
int32 icmp_recv(int32, char *, int32, uint32)
Definition: icmp.c:150
int32 icmp_register(uint32)
Definition: icmp.c:103
#define FALSE
Boolean False(0)
Definition: kernel.h:63
#define TRUE
Boolean True(1)
Definition: kernel.h:65
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint32 dnslookup(char *)
Definition: dns.c:15
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
uint32 dot2ip(char *, uint32 *)
Definition: dot2ip.c:9
Here is the call graph for this function:

◆ xsh_ps()

shellcmd xsh_ps ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_ps.c.

References fprintf(), NPROC, PR_FREE, printf(), procent::prname, proctab, procent::prparent, procent::prprio, procent::prstate, procent::prstkbase, procent::prstklen, procent::prstkptr, stderr, and strncmp().

12 {
13  struct procent *prptr; /* pointer to process */
14  int32 i; /* index into proctabl */
15  char *pstate[] = { /* names for process states */
16  "free ", "curr ", "ready", "recv ", "sleep", "susp ",
17  "wait ", "rtime"};
18 
19  /* For argument '--help', emit help about the 'ps' command */
20 
21  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
22  printf("Use: %s\n\n", args[0]);
23  printf("Description:\n");
24  printf("\tDisplays information about running processes\n");
25  printf("Options:\n");
26  printf("\t--help\t display this help and exit\n");
27  return 0;
28  }
29 
30  /* Check for valid number of arguments */
31 
32  if (nargs > 1) {
33  fprintf(stderr, "%s: too many arguments\n", args[0]);
34  fprintf(stderr, "Try '%s --help' for more information\n",
35  args[0]);
36  return 1;
37  }
38 
39  /* Print header for items from the process table */
40 
41  printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n",
42  "Pid", "Name", "State", "Prio", "Ppid", "Stack Base",
43  "Stack Ptr", "Stack Size");
44 
45  printf("%3s %-16s %5s %4s %4s %10s %-10s %10s\n",
46  "---", "----------------", "-----", "----", "----",
47  "----------", "----------", "----------");
48 
49  /* Output information for each process */
50 
51  for (i = 0; i < NPROC; i++) {
52  prptr = &proctab[i];
53  if (prptr->prstate == PR_FREE) { /* skip unused slots */
54  continue;
55  }
56  printf("%3d %-16s %s %4d %4d 0x%08X 0x%08X %8d\n",
57  i, prptr->prname, pstate[(int)prptr->prstate],
58  prptr->prprio, prptr->prparent, prptr->prstkbase,
59  prptr->prstkptr, prptr->prstklen);
60  }
61  return 0;
62 }
pid32 prparent
このプロセスを作成したプロセスID(親プロセスID)。
Definition: process.h:102
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
uint32 prstklen
Bytesで表されたスタックの長さ(最大値。Byte)。
Definition: process.h:96
pri16 prprio
プロセスのスケジューリング優先度。
Definition: process.h:90
char prname[PNMLEN]
プロセス名。
Definition: process.h:98
#define NPROC
Definition: conf.h:79
char * prstkbase
ランタイムスタックの基点(メモリ領域で最上位のアドレス)。
Definition: process.h:94
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uint16 prstate
プロセス状態(PR_CURR, ..., etc)。
Definition: process.h:88
#define PR_FREE
プロセステーブルエントリが使用されていない状態。
Definition: process.h:35
struct procent proctab[]
プロセステーブル。
Definition: initialize.c:23
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
プロセステーブル(32bitsの倍数)。
Definition: process.h:85
char * prstkptr
保存されたスタックポインタ。
Definition: process.h:92
Here is the call graph for this function:

◆ xsh_sleep()

shellcmd xsh_sleep ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_sleep.c.

References delay(), fprintf(), NULLCH, printf(), sleep(), stderr, and strncmp().

12 {
13  int32 delay; /* Delay in seconds */
14  char *chptr; /* Walks through argument */
15  char ch; /* Next character of argument */
16 
17  /* For argument '--help', emit help about the 'sleep' command */
18 
19  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
20  printf("Use: %s\n\n", args[0]);
21  printf("Description:\n");
22  printf("\tDelay for a specified number of seconds\n");
23  printf("Options:\n");
24  printf("\t--help\t display this help and exit\n");
25  return 0;
26  }
27 
28  /* Check for valid number of arguments */
29 
30  if (nargs > 2) {
31  fprintf(stderr, "%s: too many arguments\n", args[0]);
32  fprintf(stderr, "Try '%s --help' for more information\n",
33  args[0]);
34  return 1;
35  }
36 
37  if (nargs != 2) {
38  fprintf(stderr, "%s: argument in error\n", args[0]);
39  fprintf(stderr, "Try '%s --help' for more information\n",
40  args[0]);
41  return 1;
42  }
43 
44  chptr = args[1];
45  ch = *chptr++;
46  delay = 0;
47  while (ch != NULLCH) {
48  if ( (ch < '0') || (ch > '9') ) {
49  fprintf(stderr, "%s: nondigit in argument\n",
50  args[0]);
51  return 1;
52  }
53  delay = 10*delay + (ch - '0');
54  ch = *chptr++;
55  }
56  sleep(delay);
57  return 0;
58 }
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 delay(int n)
マイクロ秒単位で処理を遅らせる。
Definition: initialize.c:262
syscall sleep(int32)
Definition: sleep.c:11
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
#define NULLCH
NULL文字(NULL終端)
Definition: kernel.h:70
Here is the call graph for this function:

◆ xsh_udpdump()

shellcmd xsh_udpdump ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_udpdump.c.

References fprintf(), printf(), stderr, strncmp(), udpentry::udcount, udpentry::udlocport, UDP_FREE, UDP_SLOTS, udpentry::udpid, udptab, udpentry::udremip, udpentry::udremport, and udpentry::udstate.

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
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
Here is the call graph for this function:

◆ xsh_udpecho()

shellcmd xsh_udpecho ( int32  ,
char *  [] 
)

Definition at line 14 of file xsh_udpecho.c.

References atoi(), delay(), dot2ip(), fprintf(), printf(), stderr, strncmp(), strnlen(), SYSERR, TIMEOUT, udp_recv(), udp_register(), udp_release(), and udp_send().

15 {
16  int i; /* index into buffer */
17  int retval; /* return value */
18  char msg[] = "Xinu testing UDP echo"; /* message to send */
19  char inbuf[1500]; /* buffer for incoming reply */
20  int32 slot; /* UDP slot to use */
21  int32 msglen; /* length of outgoing message */
22  uint32 remoteip; /* remote IP address to use */
23  uint16 remport= 7; /* remote port number to use */
24  uint16 locport = 52743; /* local port to use */
25  int32 retries = 3; /* number of retries */
26  int32 delay = 500; /* reception delay in ms */
27 
28  /* For argument '--help', emit help about the 'udpecho' command */
29 
30  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
31  printf("Use: %s REMOTEIP\n\n", args[0]);
32  printf("Description:\n");
33  printf("\tBounce a message off a remote UDP echo server\n");
34  printf("Options:\n");
35  printf("\tREMOTEIP:\tIP address in dotted decimal\n");
36  printf("\t--help\t display this help and exit\n");
37  return 0;
38  }
39 
40  /* Check for valid IP address argument */
41 
42  if (nargs != 2) {
43  fprintf(stderr, "%s: invalid number of argument(s)\n", args[0]);
44  fprintf(stderr, "Try '%s --help' for more information\n",
45  args[0]);
46  return 1;
47  }
48 
49  if (dot2ip(args[1], &remoteip) == SYSERR) {
50  fprintf(stderr, "%s: invalid IP address argument\r\n",
51  args[0]);
52  return 1;
53  }
54  if (nargs == 3) {
55  retval = atoi(args[2]);
56  if ( (retval <= 0) || (retval > 64535) ) {
57  fprintf(stderr, "%s: invalid port argument\r\n",
58  args[0]);
59  return 1;
60  }
61  remport = (uint16) retval;
62  }
63 
64  fprintf(stderr, "using remote port %d\n", remport);
65 
66  /* register local UDP port */
67 
68  slot = udp_register(remoteip, remport, locport);
69  if (slot == SYSERR) {
70  fprintf(stderr, "%s: could not reserve UDP port %d\n",
71  args[0], locport);
72  return 1;
73  }
74 
75  /* Retry sending outgoing datagram and getting response */
76 
77  msglen = strnlen(msg, 1200);
78  for (i=0; i<retries; i++) {
79  retval = udp_send(slot, msg, msglen);
80  if (retval == SYSERR) {
81  fprintf(stderr, "%s: error sending UDP \n",
82  args[0]);
83  return 1;
84  }
85 
86  retval = udp_recv(slot, inbuf, sizeof(inbuf), delay);
87  if (retval == TIMEOUT) {
88  fprintf(stderr, "%s: timeout...\n", args[0]);
89  continue;
90  } else if (retval == SYSERR) {
91  fprintf(stderr, "%s: error from udp_recv \n",
92  args[0]);
93  udp_release(slot);
94  return 1;
95  }
96  break;
97  }
98 
99  udp_release(slot);
100  if (retval == TIMEOUT) {
101  fprintf(stderr, "%s: retry limit exceeded\n",
102  args[0]);
103  return 1;
104  }
105 
106  /* Response received - check contents */
107 
108  if (retval != msglen) {
109  fprintf(stderr, "%s: sent %d bytes and received %d\n",
110  args[0], msglen, retval);
111  return 1;
112  }
113  for (i = 0; i < msglen; i++) {
114  if (msg[i] != inbuf[i]) {
115  fprintf(stderr, "%s: reply differs at byte %d\n",
116  args[0], i);
117  return 1;
118  }
119  }
120 
121  printf("UDP echo test was successful\n");
122  return 0;
123 }
int32 udp_recv(uid32, char *, int32, uint32)
Definition: udp.c:146
status udp_send(uid32, char *, int32)
Definition: udp.c:316
int atoi(char *)
ASCII文字列をint型に変換する。
Definition: atoi.c:19
int32 strncmp(const char *, const char *, int32)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 delay(int n)
マイクロ秒単位で処理を遅らせる。
Definition: initialize.c:262
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
status udp_release(uid32)
Definition: udp.c:502
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
uint32 dot2ip(char *, uint32 *)
Definition: dot2ip.c:9
int32 strnlen(const char *, uint32)
NULL終端された文字列の長さを返す。NULL終端は長さに含まない。
Definition: strnlen.c:14
Here is the call graph for this function:

◆ xsh_udpeserver()

shellcmd xsh_udpeserver ( int32  ,
char *  [] 
)

Definition at line 12 of file xsh_udpserver.c.

References fprintf(), getlocalip(), printf(), stderr, strncmp(), SYSERR, TIMEOUT, TRUE, udp_recvaddr(), udp_register(), and udp_sendto().

13 {
14  int32 retval; /* return value from sys calls */
15  uint32 localip; /* local IP address */
16  uint32 remip; /* remote sender's IP address */
17  uint16 remport; /* remote sender's UDP port */
18  char buff[1500]; /* buffer for incoming reply */
19  int32 msglen; /* length of outgoing message */
20  int32 slot; /* slot in UDP table */
21  uint16 echoserverport= 7; /* port number for UDP echo */
22 
23  /* For argument '--help', emit a help message */
24 
25  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
26  printf("Use: %s\n\n", args[0]);
27  printf("Description:\n");
28  printf("\tBecome a UDP echo server\n");
29  printf("Options:\n");
30  printf("\t--help\t display this help and exit\n");
31  return 0;
32  }
33 
34  /* Check for valid IP address argument */
35 
36  if (nargs != 1) {
37  fprintf(stderr, "%s: no arguments expected\n", args[0]);
38  fprintf(stderr, "Try '%s --help' for more information\n",
39  args[0]);
40  return 1;
41  }
42 
43  localip = getlocalip();
44  if (localip == SYSERR) {
46  "%s: could not obtain a local IP address\n",
47  args[0]);
48  return 1;
49  }
50 
51  /* register local UDP port */
52 
53  slot = udp_register(0, 0, echoserverport);
54  if (slot == SYSERR) {
55  fprintf(stderr, "%s: could not reserve UDP port %d\n",
56  args[0], echoserverport);
57  return 1;
58  }
59 
60  /* Do forever: read an incoming datagram and send it back */
61 
62  while (TRUE) {
63  retval = udp_recvaddr(slot, &remip, &remport, buff,
64  sizeof(buff), 600000);
65 
66  if (retval == TIMEOUT) {
67  continue;
68  } else if (retval == SYSERR) {
69  fprintf(stderr, "%s: error receiving UDP\n",
70  args[0]);
71  return 1;
72  }
73  msglen = retval;
74  retval = udp_sendto(slot, remip, remport, buff, msglen);
75  if (retval == SYSERR) {
76  fprintf(stderr, "%s: udp_sendto failed\n",
77  args[0]);
78  return 1;
79  }
80  }
81  return 0;
82 }
int32 strncmp(const char *, const char *, int32)
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
int32 udp_recvaddr(uid32, uint32 *, uint16 *, char *, int32, uint32)
Definition: udp.c:227
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
#define TIMEOUT
システムコールがタイムアウトした場合
Definition: kernel.h:83
#define TRUE
Boolean True(1)
Definition: kernel.h:65
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
uid32 udp_register(uint32, uint16, uint16)
Definition: udp.c:85
unsigned short uint16
符号なし16ビット整数(unsigned short)
Definition: kernel.h:17
uint32 getlocalip(void)
Definition: dhcp.c:142
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
status udp_sendto(uid32, uint32, uint16, char *, int32)
Definition: udp.c:417
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the call graph for this function:

◆ xsh_uptime()

shellcmd xsh_uptime ( int32  ,
char *  [] 
)

Definition at line 11 of file xsh_uptime.c.

References clktime, fprintf(), printf(), stderr, and strncmp().

12 {
13  uint32 days, hrs, mins, secs; /* days, hours, minutes, and */
14  /* seconds since system boot */
15  uint32 secperday = 86400; /* seconds in a day */
16  uint32 secperhr = 3600; /* seconds in an hour */
17  uint32 secpermin = 60; /* seconds in a minute */
18 
19  /* For argument '--help', emit help about the 'uptime' command */
20 
21  if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
22  printf("Use: %s\n\n", args[0]);
23  printf("Description:\n");
24  printf("\tDisplays time since the system booted\n");
25  printf("Options:\n");
26  printf("\t--help\t display this help and exit\n");
27  return 0;
28  }
29 
30  /* Check for valid number of arguments */
31 
32  if (nargs > 1) {
33  fprintf(stderr, "%s: too many arguments\n", args[0]);
34  fprintf(stderr, "Try '%s --help' for more information\n",
35  args[0]);
36  return 1;
37  }
38 
39  secs = clktime; /* total seconds since boot */
40 
41  /* subtract number of whole days */
42 
43  days = secs/secperday;
44  secs -= days*secperday;
45 
46  /* subtract number of hours */
47 
48  hrs = secs/secperhr;
49  secs -= hrs*secperhr;
50 
51  /* subtract number of minutes */
52 
53  mins = secs/secpermin;
54  secs -= mins*secpermin;
55 
56  printf("Xinu has been up ");
57  if (days > 0) {
58  printf(" %d day(s) ", days);
59  }
60 
61  if (hrs > 0) {
62  printf(" %d hour(s) ", hrs);
63  }
64 
65  if (mins > 0) {
66  printf(" %d minute(s) ", mins);
67  }
68 
69  if (secs > 0) {
70  printf(" %d second(s) ", secs);
71  }
72  printf("\n");
73 
74  return 0;
75 }
int32 strncmp(const char *, const char *, int32)
#define stderr
Definition: stdio.h:17
int32 printf(const char *,...)
Definition: printf.c:13
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
uint32 clktime
起動してからの現在の時間[s]
Definition: clkinit.c:5
unsigned int uint32
符号なし32ビット整数(unsigned int)
Definition: kernel.h:15
Here is the call graph for this function: