{
unsigned int token_len = 0;
char ether_str[ETHER_ADDRSTRLEN];
- struct ether_addr *etheraddr = res;
struct ether_addr *tmp;
if (res && ressize < sizeof(struct ether_addr))
if (tmp == NULL)
return -1;
- memcpy(ðeraddr, tmp, sizeof(etheraddr));
+ if (res != NULL)
+ memcpy(res, tmp, sizeof(struct ether_addr));
return 0;
}
struct cmdline_token_ipaddr *tk2 = (struct cmdline_token_ipaddr *)tk;
unsigned int token_len = 0;
char ip_str[INET6_ADDRSTRLEN+4]; /* '+4' is for prefixlen (if any) */
- cmdline_ipaddr_t *ipaddr = res;
+ cmdline_ipaddr_t ipaddr;
char *prefix, *prefix_end;
long prefixlen;
if (res && ressize < sizeof(cmdline_ipaddr_t))
return -1;
+ memset(&ipaddr, 0, sizeof(ipaddr));
+
/* if token is too big... */
token_len = snprintf(ip_str, sizeof(ip_str), "%s", buf);
if (token_len >= sizeof(ip_str))
prefixlen = strtol(prefix, &prefix_end, 10);
if (errno || (*prefix_end != '\0') )
return -1;
- ipaddr->prefixlen = prefixlen;
+ ipaddr.prefixlen = prefixlen;
}
else {
- ipaddr->prefixlen = 0;
+ ipaddr.prefixlen = 0;
}
/* convert the IP addr */
if ((tk2->ipaddr_data.flags & CMDLINE_IPADDR_V4) &&
- my_inet_pton(AF_INET, ip_str, &ipaddr->addr.ipv4) == 1) {
- ipaddr->family = AF_INET;
+ my_inet_pton(AF_INET, ip_str, &ipaddr.addr.ipv4) == 1) {
+ ipaddr.family = AF_INET;
+ if (res != NULL)
+ memcpy(res, &ipaddr, sizeof(ipaddr));
return 0;
}
if ((tk2->ipaddr_data.flags & CMDLINE_IPADDR_V6) &&
- my_inet_pton(AF_INET6, ip_str, &ipaddr->addr.ipv6) == 1) {
- ipaddr->family = AF_INET6;
+ my_inet_pton(AF_INET6, ip_str, &ipaddr.addr.ipv6) == 1) {
+ ipaddr.family = AF_INET6;
+ if (res != NULL)
+ memcpy(res, &ipaddr, sizeof(ipaddr));
return 0;
}
return -1;