int mask2bits(__u32 netmask);
int get_addr_ila(__u64 *val, const char *arg);
+int get_hex(char c);
int get_integer(int *val, const char *arg, int base);
int get_unsigned(unsigned *val, const char *arg, int base);
int get_time_rtt(unsigned *val, const char *arg, int *raw);
* Command parser
*****************************************************************************/
-static int hex(char ch)
-{
- if ((ch >= 'a') && (ch <= 'f'))
- return ch - 'a' + 10;
- if ((ch >= '0') && (ch <= '9'))
- return ch - '0';
- if ((ch >= 'A') && (ch <= 'F'))
- return ch - 'A' + 10;
- return -1;
-}
-
static int hex2mem(const char *buf, uint8_t *mem, int count)
{
int i, j;
int c;
for (i = 0, j = 0; i < count; i++, j += 2) {
- c = hex(buf[j]);
+ c = get_hex(buf[j]);
if (c < 0)
goto err;
mem[i] = c << 4;
- c = hex(buf[j + 1]);
+ c = get_hex(buf[j + 1]);
if (c < 0)
goto err;
#include "utils.h"
-static u_int32_t hexget(char c)
-{
- if (c >= 'A' && c <= 'F')
- return c - 'A' + 10;
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 10;
- if (c >= '0' && c <= '9')
- return c - '0';
-
- return 0xf0;
-}
-
static int ipx_getnet(u_int32_t *net, const char *str)
{
int i;
for(i = 0; *str && (i < 8); i++) {
- if ((tmp = hexget(*str)) & 0xf0) {
+ if ((tmp = get_hex(*str)) == -1) {
if (*str == '.')
return 0;
else
u_int32_t tmp;
for(i = 0; i < 6; i++) {
- if ((tmp = hexget(*str++)) & 0xf0)
+ if ((tmp = get_hex(*str++)) == -1)
return -1;
node[i] = (u_int8_t)tmp;
node[i] <<= 4;
- if ((tmp = hexget(*str++)) & 0xf0)
+ if ((tmp = get_hex(*str++)) == -1)
return -1;
node[i] |= (u_int8_t)tmp;
if (*str == ':')
int timestamp_short = 0;
+int get_hex(char c)
+{
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ if (c >= '0' && c <= '9')
+ return c - '0';
+
+ return -1;
+}
+
int get_integer(int *val, const char *arg, int base)
{
long res;