summaryrefslogtreecommitdiff
path: root/cleopatre/application/libspid/src/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/application/libspid/src/network.c')
-rw-r--r--cleopatre/application/libspid/src/network.c96
1 files changed, 23 insertions, 73 deletions
diff --git a/cleopatre/application/libspid/src/network.c b/cleopatre/application/libspid/src/network.c
index 25f2390399..62aef2145c 100644
--- a/cleopatre/application/libspid/src/network.c
+++ b/cleopatre/application/libspid/src/network.c
@@ -98,84 +98,34 @@ libspid_error_t libspid_network_get_ip (const char *interface, libspid_ip_t *ip)
continue;
}
- /* --- address --- */
- if ( strcmp(ptr, "address") == 0 )
+ char *ip_field = NULL;
+
+ if (!strcmp (ptr, "address"))
+ ip_field = (char *) ip->address;
+ else if (!strcmp (ptr, "netmask"))
+ ip_field = (char *) ip->netmask;
+ else if (!strcmp (ptr, "broadcast"))
+ ip_field = (char *) ip->broadcast;
+ else if (!strcmp (ptr, "gateway"))
+ ip_field = (char *) ip->gateway;
+
+ if (ip_field)
{
- value = strtok_r(NULL, " \t", &strtok_ctx);
- if ( (ptr == NULL) || (strlen(ptr) <= 0) )
+ int string_size;
+ value = strtok_r (NULL, " \t", &strtok_ctx);
+ if (ptr == NULL || strlen (ptr) <= 0)
{
- /* put empty string into ip->address */
- strcpy((char *)ip->address, "");
+ /* Put empty string into ip->address. */
+ strcpy (ip_field, "");
continue;
}
- /* suppress '\n' character */
- value[strlen(value) - 1] = '\0';
- /* check for buffer overflow */
- if ( strlen(value) + 1 > LIBSPID_IP_STR_MAX_LEN )
- {
+ string_size = strlen (value);
+ /* Suppress '\n' character. */
+ value[string_size - 1] = '\0';
+ /* Check for buffer overflow. */
+ if (string_size + 1 > LIBSPID_IP_STR_MAX_LEN )
return LIBSPID_ERROR_NO_SPACE;
- }
- strcpy((char *)ip->address, value);
- }
-
- /* --- netmask --- */
- if ( strcmp(ptr, "netmask") == 0 )
- {
- value = strtok_r(NULL, " \t", &strtok_ctx);
- if ( (ptr == NULL) || (strlen(ptr) <= 0) )
- {
- /* put empty string into ip->netmask */
- strcpy((char *)ip->netmask, "");
- continue;
- }
- /* suppress '\n' character */
- value[strlen(value) - 1] = '\0';
- /* check for buffer overflow */
- if ( strlen(value) + 1 > LIBSPID_IP_STR_MAX_LEN )
- {
- return LIBSPID_ERROR_NO_SPACE;
- }
- strcpy((char *)ip->netmask, value);
- }
-
- /* --- broadcast --- */
- if ( strcmp(ptr, "broadcast") == 0 )
- {
- value = strtok_r(NULL, " \t", &strtok_ctx);
- if ( (ptr == NULL) || (strlen(ptr) <= 0) )
- {
- /* put empty string into ip->broadcast */
- strcpy((char *)ip->broadcast, "");
- continue;
- }
- /* suppress '\n' character */
- value[strlen(value) - 1] = '\0';
- /* check for buffer overflow */
- if ( strlen(value) + 1 > LIBSPID_IP_STR_MAX_LEN )
- {
- return LIBSPID_ERROR_NO_SPACE;
- }
- strcpy((char *)ip->broadcast, value);
- }
-
- /* --- gateway --- */
- if ( strcmp(ptr, "gateway") == 0 )
- {
- value = strtok_r(NULL, " \t", &strtok_ctx);
- if ( (ptr == NULL) || (strlen(ptr) <= 0) )
- {
- /* put empty string into ip->gateway */
- strcpy((char *)ip->gateway, "");
- continue;
- }
- /* suppress '\n' character */
- value[strlen(value) - 1] = '\0';
- /* check for buffer overflow */
- if ( strlen(value) + 1 > LIBSPID_IP_STR_MAX_LEN )
- {
- return LIBSPID_ERROR_NO_SPACE;
- }
- strcpy((char *)ip->gateway, value);
+ strcpy (ip_field, value);
}
} /* while */