static int __net_convert_string_to_ipv6_string(char *str, char **ip_address)
{
- int i = 1;
int pos = 0;
struct sockaddr_in6 sa;
+ char conv_str[INET6_ADDRSTRLEN] = {0,};
*ip_address = (char *)malloc(INET6_ADDRSTRLEN);
if (NULL == *ip_address) {
}
/* Convert String without : to string with : */
- for (i = 1; i < 8; i++) {
- pos = 4 * i + i;
- memmove(str + pos, str + pos - 1,
- strlen(str) - pos + 2 * i);
- str[pos - 1] = ':';
+ for (int i = 0; i < 8; i++) {
+ pos = 4 * i;
+ if (pos > 0)
+ conv_str[pos + i - 1] = ':';
+ memcpy(conv_str + pos + i, str + pos, 4);
}
/*
* Convert "fe80:0000:0000:0000:0a00:27ff:fe7a:65ea to fe80::a00:27ff:fe7a:65ea
*/
- inet_pton(AF_INET6, str, &(sa.sin6_addr));
+ inet_pton(AF_INET6, conv_str, &(sa.sin6_addr));
inet_ntop(AF_INET6, &(sa.sin6_addr), *ip_address, INET6_ADDRSTRLEN);
return NET_ERR_NONE;