summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-12 23:08:22 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-12 23:08:22 (GMT)
commitad05cdfa1f3e2ddee87cdbcf212a6983dc5d982b (patch)
treee61ded3feefa658b76fd62e7aa4c870041d42502
parent2294c0d4ecd81d01ddf741fff02cc04bd8de0638 (diff)
downloadcpython-ad05cdfa1f3e2ddee87cdbcf212a6983dc5d982b.zip
cpython-ad05cdfa1f3e2ddee87cdbcf212a6983dc5d982b.tar.gz
cpython-ad05cdfa1f3e2ddee87cdbcf212a6983dc5d982b.tar.bz2
Addressing SF bug #643005, implement socket.inet_aton() using
inet_aton() rather than inet_addr() -- the latter is obsolete because it has a problem: "255.255.255.255" is a valid address but indistinguishable from an error. (I'm not sure if inet_aton() exists everywhere -- in case it doesn't, I've left the old code in with an #ifdef.)
-rw-r--r--Modules/socketmodule.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 63ad50a..26e5e01 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2713,11 +2713,26 @@ socket_inet_aton(PyObject *self, PyObject *args)
/* Have to use inet_addr() instead */
char *ip_addr;
- unsigned long packed_addr;
+#if 1
+ struct in_addr buf;
if (!PyArg_ParseTuple(args, "s:inet_aton", &ip_addr)) {
return NULL;
}
+
+ if (inet_aton(ip_addr, &buf))
+ return PyString_FromStringAndSize((char *)(&buf),
+ sizeof(buf));
+
+ PyErr_SetString(socket_error,
+ "illegal IP address string passed to inet_aton");
+ return NULL;
+
+#else /* In case you don't have inet_aton() */
+ /* XXX Problem here: inet_aton('255.255.255.255') raises
+ an exception while it should be a valid address. */
+ unsigned long packed_addr;
+
packed_addr = inet_addr(ip_addr);
if (packed_addr == INADDR_NONE) { /* invalid address */
@@ -2728,6 +2743,7 @@ socket_inet_aton(PyObject *self, PyObject *args)
return PyString_FromStringAndSize((char *) &packed_addr,
sizeof(packed_addr));
+#endif
}
PyDoc_STRVAR(inet_ntoa_doc,