Skip to content

Commit

Permalink
[SQUASH ME] shell: addressed comments to ipv6_nc
Browse files Browse the repository at this point in the history
  • Loading branch information
miri64 committed Mar 24, 2015
1 parent 5a7ccf4 commit a697517
Showing 1 changed file with 4 additions and 29 deletions.
33 changes: 4 additions & 29 deletions sys/shell/commands/sc_ipv6_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,6 @@ static bool _is_iface(kernel_pid_t iface)
#endif
}

static size_t _parse_addr(char *str, uint8_t *addr)
{
char *tok = strtok(str, ":");
size_t res = 0;

while (tok != NULL) {
if (res >= MAX_L2_ADDR_LEN) {
return 0;
}

uint16_t tmp = (uint16_t)strtol(tok, NULL, 16);

if (tmp <= 0xff) {
addr[res++] = (uint8_t)tmp;
}
else {
return 0;
}

tok = strtok(NULL, ":");
}

return res;
}

static void _ipv6_nc_add(kernel_pid_t iface, char *ipv6_addr_str,
char *l2_addr_str)
{
Expand All @@ -81,7 +56,7 @@ static void _ipv6_nc_add(kernel_pid_t iface, char *ipv6_addr_str,
return;
}

if ((l2_addr_len = _parse_addr(l2_addr_str, l2_addr)) == 0) {
if ((l2_addr_len = ng_netif_addr_parse(l2_addr, sizeof(l2_addr), l2_addr_str)) == 0) {
puts("error: unable to parse link-layer address.");
return;
}
Expand Down Expand Up @@ -110,9 +85,9 @@ static void _ipv6_nc_del(char *ipv6_addr_str)
void _ipv6_nc_manage(int argc, char **argv)
{
if (argc > 2) {
kernel_pid_t iface = (kernel_pid_t)atoi(argv[2]);

if ((argc > 4) && (strcmp("add", argv[1]) == 0)) {
kernel_pid_t iface = (kernel_pid_t)atoi(argv[2]);

if (!_is_iface(iface)) {
puts("error: invalid interface given.");
return;
Expand All @@ -128,7 +103,7 @@ void _ipv6_nc_manage(int argc, char **argv)
}
}

printf("usage: %s add <if> <ipv6_addr> <l2_addr>\n"
printf("usage: %s add <iface pid> <ipv6_addr> <l2_addr>\n"
" or: %s del <ipv6_addr>\n", argv[0], argv[0]);
}

Expand Down

0 comments on commit a697517

Please sign in to comment.