summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-08-20 19:11:27 (GMT)
committerGuido van Rossum <guido@python.org>1999-08-20 19:11:27 (GMT)
commitc6a164b8bca70952a9320288eb17d8d951651dd8 (patch)
treeb9b3f0926d750568c21cdcba97a496d712d39db8 /Modules/socketmodule.c
parente61e98d2ae345518f68d199f04f982c331beb210 (diff)
downloadcpython-c6a164b8bca70952a9320288eb17d8d951651dd8.zip
cpython-c6a164b8bca70952a9320288eb17d8d951651dd8.tar.gz
cpython-c6a164b8bca70952a9320288eb17d8d951651dd8.tar.bz2
Port inet_ntoa and inet_aton to Windows:
- fix unescaped newline in string literal - removed unused err variable - Windows doesn't have inet_aton; use inet_addr instead
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 81088ba..e64090e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1801,12 +1801,13 @@ Convert a 32-bit integer from host to network byte order.";
static char inet_aton_doc[] =
"inet_aton(string) -> packed 32-bit IP representation\n\
\n\
-Convert an IP address in string format (123.45.67.89) to the 32-bit packed
+Convert an IP address in string format (123.45.67.89) to the 32-bit packed\n\
binary format used in low-level network functions.";
static PyObject*
BUILD_FUNC_DEF_2(PySocket_inet_aton, PyObject *, self, PyObject *, args)
{
+#ifndef MS_WINDOWS
char *ip_addr;
struct in_addr packed_addr;
int err;
@@ -1825,6 +1826,26 @@ BUILD_FUNC_DEF_2(PySocket_inet_aton, PyObject *, self, PyObject *, args)
return PyString_FromStringAndSize((char *) &packed_addr,
sizeof(packed_addr));
+#else /* MS_WINDOWS */
+ /* Have to use inet_addr() instead */
+ char *ip_addr;
+ long packed_addr;
+
+ if (!PyArg_Parse(args, "s", &ip_addr)) {
+ return NULL;
+ }
+
+ packed_addr = inet_addr(ip_addr);
+
+ if (packed_addr == INADDR_NONE) { /* invalid address */
+ PyErr_SetString(PySocket_Error,
+ "illegal IP address string passed to inet_aton");
+ return NULL;
+ }
+
+ return PyString_FromStringAndSize((char *) &packed_addr,
+ sizeof(packed_addr));
+#endif /* MS_WINDOWS */
}
static char inet_ntoa_doc[] =
@@ -1836,7 +1857,7 @@ static PyObject*
BUILD_FUNC_DEF_2(PySocket_inet_ntoa, PyObject *, self, PyObject *, args)
{
char *packed_str;
- int err, addr_len;
+ int addr_len;
struct in_addr packed_addr;
if (!PyArg_Parse(args, "s#", &packed_str, &addr_len)) {