| 2130 | } |
| 2131 | |
| 2132 | int HAMLIB_API parse_hoststr(char *hoststr, int hoststr_len, char host[256], |
| 2133 | char port[6]) |
| 2134 | { |
| 2135 | unsigned int net1, net2, net3, net4, net5, net6, net7, net8; |
| 2136 | char dummy[6], link[32], *p; |
| 2137 | host[0] = 0; |
| 2138 | port[0] = 0; |
| 2139 | dummy[0] = 0; |
| 2140 | |
| 2141 | // Exclude any names that aren't a host:port format |
| 2142 | // Handle device names 1st |
| 2143 | if (strstr(hoststr, "/dev")) { return -RIG_EINVAL; } |
| 2144 | |
| 2145 | if (strstr(hoststr, "/")) { return -RIG_EINVAL; } // probably a path so not a hoststr |
| 2146 | |
| 2147 | if (strncasecmp(hoststr, "com", 3) == 0) { return -RIG_EINVAL; } |
| 2148 | |
| 2149 | // escaped COM port like \\.\COM3 or \.\COM3 |
| 2150 | if (strstr(hoststr, "\\.\\")) { return -RIG_EINVAL; } |
| 2151 | |
| 2152 | // Now let's try and parse a host:port thing |
| 2153 | // bracketed IPV6 with optional port |
| 2154 | int n = sscanf(hoststr, "[%255[^]]]:%5s", host, port); |
| 2155 | |
| 2156 | if (n >= 1) |
| 2157 | { |
| 2158 | return RIG_OK; |
| 2159 | } |
| 2160 | |
| 2161 | // non-bracketed full IPV6 with optional link addr |
| 2162 | n = sscanf(hoststr, "%x:%x:%x:%x:%x:%x:%x:%x%%%31[^:]:%5s", &net1, &net2, &net3, |
| 2163 | &net4, &net5, &net6, &net7, &net8, link, port); |
| 2164 | |
| 2165 | if (n == 8 || n == 9) |
| 2166 | { |
| 2167 | strcpy(host, hoststr); |
| 2168 | return RIG_OK; |
| 2169 | } |
| 2170 | else if (n == 10) |
| 2171 | { |
| 2172 | strcpy(host, hoststr); |
| 2173 | p = strrchr(host, ':'); // remove port from host |
| 2174 | *p = 0; |
| 2175 | return RIG_OK; |
| 2176 | } |
| 2177 | |
| 2178 | // non-bracketed IPV6 with optional link addr and optional port |
| 2179 | n = sscanf(hoststr, "%x::%x:%x:%x:%x%%%31[^:]:%5s", &net1, &net2, &net3, |
| 2180 | &net4, &net5, link, port); |
| 2181 | |
| 2182 | if (strchr(hoststr, '%') && (n == 5 || n == 6)) |
| 2183 | { |
| 2184 | strcpy(host, hoststr); |
| 2185 | return RIG_OK; |
| 2186 | } |
| 2187 | else if (n == 7) |
| 2188 | { |
| 2189 | strcpy(host, hoststr); |