Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(158464)

Side by Side Diff: Modules/socketmodule.c

Issue 23001: Accept mutable bytes-like objects
Patch Set: Created 4 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Socket module */ 1 /* Socket module */
2 2
3 /* 3 /*
4 4
5 This module provides an interface to Berkeley socket IPC. 5 This module provides an interface to Berkeley socket IPC.
6 6
7 Limitations: 7 Limitations:
8 8
9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a 9 - Only AF_INET, AF_INET6 and AF_UNIX address families are supported in a
10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported 10 portable manner, though AF_PACKET, AF_NETLINK and AF_TIPC are supported
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 static int 1292 static int
1293 getsockaddrarg(PySocketSockObject *s, PyObject *args, 1293 getsockaddrarg(PySocketSockObject *s, PyObject *args,
1294 struct sockaddr *addr_ret, int *len_ret) 1294 struct sockaddr *addr_ret, int *len_ret)
1295 { 1295 {
1296 switch (s->sock_family) { 1296 switch (s->sock_family) {
1297 1297
1298 #if defined(AF_UNIX) 1298 #if defined(AF_UNIX)
1299 case AF_UNIX: 1299 case AF_UNIX:
1300 { 1300 {
1301 struct sockaddr_un* addr; 1301 struct sockaddr_un* addr;
1302 char *path; 1302 Py_buffer path;
1303 int len;
1304 int retval = 0; 1303 int retval = 0;
1305 1304
1306 /* PEP 383. Not using PyUnicode_FSConverter since we need to 1305 /* PEP 383. Not using PyUnicode_FSConverter since we need to
1307 allow embedded nulls on Linux. */ 1306 allow embedded nulls on Linux. */
1308 if (PyUnicode_Check(args)) { 1307 if (PyUnicode_Check(args)) {
1309 if ((args = PyUnicode_EncodeFSDefault(args)) == NULL) 1308 if ((args = PyUnicode_EncodeFSDefault(args)) == NULL)
1310 return 0; 1309 return 0;
1311 } 1310 }
1312 else 1311 else
1313 Py_INCREF(args); 1312 Py_INCREF(args);
1314 if (!PyArg_Parse(args, "y#", &path, &len)) 1313 if (!PyArg_Parse(args, "y*", &path)) {
1315 goto unix_out; 1314 Py_DECREF(args);
1316 assert(len >= 0); 1315 return retval;
1316 }
1317 assert(path.len >= 0);
1317 1318
1318 addr = (struct sockaddr_un*)addr_ret; 1319 addr = (struct sockaddr_un*)addr_ret;
1319 #ifdef linux 1320 #ifdef linux
1320 if (len > 0 && path[0] == 0) { 1321 if (path.len > 0 && *(const char *)path.buf == 0) {
1321 /* Linux abstract namespace extension */ 1322 /* Linux abstract namespace extension */
1322 if ((size_t)len > sizeof addr->sun_path) { 1323 if ((size_t)path.len > sizeof addr->sun_path) {
1323 PyErr_SetString(PyExc_OSError, 1324 PyErr_SetString(PyExc_OSError,
1324 "AF_UNIX path too long"); 1325 "AF_UNIX path too long");
1325 goto unix_out; 1326 goto unix_out;
1326 } 1327 }
1327 } 1328 }
1328 else 1329 else
1329 #endif /* linux */ 1330 #endif /* linux */
1330 { 1331 {
1331 /* regular NULL-terminated string */ 1332 /* regular NULL-terminated string */
1332 if ((size_t)len >= sizeof addr->sun_path) { 1333 if ((size_t)path.len >= sizeof addr->sun_path) {
1333 PyErr_SetString(PyExc_OSError, 1334 PyErr_SetString(PyExc_OSError,
1334 "AF_UNIX path too long"); 1335 "AF_UNIX path too long");
1335 goto unix_out; 1336 goto unix_out;
1336 } 1337 }
1337 addr->sun_path[len] = 0; 1338 addr->sun_path[path.len] = 0;
1338 } 1339 }
1339 addr->sun_family = s->sock_family; 1340 addr->sun_family = s->sock_family;
1340 memcpy(addr->sun_path, path, len); 1341 memcpy(addr->sun_path, path.buf, path.len);
1341 *len_ret = len + offsetof(struct sockaddr_un, sun_path); 1342 *len_ret = path.len + offsetof(struct sockaddr_un, sun_path);
1342 retval = 1; 1343 retval = 1;
1343 unix_out: 1344 unix_out:
1345 PyBuffer_Release(&path);
1344 Py_DECREF(args); 1346 Py_DECREF(args);
1345 return retval; 1347 return retval;
1346 } 1348 }
1347 #endif /* AF_UNIX */ 1349 #endif /* AF_UNIX */
1348 1350
1349 #if defined(AF_NETLINK) 1351 #if defined(AF_NETLINK)
1350 case AF_NETLINK: 1352 case AF_NETLINK:
1351 { 1353 {
1352 struct sockaddr_nl* addr; 1354 struct sockaddr_nl* addr;
1353 int pid, groups; 1355 int pid, groups;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1557
1556 #if defined(HAVE_NETPACKET_PACKET_H) && defined(SIOCGIFINDEX) 1558 #if defined(HAVE_NETPACKET_PACKET_H) && defined(SIOCGIFINDEX)
1557 case AF_PACKET: 1559 case AF_PACKET:
1558 { 1560 {
1559 struct sockaddr_ll* addr; 1561 struct sockaddr_ll* addr;
1560 struct ifreq ifr; 1562 struct ifreq ifr;
1561 char *interfaceName; 1563 char *interfaceName;
1562 int protoNumber; 1564 int protoNumber;
1563 int hatype = 0; 1565 int hatype = 0;
1564 int pkttype = 0; 1566 int pkttype = 0;
1565 char *haddr = NULL; 1567 Py_buffer haddr = {NULL, NULL};
1566 unsigned int halen = 0;
1567 1568
1568 if (!PyTuple_Check(args)) { 1569 if (!PyTuple_Check(args)) {
1569 PyErr_Format( 1570 PyErr_Format(
1570 PyExc_TypeError, 1571 PyExc_TypeError,
1571 "getsockaddrarg: " 1572 "getsockaddrarg: "
1572 "AF_PACKET address must be tuple, not %.500s", 1573 "AF_PACKET address must be tuple, not %.500s",
1573 Py_TYPE(args)->tp_name); 1574 Py_TYPE(args)->tp_name);
1574 return 0; 1575 return 0;
1575 } 1576 }
1576 if (!PyArg_ParseTuple(args, "si|iiy#", &interfaceName, 1577 if (!PyArg_ParseTuple(args, "si|iiy*", &interfaceName,
1577 &protoNumber, &pkttype, &hatype, 1578 &protoNumber, &pkttype, &hatype,
1578 &haddr, &halen)) 1579 &haddr))
1579 return 0; 1580 return 0;
1580 strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name)); 1581 strncpy(ifr.ifr_name, interfaceName, sizeof(ifr.ifr_name));
1581 ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0'; 1582 ifr.ifr_name[(sizeof(ifr.ifr_name))-1] = '\0';
1582 if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) { 1583 if (ioctl(s->sock_fd, SIOCGIFINDEX, &ifr) < 0) {
1583 s->errorhandler(); 1584 s->errorhandler();
1585 PyBuffer_Release(&haddr);
1584 return 0; 1586 return 0;
1585 } 1587 }
1586 if (halen > 8) { 1588 if (haddr.buf && haddr.len > 8) {
1587 PyErr_SetString(PyExc_ValueError, 1589 PyErr_SetString(PyExc_ValueError,
1588 "Hardware address must be 8 bytes or less"); 1590 "Hardware address must be 8 bytes or less");
1589 return 0; 1591 PyBuffer_Release(&haddr);
1592 return 0;
1590 } 1593 }
1591 if (protoNumber < 0 || protoNumber > 0xffff) { 1594 if (protoNumber < 0 || protoNumber > 0xffff) {
1592 PyErr_SetString( 1595 PyErr_SetString(
1593 PyExc_OverflowError, 1596 PyExc_OverflowError,
1594 "getsockaddrarg: protoNumber must be 0-65535."); 1597 "getsockaddrarg: protoNumber must be 0-65535.");
1598 PyBuffer_Release(&haddr);
1595 return 0; 1599 return 0;
1596 } 1600 }
1597 addr = (struct sockaddr_ll*)addr_ret; 1601 addr = (struct sockaddr_ll*)addr_ret;
1598 addr->sll_family = AF_PACKET; 1602 addr->sll_family = AF_PACKET;
1599 addr->sll_protocol = htons((short)protoNumber); 1603 addr->sll_protocol = htons((short)protoNumber);
1600 addr->sll_ifindex = ifr.ifr_ifindex; 1604 addr->sll_ifindex = ifr.ifr_ifindex;
1601 addr->sll_pkttype = pkttype; 1605 addr->sll_pkttype = pkttype;
1602 addr->sll_hatype = hatype; 1606 addr->sll_hatype = hatype;
1603 if (halen != 0) { 1607 if (haddr.buf) {
1604 memcpy(&addr->sll_addr, haddr, halen); 1608 memcpy(&addr->sll_addr, haddr.buf, haddr.len);
1609 addr->sll_halen = haddr.len;
1605 } 1610 }
1606 addr->sll_halen = halen; 1611 else
1612 addr->sll_halen = 0;
1607 *len_ret = sizeof *addr; 1613 *len_ret = sizeof *addr;
1614 PyBuffer_Release(&haddr);
1608 return 1; 1615 return 1;
1609 } 1616 }
1610 #endif 1617 #endif
1611 1618
1612 #ifdef HAVE_LINUX_TIPC_H 1619 #ifdef HAVE_LINUX_TIPC_H
1613 case AF_TIPC: 1620 case AF_TIPC:
1614 { 1621 {
1615 unsigned int atype, v1, v2, v3; 1622 unsigned int atype, v1, v2, v3;
1616 unsigned int scope = TIPC_CLUSTER_SCOPE; 1623 unsigned int scope = TIPC_CLUSTER_SCOPE;
1617 struct sockaddr_tipc *addr; 1624 struct sockaddr_tipc *addr;
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
2223 With an integer third argument, sets an integer option. 2230 With an integer third argument, sets an integer option.
2224 With a string third argument, sets an option from a buffer; 2231 With a string third argument, sets an option from a buffer;
2225 use optional built-in module 'struct' to encode the string. */ 2232 use optional built-in module 'struct' to encode the string. */
2226 2233
2227 static PyObject * 2234 static PyObject *
2228 sock_setsockopt(PySocketSockObject *s, PyObject *args) 2235 sock_setsockopt(PySocketSockObject *s, PyObject *args)
2229 { 2236 {
2230 int level; 2237 int level;
2231 int optname; 2238 int optname;
2232 int res; 2239 int res;
2233 char *buf; 2240 Py_buffer optval;
2234 int buflen;
2235 int flag; 2241 int flag;
2236 2242
2237 if (PyArg_ParseTuple(args, "iii:setsockopt", 2243 if (PyArg_ParseTuple(args, "iii:setsockopt",
2238 &level, &optname, &flag)) { 2244 &level, &optname, &flag)) {
2239 buf = (char *) &flag; 2245 res = setsockopt(s->sock_fd, level, optname, &flag, sizeof flag);
2240 buflen = sizeof flag;
2241 } 2246 }
2242 else { 2247 else {
2243 PyErr_Clear(); 2248 PyErr_Clear();
2244 if (!PyArg_ParseTuple(args, "iiy#:setsockopt", 2249 if (!PyArg_ParseTuple(args, "iiy*:setsockopt",
2245 &level, &optname, &buf, &buflen)) 2250 &level, &optname, &optval))
2246 return NULL; 2251 return NULL;
2252 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len);
2253 PyBuffer_Release(&optval);
2247 } 2254 }
2248 res = setsockopt(s->sock_fd, level, optname, (void *)buf, buflen);
2249 if (res < 0) 2255 if (res < 0)
2250 return s->errorhandler(); 2256 return s->errorhandler();
2251 Py_INCREF(Py_None); 2257 Py_INCREF(Py_None);
2252 return Py_None; 2258 return Py_None;
2253 } 2259 }
2254 2260
2255 PyDoc_STRVAR(setsockopt_doc, 2261 PyDoc_STRVAR(setsockopt_doc,
2256 "setsockopt(level, option, value)\n\ 2262 "setsockopt(level, option, value)\n\
2257 \n\ 2263 \n\
2258 Set a socket option. See the Unix manual for level and option.\n\ 2264 Set a socket option. See the Unix manual for level and option.\n\
(...skipping 2771 matching lines...) Expand 10 before | Expand all | Expand 10 after
5030 } 5036 }
5031 5037
5032 PyDoc_STRVAR(inet_ntoa_doc, 5038 PyDoc_STRVAR(inet_ntoa_doc,
5033 "inet_ntoa(packed_ip) -> ip_address_string\n\ 5039 "inet_ntoa(packed_ip) -> ip_address_string\n\
5034 \n\ 5040 \n\
5035 Convert an IP address from 32-bit packed binary format to string format"); 5041 Convert an IP address from 32-bit packed binary format to string format");
5036 5042
5037 static PyObject* 5043 static PyObject*
5038 socket_inet_ntoa(PyObject *self, PyObject *args) 5044 socket_inet_ntoa(PyObject *self, PyObject *args)
5039 { 5045 {
5040 char *packed_str; 5046 Py_buffer packed_ip;
5041 int addr_len;
5042 struct in_addr packed_addr; 5047 struct in_addr packed_addr;
5043 5048
5044 if (!PyArg_ParseTuple(args, "y#:inet_ntoa", &packed_str, &addr_len)) { 5049 if (!PyArg_ParseTuple(args, "y*:inet_ntoa", &packed_ip)) {
5045 return NULL; 5050 return NULL;
5046 } 5051 }
5047 5052
5048 if (addr_len != sizeof(packed_addr)) { 5053 if (packed_ip.len != sizeof(packed_addr)) {
5049 PyErr_SetString(PyExc_OSError, 5054 PyErr_SetString(PyExc_OSError,
5050 "packed IP wrong length for inet_ntoa"); 5055 "packed IP wrong length for inet_ntoa");
5056 PyBuffer_Release(&packed_ip);
5051 return NULL; 5057 return NULL;
5052 } 5058 }
5053 5059
5054 memcpy(&packed_addr, packed_str, addr_len); 5060 memcpy(&packed_addr, packed_ip.buf, packed_ip.len);
5061 PyBuffer_Release(&packed_ip);
5055 5062
5056 return PyUnicode_FromString(inet_ntoa(packed_addr)); 5063 return PyUnicode_FromString(inet_ntoa(packed_addr));
5057 } 5064 }
5058 5065
5059 #if defined(HAVE_INET_PTON) || defined(MS_WINDOWS) 5066 #if defined(HAVE_INET_PTON) || defined(MS_WINDOWS)
5060 5067
5061 PyDoc_STRVAR(inet_pton_doc, 5068 PyDoc_STRVAR(inet_pton_doc,
5062 "inet_pton(af, ip) -> packed IP address string\n\ 5069 "inet_pton(af, ip) -> packed IP address string\n\
5063 \n\ 5070 \n\
5064 Convert an IP address from string format to a packed string suitable\n\ 5071 Convert an IP address from string format to a packed string suitable\n\
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
5155 Convert a packed IP address of the given family to string format."); 5162 Convert a packed IP address of the given family to string format.");
5156 5163
5157 #endif 5164 #endif
5158 5165
5159 5166
5160 #ifdef HAVE_INET_PTON 5167 #ifdef HAVE_INET_PTON
5161 static PyObject * 5168 static PyObject *
5162 socket_inet_ntop(PyObject *self, PyObject *args) 5169 socket_inet_ntop(PyObject *self, PyObject *args)
5163 { 5170 {
5164 int af; 5171 int af;
5165 char* packed; 5172 Py_buffer packed_ip;
5166 int len;
5167 const char* retval; 5173 const char* retval;
5168 #ifdef ENABLE_IPV6 5174 #ifdef ENABLE_IPV6
5169 char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1]; 5175 char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
5170 #else 5176 #else
5171 char ip[INET_ADDRSTRLEN + 1]; 5177 char ip[INET_ADDRSTRLEN + 1];
5172 #endif 5178 #endif
5173 5179
5174 /* Guarantee NUL-termination for PyUnicode_FromString() below */ 5180 /* Guarantee NUL-termination for PyUnicode_FromString() below */
5175 memset((void *) &ip[0], '\0', sizeof(ip)); 5181 memset((void *) &ip[0], '\0', sizeof(ip));
5176 5182
5177 if (!PyArg_ParseTuple(args, "iy#:inet_ntop", &af, &packed, &len)) { 5183 if (!PyArg_ParseTuple(args, "iy*:inet_ntop", &af, &packed_ip)) {
5178 return NULL; 5184 return NULL;
5179 } 5185 }
5180 5186
5181 if (af == AF_INET) { 5187 if (af == AF_INET) {
5182 if (len != sizeof(struct in_addr)) { 5188 if (packed_ip.len != sizeof(struct in_addr)) {
5183 PyErr_SetString(PyExc_ValueError, 5189 PyErr_SetString(PyExc_ValueError,
5184 "invalid length of packed IP address string"); 5190 "invalid length of packed IP address string");
5191 PyBuffer_Release(&packed_ip);
5185 return NULL; 5192 return NULL;
5186 } 5193 }
5187 #ifdef ENABLE_IPV6 5194 #ifdef ENABLE_IPV6
5188 } else if (af == AF_INET6) { 5195 } else if (af == AF_INET6) {
5189 if (len != sizeof(struct in6_addr)) { 5196 if (packed_ip.len != sizeof(struct in6_addr)) {
5190 PyErr_SetString(PyExc_ValueError, 5197 PyErr_SetString(PyExc_ValueError,
5191 "invalid length of packed IP address string"); 5198 "invalid length of packed IP address string");
5199 PyBuffer_Release(&packed_ip);
5192 return NULL; 5200 return NULL;
5193 } 5201 }
5194 #endif 5202 #endif
5195 } else { 5203 } else {
5196 PyErr_Format(PyExc_ValueError, 5204 PyErr_Format(PyExc_ValueError,
5197 "unknown address family %d", af); 5205 "unknown address family %d", af);
5206 PyBuffer_Release(&packed_ip);
5198 return NULL; 5207 return NULL;
5199 } 5208 }
5200 5209
5201 retval = inet_ntop(af, packed, ip, sizeof(ip)); 5210 retval = inet_ntop(af, packed_ip.buf, ip, sizeof(ip));
5211 PyBuffer_Release(&packed_ip);
5202 if (!retval) { 5212 if (!retval) {
5203 PyErr_SetFromErrno(PyExc_OSError); 5213 PyErr_SetFromErrno(PyExc_OSError);
5204 return NULL; 5214 return NULL;
5205 } else { 5215 } else {
5206 return PyUnicode_FromString(retval); 5216 return PyUnicode_FromString(retval);
5207 } 5217 }
5208 5218
5209 /* NOTREACHED */ 5219 /* NOTREACHED */
5210 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop"); 5220 PyErr_SetString(PyExc_RuntimeError, "invalid handling of inet_ntop");
5211 return NULL; 5221 return NULL;
5212 } 5222 }
5213 5223
5214 #elif defined(MS_WINDOWS) 5224 #elif defined(MS_WINDOWS)
5215 5225
5216 static PyObject * 5226 static PyObject *
5217 socket_inet_ntop(PyObject *self, PyObject *args) 5227 socket_inet_ntop(PyObject *self, PyObject *args)
5218 { 5228 {
5219 int af; 5229 int af;
5220 char* packed; 5230 Py_buffer packed_ip;
5221 int len;
5222 struct sockaddr_in6 addr; 5231 struct sockaddr_in6 addr;
5223 DWORD addrlen, ret, retlen; 5232 DWORD addrlen, ret, retlen;
5224 #ifdef ENABLE_IPV6 5233 #ifdef ENABLE_IPV6
5225 char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1]; 5234 char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
5226 #else 5235 #else
5227 char ip[INET_ADDRSTRLEN + 1]; 5236 char ip[INET_ADDRSTRLEN + 1];
5228 #endif 5237 #endif
5229 5238
5230 /* Guarantee NUL-termination for PyUnicode_FromString() below */ 5239 /* Guarantee NUL-termination for PyUnicode_FromString() below */
5231 memset((void *) &ip[0], '\0', sizeof(ip)); 5240 memset((void *) &ip[0], '\0', sizeof(ip));
5232 5241
5233 if (!PyArg_ParseTuple(args, "iy#:inet_ntop", &af, &packed, &len)) { 5242 if (!PyArg_ParseTuple(args, "iy*:inet_ntop", &af, &packed_ip)) {
5234 return NULL; 5243 return NULL;
5235 } 5244 }
5236 5245
5237 if (af == AF_INET) { 5246 if (af == AF_INET) {
5238 struct sockaddr_in * addr4 = (struct sockaddr_in *)&addr; 5247 struct sockaddr_in * addr4 = (struct sockaddr_in *)&addr;
5239 5248
5240 if (len != sizeof(struct in_addr)) { 5249 if (packed_ip.len != sizeof(struct in_addr)) {
5241 PyErr_SetString(PyExc_ValueError, 5250 PyErr_SetString(PyExc_ValueError,
5242 "invalid length of packed IP address string"); 5251 "invalid length of packed IP address string");
5252 PyBuffer_Release(&packed_ip);
5243 return NULL; 5253 return NULL;
5244 } 5254 }
5245 memset(addr4, 0, sizeof(struct sockaddr_in)); 5255 memset(addr4, 0, sizeof(struct sockaddr_in));
5246 addr4->sin_family = AF_INET; 5256 addr4->sin_family = AF_INET;
5247 memcpy(&(addr4->sin_addr), packed, sizeof(addr4->sin_addr)); 5257 memcpy(&(addr4->sin_addr), packed_ip.buf, sizeof(addr4->sin_addr));
5248 addrlen = sizeof(struct sockaddr_in); 5258 addrlen = sizeof(struct sockaddr_in);
5249 } else if (af == AF_INET6) { 5259 } else if (af == AF_INET6) {
5250 if (len != sizeof(struct in6_addr)) { 5260 if (packed_ip.len != sizeof(struct in6_addr)) {
5251 PyErr_SetString(PyExc_ValueError, 5261 PyErr_SetString(PyExc_ValueError,
5252 "invalid length of packed IP address string"); 5262 "invalid length of packed IP address string");
5263 PyBuffer_Release(&packed_ip);
5253 return NULL; 5264 return NULL;
5254 } 5265 }
5255 5266
5256 memset(&addr, 0, sizeof(addr)); 5267 memset(&addr, 0, sizeof(addr));
5257 addr.sin6_family = AF_INET6; 5268 addr.sin6_family = AF_INET6;
5258 memcpy(&(addr.sin6_addr), packed, sizeof(addr.sin6_addr)); 5269 memcpy(&(addr.sin6_addr), packed_ip.buf, sizeof(addr.sin6_addr));
5259 addrlen = sizeof(addr); 5270 addrlen = sizeof(addr);
5260 } else { 5271 } else {
5261 PyErr_Format(PyExc_ValueError, 5272 PyErr_Format(PyExc_ValueError,
5262 "unknown address family %d", af); 5273 "unknown address family %d", af);
5274 PyBuffer_Release(&packed_ip);
5263 return NULL; 5275 return NULL;
5264 } 5276 }
5277 PyBuffer_Release(&packed_ip);
5265 5278
5266 retlen = sizeof(ip); 5279 retlen = sizeof(ip);
5267 ret = WSAAddressToStringA((struct sockaddr*)&addr, addrlen, NULL, 5280 ret = WSAAddressToStringA((struct sockaddr*)&addr, addrlen, NULL,
5268 ip, &retlen); 5281 ip, &retlen);
5269 5282
5270 if (ret) { 5283 if (ret) {
5271 PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError()); 5284 PyErr_SetExcFromWindowsErr(PyExc_OSError, WSAGetLastError());
5272 return NULL; 5285 return NULL;
5273 } else { 5286 } else {
5274 return PyUnicode_FromString(ip); 5287 return PyUnicode_FromString(ip);
(...skipping 1765 matching lines...) Expand 10 before | Expand all | Expand 10 after
7040 return NULL; 7053 return NULL;
7041 memcpy(&packed_addr, src, sizeof(packed_addr)); 7054 memcpy(&packed_addr, src, sizeof(packed_addr));
7042 return strncpy(dst, inet_ntoa(packed_addr), size); 7055 return strncpy(dst, inet_ntoa(packed_addr), size);
7043 } 7056 }
7044 /* Should set errno to EAFNOSUPPORT */ 7057 /* Should set errno to EAFNOSUPPORT */
7045 return NULL; 7058 return NULL;
7046 } 7059 }
7047 7060
7048 #endif 7061 #endif
7049 #endif 7062 #endif
OLDNEW
« Modules/fcntlmodule.c ('K') | « Modules/ossaudiodev.c ('k') | Modules/_ssl.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+