Clean up network_open pathname logic

https://github.com/Hamlib/Hamlib/issues/298
pull/345/head
Michael Black W9MDB 2020-06-13 06:56:15 -05:00
rodzic e54bc7e860
commit a11cddfd24
1 zmienionych plików z 4 dodań i 11 usunięć

Wyświetl plik

@ -582,20 +582,19 @@ int HAMLIB_API rig_open(RIG *rig)
is_network |= sscanf(rs->rigport.pathname, "%u.%u.%u.%u:%u", &net1, &net2,
&net3, &net4, &port) == 5;
is_network |= sscanf(rs->rigport.pathname, ":%u", &port) == 1;
is_network |= strstr(rs->rigport.pathname, "localhost") != NULL;
is_network |= sscanf(rs->rigport.pathname, "%u::%u:%u:%u:%u:%u", &net1, &net2,
&net3, &net4, &net5, &port) == 6;
is_network |= sscanf(rs->rigport.pathname, "%u:%u:%u:%u:%u:%u:%u:%u:%u", &net1,
&net2, &net3, &net4, &net5, &net6, &net7, &net8, &port) == 9;
if ((token = strtok_r(rs->rigport.pathname, ":", &strtokp)))
// if we haven't met one of the condition above then we must have a hostname
if (!is_network && (token = strtok_r(rs->rigport.pathname, ":", &strtokp)))
{
rig_debug(RIG_DEBUG_ERR, "%s: token1=%s\n", __func__, token);
rig_debug(RIG_DEBUG_TRACE, "%s: token1=%s\n", __func__, token);
token = strtok_r(strtokp, ":", &strtokp);
if (token)
{
rig_debug(RIG_DEBUG_ERR, "%s: token2=%s\n", __func__, token);
rig_debug(RIG_DEBUG_TRACE, "%s: token2=%s\n", __func__, token);
if (sscanf(token, "%d", &port)) { is_network |= 1; }
}
@ -607,12 +606,6 @@ int HAMLIB_API rig_open(RIG *rig)
rs->rigport.pathname);
rs->rigport.type.rig = RIG_PORT_NETWORK;
}
else if (sscanf(rs->rigport.pathname, ":%u", &port) == 1)
{
rig_debug(RIG_DEBUG_TRACE, "%s: using network address %s\n", __func__,
rs->rigport.pathname);
rs->rigport.type.rig = RIG_PORT_NETWORK;
}
if (rs->rigport.type.rig == RIG_PORT_SERIAL)
{