aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2008-09-26 15:35:57 -1000
committerBill Nottingham <notting@redhat.com>2009-03-19 15:49:54 -0400
commit17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40 (patch)
treec4ac96e48ed8f72c6de1f9717732f3f5d5c14561
parent6928c0976e15fa9e592d9a83391adbaab927460f (diff)
downloadinitscripts-17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40.tar
initscripts-17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40.tar.gz
initscripts-17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40.tar.bz2
initscripts-17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40.tar.xz
initscripts-17057e2d8ec5fe3395cbb0c0a7552c1eaff2ff40.zip
Use inet_ntop() and inet_pton()
The inet_ntoa() and inet_aton() functions are deprecated and limited to AF_INET only.
-rw-r--r--src/ipcalc.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/ipcalc.c b/src/ipcalc.c
index 31094be9..fc81ba26 100644
--- a/src/ipcalc.c
+++ b/src/ipcalc.c
@@ -204,6 +204,7 @@ int main(int argc, const char **argv) {
int rc;
poptContext optCon;
char *ipStr, *prefixStr, *netmaskStr, *hostName, *chptr;
+ char namebuf[INET6_ADDRSTRLEN+1];
struct in_addr ip, netmask, network, broadcast;
int prefix = 0;
char errBuf[250];
@@ -276,7 +277,7 @@ int main(int argc, const char **argv) {
}
return 1;
} else if (netmaskStr) {
- if (!inet_aton(netmaskStr, &netmask)) {
+ if (inet_pton(AF_INET, netmaskStr, &netmask) <= 0) {
if (!beSilent)
fprintf(stderr, "ipcalc: bad netmask: %s\n", netmaskStr);
return 1;
@@ -313,7 +314,7 @@ int main(int argc, const char **argv) {
}
}
- if (!inet_aton(ipStr, (struct in_addr *) &ip)) {
+ if (inet_pton(AF_INET, ipStr, &ip) <= 0) {
if (!beSilent)
fprintf(stderr, "ipcalc: bad ip address: %s\n", ipStr);
return 1;
@@ -337,7 +338,14 @@ int main(int argc, const char **argv) {
prefix = mask2prefix(netmask);
}
- printf("NETMASK=%s\n", inet_ntoa(netmask));
+ memset(&namebuf, '\0', sizeof(namebuf));
+
+ if (inet_ntop(AF_INET, &netmask, namebuf, INET_ADDRSTRLEN) == NULL) {
+ fprintf(stderr, "Memory allocation failure line %d\n", __LINE__);
+ abort();
+ }
+
+ printf("NETMASK=%s\n", namebuf);
}
if (showPrefix) {
@@ -348,12 +356,26 @@ int main(int argc, const char **argv) {
if (showBroadcast) {
broadcast = calc_broadcast(ip, prefix);
- printf("BROADCAST=%s\n", inet_ntoa(broadcast));
+ memset(&namebuf, '\0', sizeof(namebuf));
+
+ if (inet_ntop(AF_INET, &broadcast, namebuf, INET_ADDRSTRLEN) == NULL) {
+ fprintf(stderr, "Memory allocation failure line %d\n", __LINE__);
+ abort();
+ }
+
+ printf("BROADCAST=%s\n", namebuf);
}
if (showNetwork) {
network = calc_network(ip, prefix);
- printf("NETWORK=%s\n", inet_ntoa(network));
+ memset(&namebuf, '\0', sizeof(namebuf));
+
+ if (inet_ntop(AF_INET, &network, namebuf, INET_ADDRSTRLEN) == NULL) {
+ fprintf(stderr, "Memory allocation failure line %d\n", __LINE__);
+ abort();
+ }
+
+ printf("NETWORK=%s\n", namebuf);
}
if (showHostname) {