com_help.c com_igmp.c com_list.c com_login.c commands.c com_mirror.c \
common.c com_name.c com_netconf.c com_password.c com_ports.c com_qos.c \
com_quit.c com_restart.c com_scan.c com_stormfilter.c com_tree.c com_vlan.c
-ngcli_CPPFLAGS = -I$(top_srcdir)/lib/include/
-ngcli_LDADD = $(top_builddir)/lib/src/libngadmin.la $(READLINE_LIBS)
+ngcli_CPPFLAGS = -I$(top_srcdir)/raw/include/ -I$(top_srcdir)/lib/include/
+ngcli_LDADD = $(top_builddir)/raw/src/librawnsdp.la $(top_builddir)/lib/src/libngadmin.la $(READLINE_LIBS)
while (i < argc - 1) {
- s = parseBitrate(argv[i + 1]);
+ s = parseBitrateStr(argv[i + 1]);
if (strcmp(argv[i], "inout") == 0) {
ports[0] = s;
ports[1] = s;
}
for (i = 0; i < sa->ports; i++)
- printf("port %i: in %s, out %s\n", i + 1, bitrates[ports[2 * i + 0]], bitrates[ports[2 * i + 1]]);
+ printf("port %i: in %s, out %s\n", i + 1, safeStr(getBitrateStr(ports[2 * i + 0])), safeStr(getBitrateStr(ports[2 * i + 1])));
end:
free(ports);
goto end;
}
- for (i = 0; i < sa->ports; i++) {
- printf("port %i: ", i + 1);
- switch (ports[i]) {
-
- case 0:
- printf("down");
- break;
-
- case SPEED_10_HD:
- printf("up, 10M half-duplex");
- break;
-
- case SPEED_10_FD:
- printf("up, 10M full-duplex");
- break;
-
- case SPEED_100_HD:
- printf("up, 100M half-duplex");
- break;
-
- case SPEED_100_FD:
- printf("up, 100M full-duplex");
- break;
-
- case SPEED_1000_FD:
- printf("up, 1000M full-duplex");
- break;
-
- default:
- printf("unknown (%i)", ports[i]);
- }
- putchar('\n');
- }
+ for (i = 0; i < sa->ports; i++)
+ printf("port %i: %s\n", i + 1, safeStr(getSpeedStr(ports[i])));
end:
free(ports);
/* read defaults */
if (strcmp(argv[0], "all") == 0) {
- d = parsePrio(argv[1]);
+ d = parseQosPrioStr(argv[1]);
argv += 2;
argc -= 2;
}
p = strtol(argv[i], NULL, 0);
if (p < 1 || p > sa->ports)
continue;
- ports[p - 1] = parsePrio(argv[i + 1]);
+ ports[p - 1] = parseQosPrioStr(argv[i + 1]);
}
/* send the new configuration to the switch */
goto end;
}
- printf("QoS mode: ");
- switch (s) {
-
- case QOS_DOT:
- printf("802.1p\n");
- goto end;
-
- case QOS_PORT:
- printf("port based\n");
- break;
-
- default:
- printf("unknown (%i)\n", s);
+ printf("QoS mode: %s\n", safeStr(getQosTypeStr(s)));
+ if (s != QOS_PORT)
goto end;
- }
ports = malloc(sa->ports * sizeof(char));
i = ngadmin_getQOSValues(nga, ports);
}
for (i = 0; i < sa->ports; i++)
- printf("port %i: %s\n", i + 1, prio[(int)ports[i]]);
+ printf("port %i: %s\n", i + 1, safeStr(getQosPrioStr(ports[i])));
end:
free(ports);
/* read defaults */
if (strcmp(argv[0], "all") == 0) {
- d = parseBitrate(argv[1]);
+ d = parseBitrateStr(argv[1]);
argv += 2;
argc -= 2;
}
p = strtol(argv[i], NULL, 0);
if (p < 1 || p > sa->ports)
continue;
- ports[p - 1] = parseBitrate(argv[i + 1]);
+ ports[p - 1] = parseBitrateStr(argv[i + 1]);
}
/* send the new configuration to the switch */
}
for (i = 0; i < sa->ports; i++)
- printf("port %i: %s\n", i + 1, bitrates[ports[i]]);
+ printf("port %i: %s\n", i + 1, safeStr(getBitrateStr(ports[i])));
end:
free(ports);
goto end;
}
- printf("VLAN type: ");
- switch (t) {
-
- case VLAN_DISABLED:
- printf("disabled\n");
- break;
-
- case VLAN_PORT_BASIC:
- printf("port basic\n");
- break;
-
- case VLAN_PORT_ADV:
- printf("port advanced\n");
- break;
-
- case VLAN_DOT_BASIC:
- printf("802.1Q basic\n");
- break;
-
- case VLAN_DOT_ADV:
- printf("802.1Q advanced\n");
- break;
-
- default:
- printf("unknown (%i)\n", t);
- }
+ printf("VLAN type: %s\n", safeStr(getVlanTypeStr(t)));
end:
void printErrCode (int err)
{
- switch (err) {
- case ERR_OK:
- break;
+ const char *str;
- case ERR_NET:
- printf("network error\n");
- break;
+ str = ngadmin_errorStr(err);
- case ERR_NOTLOG:
- printf("no switch selected\n");
- break;
-
- case ERR_DENIED:
- printf("access denied\n");
- break;
-
- case ERR_BADPASS:
- printf("wrong password\n");
- break;
-
- case ERR_BADID:
- printf("bad switch id\n");
- break;
-
- case ERR_INVARG:
- printf("invalid argument\n");
- break;
-
- case ERR_TIMEOUT:
- printf("timeout\n");
- break;
-
- case ERR_NOTIMPL:
- printf("not implemented\n");
- break;
-
- case ERR_BADREPLY:
- printf("bad reply from switch\n");
- break;
-
- case ERR_INVOP:
- printf("invalid operation\n");
- break;
-
- case ERR_UNKNOWN:
- printf("unknown error\n");
- break;
-
- default:
+ if (str == NULL)
printf("unknown status code (%i)\n", err);
- }
-}
-
-
-const char* const bitrates[] = {
- "nl",
- "512K",
- "1M",
- "2M",
- "4M",
- "8M",
- "16M",
- "32M",
- "64M",
- "128M",
- "256M",
- "512M",
- NULL
-};
-
-
-const char* const prio[]={
- NULL,
- "high",
- "medium",
- "normal",
- "low",
- NULL
-};
-
-
-int parseBitrate (const char *s)
-{
- int i;
-
- for (i = 0; bitrates[i] != NULL && strcasecmp(bitrates[i], s) != 0; i++);
-
- return i;
-}
-
-
-char parsePrio (const char *s)
-{
- int i;
-
- for (i = 1; prio[i] != NULL && strcasecmp(prio[i], s) != 0; i++);
-
- return (char)i;
+ else if (err != ERR_OK)
+ puts(str);
}
}
-int trim (char *txt, int start)
-{
- char *p;
-
- if (txt == NULL)
- return 0;
-
- p = txt + start;
- for (p--; p >= txt && (*p == ' ' || *p == '\n'); *p-- = 0);
-
- return p - txt + 1;
-}
-
-
int explode (const char *commande, char** tab, int maximum)
{
const char *start, *end;
#include <termios.h>
#include <unistd.h>
+#include <nsdp/str.h>
#include <ngadmin.h>
extern struct termios current_term;
-extern const char * const bitrates[], * const prio[];
-
-
void displaySwitchTab (const struct swi_attr *sa, int nb);
void printErrCode (int err);
-int parseBitrate (const char *s);
-char parsePrio (const char *s);
-
-
-int trim (char *txt, int start);
int explode (const char *commande, char** tab, int maximum);
#include <nsdp/protocol.h>
#include <nsdp/attr.h>
#include <nsdp/net.h>
-#include <nsdp/misc.h>
+#include <nsdp/str.h>
#define MAX_STR_SIZE 64
struct ngadmin* ngadmin_init (const char *iface);
+/**
+ * Convert error to string.
+ * This function returns a string corresponding to the numerical error code.
+ * @param error The numerical error code to convert.
+ * @return A pointer to a static string or NULL if the error code is invalid.
+ */
+const char* ngadmin_errorStr (int error);
+
+
/**
* Close NgAdmin library.
* This function frees the resources used by the library. You really should
#include <nsdp/attr.h>
#include <nsdp/protocol.h>
-#include <nsdp/misc.h>
+#include <nsdp/str.h>
#include "lib.h"
#include "network.h"
+static const char* const liberror_str_tab[] = {
+ [-ERR_OK] = "no error",
+ [-ERR_NET] = "network error",
+ [-ERR_NOTLOG] "not logged",
+ [-ERR_DENIED] = "access denied",
+ [-ERR_BADPASS] = "bad password",
+ [-ERR_BADID] = "bad id",
+ [-ERR_INVARG] = "invalid argument",
+ [-ERR_TIMEOUT] = "timeout",
+ [-ERR_MEM] = "out of memory",
+ [-ERR_NOTIMPL] = "not implemented",
+ [-ERR_BADREPLY] = "bad reply",
+ [-ERR_INVOP] = "invalid operation",
+ [-ERR_UNKNOWN] = "unknown error",
+ NULL
+};
+
+
+const char* ngadmin_errorStr (int error)
+{
+ return getValueStr(liberror_str_tab, -ERR_OK, -ERR_UNKNOWN, -error);
+}
+
+
int ngadmin_setName (struct ngadmin *nga, const char *name)
{
List *attr;
#include <sys/ioctl.h>
#include <nsdp/attr.h>
-#include <nsdp/misc.h>
+#include <nsdp/str.h>
#include <nsdp/net.h>
#include <nsdp/protocol.h>
-noinst_HEADERS = attr.h list.h misc.h net.h packet.h protocol.h
+noinst_HEADERS = attr.h list.h net.h packet.h protocol.h str.h
+++ /dev/null
-
-#ifndef DEF_MISC
-#define DEF_MISC
-
-
-void passwordEndecode (char *buf, unsigned int len);
-
-
-int trim (char *txt, int start);
-
-
-static inline int min (int a, int b)
-{
- return a < b ? a : b;
-}
-
-
-#endif
-
#define CODE_WRITE_REQ 3
#define CODE_WRITE_REP 4
+#define ERROR_NONE 0
#define ERROR_READONLY 3
#define ERROR_WRITEONLY 4
#define ERROR_INVALID_VALUE 5
--- /dev/null
+
+#ifndef DEF_STR
+#define DEF_STR
+
+
+#include <nsdp/protocol.h>
+#include <ngadmin.h> /* FIXME */
+
+
+extern const char passwordKey[];
+
+extern const char* const speed_str_tab[];
+extern const char* const vlan_type_str_tab[];
+extern const char* const vlan_code_str_tab[];
+extern const char* const qos_type_str_tab[];
+extern const char* const qos_prio_str_tab[];
+extern const char* const bitrate_str_tab[];
+extern const char* const code_str_tab[];
+extern const char* const error_str_tab[];
+
+
+static inline const char* safeStr (const char *s)
+{
+ return (s == NULL) ? "unknown" : s;
+}
+
+
+static inline const char* getValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, unsigned char value)
+{
+ return (value >= mini && value <= maxi) ? tab[value] : NULL;
+}
+
+
+#define getSpeedStr(speed) getValueStr(speed_str_tab, SPEED_DOWN, SPEED_1000_FD, speed)
+#define getVlanTypeStr(type) getValueStr(vlan_type_str_tab, VLAN_DISABLED, VLAN_DOT_ADV, type)
+#define getVlanCodeStr(code) getValueStr(vlan_code_str_tab, VLAN_NO, VLAN_TAGGED, code)
+#define getQosTypeStr(type) getValueStr(qos_type_str_tab, QOS_PORT, QOS_DOT, type)
+#define getQosPrioStr(prio) getValueStr(qos_prio_str_tab, PRIO_HIGH, PRIO_LOW, prio)
+#define getBitrateStr(bitrate) getValueStr(bitrate_str_tab, BITRATE_NOLIMIT, BITRATE_512M, bitrate)
+#define getCodeStr(code) getValueStr(code_str_tab, CODE_READ_REQ, CODE_WRITE_REP, code)
+#define getErrorStr(error) getValueStr(error_str_tab, ERROR_NONE, ERROR_DENIED, error)
+
+
+int parseValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, const char *str);
+
+
+#define parseSpeedStr(str) parseValueStr(speed_str_tab, SPEED_DOWN, SPEED_1000_FD, str)
+#define parseVlanTypeStr(str) parseValueStr(vlan_type_str_tab, VLAN_DISABLED, VLAN_DOT_ADV, str)
+#define parseVlanCodeStr(str) parseValueStr(vlan_code_str_tab, VLAN_NO, VLAN_TAGGED, str)
+#define parseQosTypeStr(str) parseValueStr(qos_type_str_tab, QOS_PORT, QOS_DOT, str)
+#define parseQosPrioStr(str) parseValueStr(qos_prio_str_tab, PRIO_HIGH, PRIO_LOW, str)
+#define parseBitrateStr(str) parseValueStr(bitrate_str_tab, BITRATE_NOLIMIT, BITRATE_512M, str)
+#define parseCodeStr(str) parseValueStr(code_str_tab, CODE_READ_REQ, CODE_WRITE_REP, str)
+#define parseErrorStr(str) parseValueStr(error_str_tab, ERROR_NONE, ERROR_DENIED, str)
+
+
+bool isStringPrintable (const char *str, unsigned int len);
+
+
+void passwordEndecode (char *buf, unsigned int len);
+
+
+int trim (char *txt, int start);
+
+
+static inline int min (int a, int b)
+{
+ return a < b ? a : b;
+}
+
+
+#endif
+
noinst_LTLIBRARIES = librawnsdp.la
-librawnsdp_la_SOURCES = attr.c list.c misc.c net.c packet.c
+librawnsdp_la_SOURCES = attr.c list.c net.c packet.c str.c
librawnsdp_la_CPPFLAGS = -I$(top_srcdir)/raw/include/ -I$(top_srcdir)/lib/include/
librawnsdp_la_CFLAGS = -fno-strict-aliasing
librawnsdp_la_LIBADD = $(RT_LIBS)
+++ /dev/null
-
-#include <stdlib.h>
-
-#include <nsdp/misc.h>
-
-
-static const char passwordKey[] = "NtgrSmartSwitchRock";
-
-
-void passwordEndecode (char *buf, unsigned int len)
-{
- const char *k = passwordKey;
- unsigned int i;
-
- if (buf == NULL || len <= 0)
- return;
-
- for (i = 0; i < len; i++) {
- if (*k == '\0')
- k = passwordKey;
- buf[i] ^= *k++;
- }
-}
-
-
-int trim (char *txt, int start)
-{
- char *p;
-
- if (txt == NULL)
- return 0;
-
- p = txt + start;
- while (p >= txt && (*p == ' ' || *p == '\n')) {
- *p = '\0';
- p--;
- }
-
- return p - txt + 1;
-}
-
-
--- /dev/null
+
+#include <string.h>
+#include <ctype.h>
+
+#include <nsdp/str.h>
+
+
+const char passwordKey[] = "NtgrSmartSwitchRock";
+
+
+const char* const speed_str_tab[] = {
+ [SPEED_DOWN] = "down",
+ [SPEED_10_HD] = "10M half-duplex",
+ [SPEED_10_FD] = "10M full-duplex",
+ [SPEED_100_HD] = "100M half-duplex",
+ [SPEED_100_FD] = "100M full-duplex",
+ [SPEED_1000_FD] = "1000M full-duplex",
+ NULL
+};
+
+
+const char* const vlan_type_str_tab[] = {
+ [VLAN_DISABLED] = "disabled",
+ [VLAN_PORT_BASIC] = "basic port based",
+ [VLAN_PORT_ADV] = "advanced port based",
+ [VLAN_DOT_BASIC] = "basic 802.1Q",
+ [VLAN_DOT_ADV] = "advanced 802.1Q",
+ NULL
+};
+
+
+const char* const vlan_code_str_tab[] = {
+ [VLAN_NO] = "no",
+ [VLAN_UNTAGGED] = "untagged",
+ [VLAN_TAGGED] = "tagged",
+ NULL
+};
+
+
+const char* const qos_type_str_tab[] = {
+ [QOS_PORT] = "port",
+ [QOS_DOT] = "802.1p",
+ NULL
+};
+
+
+const char* const qos_prio_str_tab[] = {
+ [PRIO_HIGH] = "high",
+ [PRIO_MED] = "medium",
+ [PRIO_NORM] = "normal",
+ [PRIO_LOW] = "low",
+ NULL
+};
+
+
+const char* const bitrate_str_tab[] = {
+ [BITRATE_NOLIMIT] = "nl",
+ [BITRATE_512K] = "512K",
+ [BITRATE_1M] = "1M",
+ [BITRATE_2M] = "2M",
+ [BITRATE_4M] = "4M",
+ [BITRATE_8M] = "8M",
+ [BITRATE_16M] = "16M",
+ [BITRATE_32M] = "32M",
+ [BITRATE_64M] = "64M",
+ [BITRATE_128M] = "128M",
+ [BITRATE_256M] = "256M",
+ [BITRATE_512M] = "512M",
+ NULL
+};
+
+
+const char* const code_str_tab[] = {
+ [CODE_READ_REQ] = "read request",
+ [CODE_READ_REP] = "read reply",
+ [CODE_WRITE_REQ] = "write request",
+ [CODE_WRITE_REP] = "write reply",
+ NULL
+};
+
+
+const char* const error_str_tab[] = {
+ [ERROR_NONE] = "none",
+ [ERROR_READONLY] = "read only",
+ [ERROR_INVALID_VALUE] = "invalid value",
+ [ERROR_DENIED] = "access denied",
+ NULL
+};
+
+
+int parseValueStr (const char* const* tab, unsigned char mini, unsigned char maxi, const char *str)
+{
+ unsigned char i;
+
+ for (i = mini; i <= maxi; i++) {
+ if (tab[i] != NULL && strcasecmp(str, tab[i]) == 0)
+ return (int)i;
+ }
+
+ return -1;
+}
+
+
+bool isStringPrintable (const char *str, unsigned int len)
+{
+ const char *p;
+
+ for (p = str; len > 0; len--) {
+ if (!isprint(*p))
+ return false;
+ }
+
+ return true;
+}
+
+
+void passwordEndecode (char *buf, unsigned int len)
+{
+ const char *k = passwordKey;
+ unsigned int i;
+
+ if (buf == NULL || len <= 0)
+ return;
+
+ for (i = 0; i < len; i++) {
+ if (*k == '\0')
+ k = passwordKey;
+ buf[i] ^= *k++;
+ }
+}
+
+
+int trim (char *txt, int start)
+{
+ char *p;
+
+ if (txt == NULL)
+ return 0;
+
+ p = txt + start;
+ for (p--; p >= txt && (*p == ' ' || *p == '\n'); *p-- = '\0');
+
+ return p - txt + 1;
+}
+
+
#include <nsdp/protocol.h>
#include <nsdp/attr.h>
#include <nsdp/net.h>
-#include <nsdp/misc.h>
+#include <nsdp/str.h>
static void print_password (const char *pass, unsigned int len)
char *s;
- for (i = 0; i < len; i++) {
- if (!isprint(pass[i]))
- break;
- }
-
- if (i == len) {
+ if (isStringPrintable(pass, len)) {
/* all characters are printable, cleartext password assumed */
printf("(clear) \"%s\"", pass);
return;
passwordEndecode(s, len);
- for (i = 0; i < len; i++) {
- if (!isprint(s[i]))
- break;
- }
-
- if (i == len) {
+ if (isStringPrintable(s, len)) {
/* all characters are printable, encrypted password assumed */
printf("(encrypted) \"%s\"", s);
free(s);
}
-static const char* port_status_str (unsigned char status)
-{
- switch (status) {
-
- case SPEED_DOWN:
- return "down";
-
- case SPEED_10_HD:
- return "10M half-duplex";
-
- case SPEED_10_FD:
- return "10M full-duplex";
-
- case SPEED_100_HD:
- return "100M half-duplex";
-
- case SPEED_100_FD:
- return "100M full-duplex";
-
- case SPEED_1000_FD:
- return "1000M full-duplex";
-
- default:
- return "unknown";
- }
-}
-
-
-static const char* vlan_type_code (unsigned char type)
-{
- switch (type) {
-
- case VLAN_DISABLED:
- return "disabled";
-
- case VLAN_PORT_BASIC:
- return "basic port based";
-
- case VLAN_PORT_ADV:
- return "advanced port based";
-
- case VLAN_DOT_BASIC:
- return "basic 802.1Q";
-
- case VLAN_DOT_ADV:
- return "advanced 802.1Q";
-
- default:
- return "unknown";
- }
-}
-
-
-static const char* vlan_code_str (unsigned char code)
-{
- switch (code) {
-
- case VLAN_NO:
- return "no";
-
- case VLAN_UNTAGGED:
- return "untagged";
-
- case VLAN_TAGGED:
- return "tagged";
-
- default:
- return "unknown";
- }
-}
-
-
-static const char* qos_type_str (unsigned char type)
-{
- switch (type) {
-
- case QOS_PORT:
- return "port";
-
- case QOS_DOT:
- return "802.1p";
-
- default:
- return "unknown";
- }
-}
-
-
-static const char* qos_prio_str (unsigned char prio)
-{
- switch (prio) {
-
- case PRIO_HIGH:
- return "high";
-
- case PRIO_MED:
- return "medium";
-
- case PRIO_NORM:
- return "normal";
-
- case PRIO_LOW:
- return "low";
-
- default:
- return "unknown";
- }
-}
-
-
-static const char* bitrate_str (unsigned int bitrate)
-{
- switch (bitrate) {
-
- case BITRATE_NOLIMIT:
- return "unlimited";
-
- case BITRATE_512K:
- return "512K";
-
- case BITRATE_1M:
- return "1M";
-
- case BITRATE_2M:
- return "2M";
-
- case BITRATE_4M:
- return "4M";
-
- case BITRATE_8M:
- return "8M";
-
- case BITRATE_16M:
- return "16M";
-
- case BITRATE_32M:
- return "32M";
-
- case BITRATE_64M:
- return "64M";
-
- case BITRATE_128M:
- return "128M";
-
- case BITRATE_256M:
- return "256M";
-
- case BITRATE_512M:
- return "512M";
-
- default:
- return "unknown";
- }
-}
-
-
static void print_attr (const struct attr *at)
{
unsigned char p, ports, *byte = at->data;
case ATTR_PORT_STATUS:
printf("\tport status\n");
printf("\tport = %u\n", apsu->port);
- printf("\tstate = %s\n", port_status_str(apsu->status));
+ printf("\tstate = %s\n", safeStr(getSpeedStr(apsu->status)));
break;
case ATTR_PORT_STATISTICS:
break;
case ATTR_VLAN_TYPE:
- printf("\tVLAN type = %s\n", vlan_type_code(*byte));
+ printf("\tVLAN type = %s\n", safeStr(getVlanTypeStr(*byte)));
break;
case ATTR_VLAN_PORT_CONF:
printf("\tVLAN = %u\n", avc->vlan);
ports = at->size - sizeof(struct attr_vlan_conf);
for (p = 0; p < ports; p++)
- printf("\tport %d = %s\n", p + 1, vlan_code_str(avc->ports[p]));
+ printf("\tport %d = %s\n", p + 1, safeStr(getVlanCodeStr(avc->ports[p])));
break;
case ATTR_VLAN_DOT_CONF:
printf("\tVLAN = %u\n", avc->vlan);
ports = at->size - sizeof(struct attr_vlan_conf);
for (p = 0; p < ports; p++)
- printf("\tport %d = %s\n", p + 1, vlan_code_str(avc->ports[p]));
+ printf("\tport %d = %s\n", p + 1, safeStr(getVlanCodeStr(avc->ports[p])));
break;
case ATTR_VLAN_DESTROY:
break;
case ATTR_QOS_TYPE:
- printf("\tQoS type = %s\n", qos_type_str(*byte));
+ printf("\tQoS type = %s\n", safeStr(getQosTypeStr(*byte)));
break;
case ATTR_QOS_CONFIG:
printf("\tQoS configuration\n");
printf("\tport = %u\n", aq->port);
- printf("\tpriority = %s\n", qos_prio_str(aq->prio));
+ printf("\tpriority = %s\n", safeStr(getQosPrioStr(aq->prio)));
break;
case ATTR_BITRATE_INPUT:
printf("\tinput bitrate\n");
printf("\tport = %u\n", ab->port);
- printf("\tbitrate = %s\n", bitrate_str(ab->bitrate));
+ printf("\tbitrate = %s\n", safeStr(getBitrateStr(ab->bitrate)));
break;
case ATTR_BITRATE_OUTPUT:
printf("\toutput bitrate\n");
printf("\tport = %u\n", ab->port);
- printf("\tbitrate = %s\n", bitrate_str(ab->bitrate));
+ printf("\tbitrate = %s\n", safeStr(getBitrateStr(ab->bitrate)));
break;
case ATTR_STORM_ENABLE:
case ATTR_STORM_BITRATE:
printf("\tstorm filtering bitrate\n");
printf("\tport = %u\n", ab->port);
- printf("\tbitrate = %s\n", bitrate_str(ab->bitrate));
+ printf("\tbitrate = %s\n", safeStr(getBitrateStr(ab->bitrate)));
break;
case ATTR_MIRROR:
}
-static const char* code_str (unsigned char code)
-{
- switch (code) {
-
- case CODE_READ_REQ:
- return "read request";
-
- case CODE_READ_REP:
- return "read reply";
-
- case CODE_WRITE_REQ:
- return "write request";
-
- case CODE_WRITE_REP:
- return "write reply";
-
- default:
- return "unknown";
- }
-}
-
-
-static const char* error_str (unsigned char err)
-{
- switch (err) {
-
- case 0:
- return "none";
-
- case ERROR_READONLY:
- return "read only";
-
- case ERROR_INVALID_VALUE:
- return "invalid value";
-
- case ERROR_DENIED:
- return "access denied";
-
- default:
- return "unknown";
- }
-}
-
-
static void print_packet (const List *attr, const struct nsdp_cmd *nc)
{
const ListNode *ln;
printf("---------------------------------\n");
- printf("code = %s (%u)\n", code_str(nc->code), nc->code);
- printf("error = %s (%u)\n", error_str(nc->error), nc->error);
+ printf("code = %s (%u)\n", safeStr(getCodeStr(nc->code)), nc->code);
+ printf("error = %s (%u)\n", safeStr(getErrorStr(nc->error)), nc->error);
if (nc->attr_error != 0)
printf("erroneous attribute = %04X\n", nc->attr_error);
printf("source address = %s:%u\n", inet_ntoa(nc->remote_addr.sin_addr), ntohs(nc->remote_addr.sin_port));