* @ingroup ipaddr * Convert IP address string (both versions) to numeric. * The version is auto-detected from the string. * * @param cp IP address string to convert * @param addr conversion result is stored here * @return 1 on success, 0 on error */
| 120 | * @return 1 on success, 0 on error |
| 121 | */ |
| 122 | int |
| 123 | ipaddr_aton(const char *cp, ip_addr_t *addr) |
| 124 | { |
| 125 | if (cp != NULL) { |
| 126 | const char *c; |
| 127 | for (c = cp; *c != 0; c++) { |
| 128 | if (*c == ':') { |
| 129 | /* contains a colon: IPv6 address */ |
| 130 | if (addr) { |
| 131 | IP_SET_TYPE_VAL(*addr, IPADDR_TYPE_V6); |
| 132 | } |
| 133 | return ip6addr_aton(cp, ip_2_ip6(addr)); |
| 134 | } else if (*c == '.') { |
| 135 | /* contains a dot: IPv4 address */ |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | /* call ip4addr_aton as fallback or if IPv4 was found */ |
| 140 | if (addr) { |
| 141 | IP_SET_TYPE_VAL(*addr, IPADDR_TYPE_V4); |
| 142 | } |
| 143 | return ip4addr_aton(cp, ip_2_ip4(addr)); |
| 144 | } |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @ingroup lwip_nosys |