summaryrefslogtreecommitdiff
path: root/libc/inet/addr.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-08-04 19:03:33 +0000
committerEric Andersen <andersen@codepoet.org>2003-08-04 19:03:33 +0000
commitd2cc961c7312e18852ef016b4cfa7be02bbca725 (patch)
treebbe5de6cebd8cc583f905fb3c475d14fca67fe02 /libc/inet/addr.c
parent2f40578f87cb83e379da935b3190701845b7fe88 (diff)
Update inet_aton() to support an undocumented feature of inet_aton,
per UNIX Network Programming, Volume 1, second edition: An undocumented feature of inet_aton is that if addrptr is a null pointer, the function still performs it validation of the input string, but does not store the result.
Diffstat (limited to 'libc/inet/addr.c')
-rw-r--r--libc/inet/addr.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/libc/inet/addr.c b/libc/inet/addr.c
index df14fd09f..b4f8c9b87 100644
--- a/libc/inet/addr.c
+++ b/libc/inet/addr.c
@@ -24,20 +24,17 @@
#include <ctype.h>
#include <netinet/in.h>
-int inet_aton(const char *cp, struct in_addr *inp);
+int inet_aton(const char *cp, struct in_addr *addrptr);
#ifdef L_inet_aton
-int inet_aton(cp, inp)
+int inet_aton(cp, addrptr)
const char *cp;
-struct in_addr *inp;
+struct in_addr *addrptr;
{
unsigned long addr;
int value;
int part;
- if (!inp)
- return 0;
-
addr = 0;
for (part = 1; part <= 4; part++) {
@@ -65,7 +62,16 @@ struct in_addr *inp;
addr |= value;
}
- inp->s_addr = htonl(addr);
+ /* W. Richard Stevens in his book UNIX Network Programming,
+ * Volume 1, second edition, on page 71 says:
+ *
+ * An undocumented feature of inet_aton is that if addrptr is
+ * a null pointer, the function still performs it validation
+ * of the input string, but does not store the result.
+ */
+ if (addrptr) {
+ addrptr->s_addr = htonl(addr);
+ }
return 1;
}