Allow IPv6 address entry in tools>ping - Loosens valid character check
[tomato/davidwu.git] / release / src / router / nvram / main.c
blobc0b43d4960ef4a708d7b5f25c42cc9cb8b5eea92
1 /*
2 * Frontend command-line utility for Linux NVRAM layer
4 * Copyright 2005, Broadcom Corporation
5 * All Rights Reserved.
6 *
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: main.c,v 1.1.1.7 2005/03/07 07:31:19 kanki Exp $
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
19 #include <typedefs.h>
20 #include <bcmnvram.h>
22 static void
23 usage(void)
25 fprintf(stderr, "usage: nvram [get name] [set name=value] [unset name] [show]\n");
26 exit(0);
29 /* NVRAM utility */
30 int
31 main(int argc, char **argv)
33 char *name, *value, buf[NVRAM_SPACE];
34 int size;
36 /* Skip program name */
37 --argc;
38 ++argv;
40 if (!*argv)
41 usage();
43 /* Process the remaining arguments. */
44 for (; *argv; argv++) {
45 if (!strncmp(*argv, "get", 3)) {
46 if (*++argv) {
47 if ((value = nvram_get(*argv)))
48 puts(value);
51 else if (!strncmp(*argv, "set", 3)) {
52 if (*++argv) {
53 strncpy(value = buf, *argv, sizeof(buf));
54 name = strsep(&value, "=");
55 nvram_set(name, value);
58 else if (!strncmp(*argv, "unset", 5)) {
59 if (*++argv)
60 nvram_unset(*argv);
62 else if (!strncmp(*argv, "commit", 5)) {
63 nvram_commit();
65 else if (!strncmp(*argv, "show", 4) ||
66 !strncmp(*argv, "getall", 6)) {
67 nvram_getall(buf, sizeof(buf));
68 for (name = buf; *name; name += strlen(name) + 1)
69 puts(name);
70 size = sizeof(struct nvram_header) + (int) name - (int) buf;
71 fprintf(stderr, "size: %d bytes (%d left)\n", size, NVRAM_SPACE - size);
73 if (!*argv)
74 break;
77 return 0;