Skip to content

Commit

Permalink
Use inet_ntop() to output IPv4 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Jan 17, 2017
1 parent bb26a8f commit fa47f13
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 28 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2017-01-17 Albert Chu <[email protected]>

* ipmi-config/: Use inet_ntop() to output IPv4 addresses instead
of outputting "by hand".

2017-01-03 Albert Chu <[email protected]>

* common/toolcommon/pstdout.c (pstdout_hostnames_count): Slight
Expand Down
73 changes: 45 additions & 28 deletions ipmi-config/ipmi-config-category-core-lan-conf-section.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#if STDC_HEADERS
#include <string.h>
#endif /* STDC_HEADERS */
#include <arpa/inet.h>
#include <assert.h>

#include "ipmi-config.h"
Expand Down Expand Up @@ -255,13 +256,17 @@ ip_address_checkout (ipmi_config_state_data_t *state_data,
}

memset (ip_address_str, '\0', BMC_MAXIPADDRLEN+1);
snprintf (ip_address_str,
BMC_MAXIPADDRLEN,
"%u.%u.%u.%u",
ip_address_bytes[0],
ip_address_bytes[1],
ip_address_bytes[2],
ip_address_bytes[3]);
if (!inet_ntop (AF_INET,
ip_address_bytes,
ip_address_str,
BMC_MAXIPADDRLEN))
{
pstdout_fprintf (state_data->pstate,
stderr,
"inet_ntop: %s",
strerror (errno));
goto cleanup;
}

if (ipmi_config_section_update_keyvalue_output (state_data,
kv,
Expand Down Expand Up @@ -558,13 +563,17 @@ subnet_mask_checkout (ipmi_config_state_data_t *state_data,
}

memset (subnet_mask_str, '\0', BMC_MAXIPADDRLEN + 1);
snprintf (subnet_mask_str,
BMC_MAXIPADDRLEN,
"%u.%u.%u.%u",
subnet_mask_bytes[0],
subnet_mask_bytes[1],
subnet_mask_bytes[2],
subnet_mask_bytes[3]);
if (!inet_ntop (AF_INET,
subnet_mask_bytes,
subnet_mask_str,
BMC_MAXIPADDRLEN))
{
pstdout_fprintf (state_data->pstate,
stderr,
"inet_ntop: %s",
strerror (errno));
goto cleanup;
}

if (ipmi_config_section_update_keyvalue_output (state_data,
kv,
Expand Down Expand Up @@ -708,13 +717,17 @@ default_gateway_address_checkout (ipmi_config_state_data_t *state_data,
}

memset (ip_address_str, '\0', BMC_MAXIPADDRLEN + 1);
snprintf (ip_address_str,
BMC_MAXIPADDRLEN,
"%u.%u.%u.%u",
ip_address_bytes[0],
ip_address_bytes[1],
ip_address_bytes[2],
ip_address_bytes[3]);
if (!inet_ntop (AF_INET,
ip_address_bytes,
ip_address_str,
BMC_MAXIPADDRLEN))
{
pstdout_fprintf (state_data->pstate,
stderr,
"inet_ntop: %s",
strerror (errno));
goto cleanup;
}

if (ipmi_config_section_update_keyvalue_output (state_data,
kv,
Expand Down Expand Up @@ -1012,13 +1025,17 @@ backup_gateway_address_checkout (ipmi_config_state_data_t *state_data,
}

memset (ip_address_str, '\0', BMC_MAXIPADDRLEN+1);
snprintf (ip_address_str,
BMC_MAXIPADDRLEN,
"%u.%u.%u.%u",
ip_address_bytes[0],
ip_address_bytes[1],
ip_address_bytes[2],
ip_address_bytes[3]);
if (!inet_ntop (AF_INET,
ip_address_bytes,
ip_address_str,
BMC_MAXIPADDRLEN))
{
pstdout_fprintf (state_data->pstate,
stderr,
"inet_ntop: %s",
strerror (errno));
goto cleanup;
}

if (ipmi_config_section_update_keyvalue_output (state_data,
kv,
Expand Down

0 comments on commit fa47f13

Please sign in to comment.