Index: socketmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v retrieving revision 1.249 diff -r1.249 socketmodule.c 2759a2760,2837 > PyDoc_STRVAR(inet_pton_doc, > "inet_pton(af, ip) -> packed IP address string\n\ > \n\ > Convert an IP address from string format to a packed string suitable for use\n\ > with low-level network functions."); > > /* Python interface to inet_pton(af, src, dst) */ > static PyObject * > socket_inet_pton(PyObject *self, PyObject *args) > { > int af; > char* ip; > int retval; > char packed[16]; > > if (!PyArg_ParseTuple(args, "is:inet_pton", &af, &ip)) { > return NULL; > } > > retval = inet_pton(af, ip, &packed[0]); > if (retval < 0) { > PyErr_SetFromErrno(socket_error); > return NULL; > } else if (retval == 0) { > PyErr_SetString(socket_error, > "illegal IP address string passed to inet_pton"); > return NULL; > } else if (af == AF_INET) { > return PyString_FromStringAndSize(&packed[0], > sizeof(struct in_addr)); > #ifdef ENABLE_IPV6 > } else if (af == AF_INET6) { > return PyString_FromStringAndSize(&packed[0], > sizeof(struct in6_addr)); > #endif > } else { > PyErr_SetString(socket_error, "unknown address family"); > return NULL; > } > } > > PyDoc_STRVAR(inet_ntop_doc, > "inet_ntop(af, packed_ip) -> string formatted IP address > \n\ > Convert a packed IP address of the given family to string format."); > > static PyObject * > socket_inet_ntop(PyObject *self, PyObject *args) > { > int af; > char* packed; > int len; /* ignored */ > const char* retval; > #ifdef ENABLE_IPV6 > char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)]; > #else > char ip[INET_ADDRSTRLEN]; > #endif > if (!PyArg_ParseTuple(args, "is#:inet_ntop", &af, &packed, &len)) { > return NULL; > } > > retval = inet_ntop(af, packed, &ip[0], sizeof(ip)); > if (!retval) { > PyErr_SetFromErrno(socket_error); > return NULL; > } else if (af == AF_INET) { > return PyString_FromString(retval); > #ifdef ENABLE_IPV6 > } else if (af == AF_INET6) { > return PyString_FromString(retval); > #endif > } else { > PyErr_SetString(socket_error, "unknown address family"); > return NULL; > } > } > 3000a3079,3082 > {"inet_pton", socket_inet_pton, > METH_VARARGS, inet_pton_doc}, > {"inet_ntop", socket_inet_ntop, > METH_VARARGS, inet_ntop_doc},