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

Side by Side Diff: Modules/socketmodule.c

Issue 27744: Add AF_ALG (Linux Kernel crypto) to socket module
Patch Set: Created 3 years, 7 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
« Lib/test/test_socket.py ('K') | « Lib/test/test_socket.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 listen([n]) -- start listening for incoming connections\n\ 129 listen([n]) -- start listening for incoming connections\n\
130 recv(buflen[, flags]) -- receive data\n\ 130 recv(buflen[, flags]) -- receive data\n\
131 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\ 131 recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n\
132 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\ 132 recvfrom(buflen[, flags]) -- receive data and sender\'s address\n\
133 recvfrom_into(buffer[, nbytes, [, flags])\n\ 133 recvfrom_into(buffer[, nbytes, [, flags])\n\
134 -- receive data and sender\'s address (into a buffer)\n\ 134 -- receive data and sender\'s address (into a buffer)\n\
135 sendall(data[, flags]) -- send all data\n\ 135 sendall(data[, flags]) -- send all data\n\
136 send(data[, flags]) -- send data, may not send all of it\n\ 136 send(data[, flags]) -- send data, may not send all of it\n\
137 sendto(data[, flags], addr) -- send data to a given address\n\ 137 sendto(data[, flags], addr) -- send data to a given address\n\
138 setblocking(0 | 1) -- set or clear the blocking I/O flag\n\ 138 setblocking(0 | 1) -- set or clear the blocking I/O flag\n\
139 setsockopt(level, optname, value) -- set socket options\n\ 139 setsockopt(level, optname, value[, optlen]) -- set socket options\n\
140 settimeout(None | float) -- set or clear the timeout\n\ 140 settimeout(None | float) -- set or clear the timeout\n\
141 shutdown(how) -- shut down traffic in one or both directions\n\ 141 shutdown(how) -- shut down traffic in one or both directions\n\
142 if_nameindex() -- return all network interface indices and names\n\ 142 if_nameindex() -- return all network interface indices and names\n\
143 if_nametoindex(name) -- return the corresponding interface index\n\ 143 if_nametoindex(name) -- return the corresponding interface index\n\
144 if_indextoname(index) -- return the corresponding interface name\n\ 144 if_indextoname(index) -- return the corresponding interface name\n\
145 \n\ 145 \n\
146 [*] not available on all platforms!"); 146 [*] not available on all platforms!");
147 147
148 /* XXX This is a terrible mess of platform-dependent preprocessor hacks. 148 /* XXX This is a terrible mess of platform-dependent preprocessor hacks.
149 I hope some day someone can clean this up please... */ 149 I hope some day someone can clean this up please... */
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 #include <sys/types.h> 278 #include <sys/types.h>
279 #endif 279 #endif
280 280
281 #ifdef HAVE_SYS_SOCKET_H 281 #ifdef HAVE_SYS_SOCKET_H
282 #include <sys/socket.h> 282 #include <sys/socket.h>
283 #endif 283 #endif
284 284
285 #ifdef HAVE_NET_IF_H 285 #ifdef HAVE_NET_IF_H
286 #include <net/if.h> 286 #include <net/if.h>
287 #endif 287 #endif
288
289 #ifdef HAVE_SOCKADDR_ALG
290 #include <linux/if_alg.h>
291 #ifndef AF_ALG
292 #define AF_ALG 38
293 #endif
294 #ifndef SOL_ALG
295 #define SOL_ALG 279
296 #endif
297
298 /* Linux 3.19 */
299 #ifndef ALG_SET_AEAD_ASSOCLEN
300 #define ALG_SET_AEAD_ASSOCLEN 4
301 #endif
302 #ifndef ALG_SET_AEAD_AUTHSIZE
303 #define ALG_SET_AEAD_AUTHSIZE 5
304 #endif
305 /* Linux 4.8 */
306 #ifndef ALG_SET_PUBKEY
307 #define ALG_SET_PUBKEY 6
308 #endif
309
310 #ifndef ALG_OP_SIGN
311 #define ALG_OP_SIGN 2
312 #endif
313 #ifndef ALG_OP_VERIFY
314 #define ALG_OP_VERIFY 3
315 #endif
316
317 #endif /* HAVE_SOCKADDR_ALG */
288 318
289 /* Generic socket object definitions and includes */ 319 /* Generic socket object definitions and includes */
290 #define PySocket_BUILDING_SOCKET 320 #define PySocket_BUILDING_SOCKET
291 #include "socketmodule.h" 321 #include "socketmodule.h"
292 322
293 /* Addressing includes */ 323 /* Addressing includes */
294 324
295 #ifndef MS_WINDOWS 325 #ifndef MS_WINDOWS
296 326
297 /* Non-MS WINDOWS includes */ 327 /* Non-MS WINDOWS includes */
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 { 1396 {
1367 struct sockaddr_ctl *a = (struct sockaddr_ctl *)addr; 1397 struct sockaddr_ctl *a = (struct sockaddr_ctl *)addr;
1368 return Py_BuildValue("(II)", a->sc_id, a->sc_unit); 1398 return Py_BuildValue("(II)", a->sc_id, a->sc_unit);
1369 } 1399 }
1370 #endif 1400 #endif
1371 default: 1401 default:
1372 PyErr_SetString(PyExc_ValueError, 1402 PyErr_SetString(PyExc_ValueError,
1373 "Invalid address type"); 1403 "Invalid address type");
1374 return 0; 1404 return 0;
1375 } 1405 }
1406 #endif
1407
1408 #ifdef HAVE_SOCKADDR_ALG
1409 case AF_ALG:
1410 {
1411 struct sockaddr_alg *a = (struct sockaddr_alg *)addr;
1412 return Py_BuildValue("s#s#HH",
1413 a->salg_type,
1414 strnlen((const char*)a->salg_type,
1415 sizeof(a->salg_type)),
1416 a->salg_name,
1417 strnlen((const char*)a->salg_name,
1418 sizeof(a->salg_name)),
1419 a->salg_feat,
1420 a->salg_mask);
1421 }
1376 #endif 1422 #endif
1377 1423
1378 /* More cases here... */ 1424 /* More cases here... */
1379 1425
1380 default: 1426 default:
1381 /* If we don't know the address family, don't raise an 1427 /* If we don't know the address family, don't raise an
1382 exception -- return it as an (int, bytes) tuple. */ 1428 exception -- return it as an (int, bytes) tuple. */
1383 return Py_BuildValue("iy#", 1429 return Py_BuildValue("iy#",
1384 addr->sa_family, 1430 addr->sa_family,
1385 addr->sa_data, 1431 addr->sa_data,
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 1978
1933 *len_ret = sizeof(*addr); 1979 *len_ret = sizeof(*addr);
1934 return 1; 1980 return 1;
1935 } 1981 }
1936 #endif 1982 #endif
1937 default: 1983 default:
1938 PyErr_SetString(PyExc_OSError, 1984 PyErr_SetString(PyExc_OSError,
1939 "getsockaddrarg: unsupported PF_SYSTEM protocol"); 1985 "getsockaddrarg: unsupported PF_SYSTEM protocol");
1940 return 0; 1986 return 0;
1941 } 1987 }
1988 #endif
1989 #ifdef HAVE_SOCKADDR_ALG
1990 case AF_ALG:
1991 {
1992 struct sockaddr_alg *sa;
1993 char *type;
1994 char *name;
1995 sa = (struct sockaddr_alg *)addr_ret;
1996
1997 memset(sa, 0, sizeof(*sa));
1998 sa->salg_family = AF_ALG;
1999
2000 if (!PyArg_ParseTuple(args, "ss|HH:getsockaddrarg",
2001 &type, &name, &sa->salg_feat, &sa->salg_mask))
2002 return 0;
2003 /* sockaddr_alg has fixed-sized char arrays for type and name */
2004 if (strlen(type) > sizeof(sa->salg_type)) {
2005 PyErr_SetString(PyExc_ValueError, "AF_ALG type too long.");
2006 return 0;
2007 }
2008 strncpy((char *)sa->salg_type, type, sizeof(sa->salg_type));
2009 if (strlen(name) > sizeof(sa->salg_name)) {
2010 PyErr_SetString(PyExc_ValueError, "AF_ALG name too long.");
2011 return 0;
2012 }
2013 strncpy((char *)sa->salg_name, name, sizeof(sa->salg_name));
2014
2015 *len_ret = sizeof(*sa);
2016 return 1;
2017 }
1942 #endif 2018 #endif
1943 2019
1944 /* More cases here... */ 2020 /* More cases here... */
1945 2021
1946 default: 2022 default:
1947 PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family"); 2023 PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family");
1948 return 0; 2024 return 0;
1949 2025
1950 } 2026 }
1951 } 2027 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 #ifdef SYSPROTO_CONTROL 2129 #ifdef SYSPROTO_CONTROL
2054 case SYSPROTO_CONTROL: 2130 case SYSPROTO_CONTROL:
2055 *len_ret = sizeof (struct sockaddr_ctl); 2131 *len_ret = sizeof (struct sockaddr_ctl);
2056 return 1; 2132 return 1;
2057 #endif 2133 #endif
2058 default: 2134 default:
2059 PyErr_SetString(PyExc_OSError, "getsockaddrlen: " 2135 PyErr_SetString(PyExc_OSError, "getsockaddrlen: "
2060 "unknown PF_SYSTEM protocol"); 2136 "unknown PF_SYSTEM protocol");
2061 return 0; 2137 return 0;
2062 } 2138 }
2139 #endif
2140 #ifdef HAVE_SOCKADDR_ALG
2141 case AF_ALG:
2142 {
2143 *len_ret = sizeof (struct sockaddr_alg);
2144 return 1;
2145 }
2063 #endif 2146 #endif
2064 2147
2065 /* More cases here... */ 2148 /* More cases here... */
2066 2149
2067 default: 2150 default:
2068 PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family"); 2151 PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family");
2069 return 0; 2152 return 0;
2070 2153
2071 } 2154 }
2072 } 2155 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 2296
2214 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) 2297 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
2215 /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */ 2298 /* accept4() is available on Linux 2.6.28+ and glibc 2.10 */
2216 static int accept4_works = -1; 2299 static int accept4_works = -1;
2217 #endif 2300 #endif
2218 2301
2219 static int 2302 static int
2220 sock_accept_impl(PySocketSockObject *s, void *data) 2303 sock_accept_impl(PySocketSockObject *s, void *data)
2221 { 2304 {
2222 struct sock_accept *ctx = data; 2305 struct sock_accept *ctx = data;
2306 struct sockaddr *addr = SAS2SA(ctx->addrbuf);
2307 socklen_t *paddrlen = ctx->addrlen;
2308 #ifdef HAVE_SOCKADDR_ALG
2309 /* AF_ALG does not support accept() with addr and raises
2310 * ECONNABORTED instead. */
2311 if (s->sock_family == AF_ALG) {
2312 addr = NULL;
2313 paddrlen = NULL;
2314 *ctx->addrlen = 0;
2315 }
2316 #endif
2223 2317
2224 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) 2318 #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
2225 if (accept4_works != 0) { 2319 if (accept4_works != 0) {
2226 ctx->result = accept4(s->sock_fd, SAS2SA(ctx->addrbuf), ctx->addrlen, 2320 ctx->result = accept4(s->sock_fd, addr, paddrlen,
2227 SOCK_CLOEXEC); 2321 SOCK_CLOEXEC);
2228 if (ctx->result == INVALID_SOCKET && accept4_works == -1) { 2322 if (ctx->result == INVALID_SOCKET && accept4_works == -1) {
2229 /* On Linux older than 2.6.28, accept4() fails with ENOSYS */ 2323 /* On Linux older than 2.6.28, accept4() fails with ENOSYS */
2230 accept4_works = (errno != ENOSYS); 2324 accept4_works = (errno != ENOSYS);
2231 } 2325 }
2232 } 2326 }
2233 if (accept4_works == 0) 2327 if (accept4_works == 0)
2234 ctx->result = accept(s->sock_fd, SAS2SA(ctx->addrbuf), ctx->addrlen); 2328 ctx->result = accept(s->sock_fd, addr, paddrlen);
2235 #else 2329 #else
2236 ctx->result = accept(s->sock_fd, SAS2SA(ctx->addrbuf), ctx->addrlen); 2330 ctx->result = accept(s->sock_fd, addr, paddrlen);
2237 #endif 2331 #endif
2238 2332
2239 #ifdef MS_WINDOWS 2333 #ifdef MS_WINDOWS
2240 return (ctx->result != INVALID_SOCKET); 2334 return (ctx->result != INVALID_SOCKET);
2241 #else 2335 #else
2242 return (ctx->result >= 0); 2336 return (ctx->result >= 0);
2243 #endif 2337 #endif
2244 } 2338 }
2245 2339
2246 /* s._accept() -> (fd, address) */ 2340 /* s._accept() -> (fd, address) */
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2428 } 2522 }
2429 2523
2430 PyDoc_STRVAR(gettimeout_doc, 2524 PyDoc_STRVAR(gettimeout_doc,
2431 "gettimeout() -> timeout\n\ 2525 "gettimeout() -> timeout\n\
2432 \n\ 2526 \n\
2433 Returns the timeout in seconds (float) associated with socket \n\ 2527 Returns the timeout in seconds (float) associated with socket \n\
2434 operations. A timeout of None indicates that timeouts on socket \n\ 2528 operations. A timeout of None indicates that timeouts on socket \n\
2435 operations are disabled."); 2529 operations are disabled.");
2436 2530
2437 /* s.setsockopt() method. 2531 /* s.setsockopt() method.
2438 With an integer third argument, sets an integer option. 2532 With an integer third argument, sets an integer optval with optlen=4.
2533 With None as third argument and an integer fourth argument, set
2534 optval=NULL with unsigned int as optlen.
2439 With a string third argument, sets an option from a buffer; 2535 With a string third argument, sets an option from a buffer;
2440 use optional built-in module 'struct' to encode the string. */ 2536 use optional built-in module 'struct' to encode the string.
2537 */
2441 2538
2442 static PyObject * 2539 static PyObject *
2443 sock_setsockopt(PySocketSockObject *s, PyObject *args) 2540 sock_setsockopt(PySocketSockObject *s, PyObject *args)
2444 { 2541 {
2445 int level; 2542 int level;
2446 int optname; 2543 int optname;
2447 int res; 2544 int res;
2448 Py_buffer optval; 2545 Py_buffer optval;
2449 int flag; 2546 int flag;
2547 unsigned int optlen;
haypo 2016/09/01 23:10:30 Oh, thanks for fixing optlen type ;-)
2548 PyObject *none;
2450 2549
2550 /* setsockopt(level, opt, flag) */
2451 if (PyArg_ParseTuple(args, "iii:setsockopt", 2551 if (PyArg_ParseTuple(args, "iii:setsockopt",
2452 &level, &optname, &flag)) { 2552 &level, &optname, &flag)) {
2453 res = setsockopt(s->sock_fd, level, optname, 2553 res = setsockopt(s->sock_fd, level, optname,
2454 (char*)&flag, sizeof flag); 2554 (char*)&flag, sizeof flag);
2555 goto done;
2455 } 2556 }
2456 else { 2557
2457 PyErr_Clear(); 2558 PyErr_Clear();
2458 if (!PyArg_ParseTuple(args, "iiy*:setsockopt", 2559 /* setsockopt(level, opt, (None, flag)) */
haypo 2016/09/01 23:10:30 The comment is still outdated, no?
2459 &level, &optname, &optval)) 2560 if (PyArg_ParseTuple(args, "iiO!I:setsockopt",
2460 return NULL; 2561 &level, &optname, Py_TYPE(Py_None), &none, &optlen)) {
2562 assert(sizeof(socklen_t) >= sizeof(unsigned int));
2563 res = setsockopt(s->sock_fd, level, optname,
2564 NULL, (socklen_t)optlen);
2565 goto done;
2566 }
2567
2568 PyErr_Clear();
2569 /* setsockopt(level, opt, buffer) */
2570 if (!PyArg_ParseTuple(args, "iiy*:setsockopt",
2571 &level, &optname, &optval))
2572 return NULL;
2573
2461 #ifdef MS_WINDOWS 2574 #ifdef MS_WINDOWS
2462 if (optval.len > INT_MAX) { 2575 if (optval.len > INT_MAX) {
2463 PyBuffer_Release(&optval); 2576 PyBuffer_Release(&optval);
2464 PyErr_Format(PyExc_OverflowError, 2577 PyErr_Format(PyExc_OverflowError,
2465 "socket option is larger than %i bytes", 2578 "socket option is larger than %i bytes",
2466 INT_MAX); 2579 INT_MAX);
2467 return NULL; 2580 return NULL;
2468 } 2581 }
2469 res = setsockopt(s->sock_fd, level, optname, 2582 res = setsockopt(s->sock_fd, level, optname,
2470 optval.buf, (int)optval.len); 2583 optval.buf, (int)optval.len);
2471 #else 2584 #else
2472 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len); 2585 res = setsockopt(s->sock_fd, level, optname, optval.buf, optval.len);
2473 #endif 2586 #endif
2474 PyBuffer_Release(&optval); 2587 PyBuffer_Release(&optval);
2475 } 2588
2589 done:
2476 if (res < 0) { 2590 if (res < 0) {
2477 return s->errorhandler(); 2591 return s->errorhandler();
2478 } 2592 }
2479 2593
2480 Py_RETURN_NONE; 2594 Py_RETURN_NONE;
2481 } 2595 }
2482 2596
2483 PyDoc_STRVAR(setsockopt_doc, 2597 PyDoc_STRVAR(setsockopt_doc,
2484 "setsockopt(level, option, value)\n\ 2598 "setsockopt(level, option, value: int)\n\
2599 setsockopt(level, option, value: buffer)\n\
2600 setsockopt(level, option, None, optlen: int)\n\
2485 \n\ 2601 \n\
2486 Set a socket option. See the Unix manual for level and option.\n\ 2602 Set a socket option. See the Unix manual for level and option.\n\
2487 The value argument can either be an integer or a string."); 2603 The value argument can either be an integer, a string buffer, or \n\
2604 None, optlen.");
2488 2605
2489 2606
2490 /* s.getsockopt() method. 2607 /* s.getsockopt() method.
2491 With two arguments, retrieves an integer option. 2608 With two arguments, retrieves an integer option.
2492 With a third integer argument, retrieves a string buffer of that size; 2609 With a third integer argument, retrieves a string buffer of that size;
2493 use optional built-in module 'struct' to decode the string. */ 2610 use optional built-in module 'struct' to decode the string. */
2494 2611
2495 static PyObject * 2612 static PyObject *
2496 sock_getsockopt(PySocketSockObject *s, PyObject *args) 2613 sock_getsockopt(PySocketSockObject *s, PyObject *args)
2497 { 2614 {
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after
3765 3882
3766 3883
3767 /* The sendmsg() and recvmsg[_into]() methods require a working 3884 /* The sendmsg() and recvmsg[_into]() methods require a working
3768 CMSG_LEN(). See the comment near get_CMSG_LEN(). */ 3885 CMSG_LEN(). See the comment near get_CMSG_LEN(). */
3769 #ifdef CMSG_LEN 3886 #ifdef CMSG_LEN
3770 struct sock_sendmsg { 3887 struct sock_sendmsg {
3771 struct msghdr *msg; 3888 struct msghdr *msg;
3772 int flags; 3889 int flags;
3773 ssize_t result; 3890 ssize_t result;
3774 }; 3891 };
3892
3893 static int
3894 sock_sendmsg_iovec(PySocketSockObject *s, PyObject *data_arg,
3895 struct msghdr *msg,
3896 Py_buffer **databufsout, Py_ssize_t *ndatabufsout) {
3897 Py_ssize_t ndataparts, ndatabufs = 0;
3898 int result = -1;
3899 struct iovec *iovs = NULL;
3900 PyObject *data_fast = NULL;
3901 Py_buffer *databufs = NULL;
3902
3903 /* Fill in an iovec for each message part, and save the Py_buffer
3904 structs to release afterwards. */
3905 if ((data_fast = PySequence_Fast(data_arg,
3906 "sendmsg() argument 1 must be an "
3907 "iterable")) == NULL)
3908 goto finally;
3909 ndataparts = PySequence_Fast_GET_SIZE(data_fast);
3910 if (ndataparts > INT_MAX) {
3911 PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long");
3912 goto finally;
3913 }
3914 msg->msg_iovlen = ndataparts;
3915 if (ndataparts > 0 &&
3916 ((msg->msg_iov = iovs = PyMem_New(struct iovec, ndataparts)) == NULL ||
3917 (databufs = PyMem_New(Py_buffer, ndataparts)) == NULL)) {
3918 PyErr_NoMemory();
3919 goto finally;
3920 }
3921 for (; ndatabufs < ndataparts; ndatabufs++) {
3922 if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
3923 "y*;sendmsg() argument 1 must be an iterable of "
3924 "bytes-like objects",
3925 &databufs[ndatabufs]))
3926 goto finally;
3927 iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
3928 iovs[ndatabufs].iov_len = databufs[ndatabufs].len;
3929 }
3930 result = 0;
3931 finally:
3932 *databufsout = databufs;
3933 *ndatabufsout = ndatabufs;
3934 Py_XDECREF(data_fast);
3935 return result;
3936 }
3775 3937
3776 static int 3938 static int
3777 sock_sendmsg_impl(PySocketSockObject *s, void *data) 3939 sock_sendmsg_impl(PySocketSockObject *s, void *data)
3778 { 3940 {
3779 struct sock_sendmsg *ctx = data; 3941 struct sock_sendmsg *ctx = data;
3780 3942
3781 ctx->result = sendmsg(s->sock_fd, ctx->msg, ctx->flags); 3943 ctx->result = sendmsg(s->sock_fd, ctx->msg, ctx->flags);
3782 return (ctx->result >= 0); 3944 return (ctx->result >= 0);
3783 } 3945 }
3784 3946
3785 /* s.sendmsg(buffers[, ancdata[, flags[, address]]]) method */ 3947 /* s.sendmsg(buffers[, ancdata[, flags[, address]]]) method */
3786 3948
3787 static PyObject * 3949 static PyObject *
3788 sock_sendmsg(PySocketSockObject *s, PyObject *args) 3950 sock_sendmsg(PySocketSockObject *s, PyObject *args)
3789 { 3951 {
3790 Py_ssize_t i, ndataparts, ndatabufs = 0, ncmsgs, ncmsgbufs = 0; 3952 Py_ssize_t i, ndatabufs = 0, ncmsgs, ncmsgbufs = 0;
3791 Py_buffer *databufs = NULL; 3953 Py_buffer *databufs = NULL;
3792 struct iovec *iovs = NULL;
3793 sock_addr_t addrbuf; 3954 sock_addr_t addrbuf;
3794 struct msghdr msg = {0}; 3955 struct msghdr msg = {0};
3795 struct cmsginfo { 3956 struct cmsginfo {
3796 int level; 3957 int level;
3797 int type; 3958 int type;
3798 Py_buffer data; 3959 Py_buffer data;
3799 } *cmsgs = NULL; 3960 } *cmsgs = NULL;
3800 void *controlbuf = NULL; 3961 void *controlbuf = NULL;
3801 size_t controllen, controllen_last; 3962 size_t controllen, controllen_last;
3802 int addrlen, flags = 0; 3963 int addrlen, flags = 0;
3803 PyObject *data_arg, *cmsg_arg = NULL, *addr_arg = NULL, *data_fast = NULL, 3964 PyObject *data_arg, *cmsg_arg = NULL, *addr_arg = NULL,
3804 *cmsg_fast = NULL, *retval = NULL; 3965 *cmsg_fast = NULL, *retval = NULL;
3805 struct sock_sendmsg ctx; 3966 struct sock_sendmsg ctx;
3806 3967
3807 if (!PyArg_ParseTuple(args, "O|OiO:sendmsg", 3968 if (!PyArg_ParseTuple(args, "O|OiO:sendmsg",
3808 &data_arg, &cmsg_arg, &flags, &addr_arg)) 3969 &data_arg, &cmsg_arg, &flags, &addr_arg))
3809 return NULL; 3970 return NULL;
3810 3971
3811 /* Parse destination address. */ 3972 /* Parse destination address. */
3812 if (addr_arg != NULL && addr_arg != Py_None) { 3973 if (addr_arg != NULL && addr_arg != Py_None) {
3813 if (!getsockaddrarg(s, addr_arg, SAS2SA(&addrbuf), &addrlen)) 3974 if (!getsockaddrarg(s, addr_arg, SAS2SA(&addrbuf), &addrlen))
3814 goto finally; 3975 goto finally;
3815 msg.msg_name = &addrbuf; 3976 msg.msg_name = &addrbuf;
3816 msg.msg_namelen = addrlen; 3977 msg.msg_namelen = addrlen;
3817 } 3978 }
3818 3979
3819 /* Fill in an iovec for each message part, and save the Py_buffer 3980 /* Fill in an iovec for each message part, and save the Py_buffer
3820 structs to release afterwards. */ 3981 structs to release afterwards. */
3821 if ((data_fast = PySequence_Fast(data_arg, 3982 if (sock_sendmsg_iovec(s, data_arg, &msg, &databufs, &ndatabufs) == -1) {
3822 "sendmsg() argument 1 must be an "
3823 "iterable")) == NULL)
3824 goto finally; 3983 goto finally;
3825 ndataparts = PySequence_Fast_GET_SIZE(data_fast);
3826 if (ndataparts > INT_MAX) {
3827 PyErr_SetString(PyExc_OSError, "sendmsg() argument 1 is too long");
3828 goto finally;
3829 }
3830 msg.msg_iovlen = ndataparts;
3831 if (ndataparts > 0 &&
3832 ((msg.msg_iov = iovs = PyMem_New(struct iovec, ndataparts)) == NULL ||
3833 (databufs = PyMem_New(Py_buffer, ndataparts)) == NULL)) {
3834 PyErr_NoMemory();
3835 goto finally;
3836 }
3837 for (; ndatabufs < ndataparts; ndatabufs++) {
3838 if (!PyArg_Parse(PySequence_Fast_GET_ITEM(data_fast, ndatabufs),
3839 "y*;sendmsg() argument 1 must be an iterable of "
3840 "bytes-like objects",
3841 &databufs[ndatabufs]))
3842 goto finally;
3843 iovs[ndatabufs].iov_base = databufs[ndatabufs].buf;
3844 iovs[ndatabufs].iov_len = databufs[ndatabufs].len;
3845 } 3984 }
3846 3985
3847 if (cmsg_arg == NULL) 3986 if (cmsg_arg == NULL)
3848 ncmsgs = 0; 3987 ncmsgs = 0;
3849 else { 3988 else {
3850 if ((cmsg_fast = PySequence_Fast(cmsg_arg, 3989 if ((cmsg_fast = PySequence_Fast(cmsg_arg,
3851 "sendmsg() argument 2 must be an " 3990 "sendmsg() argument 2 must be an "
3852 "iterable")) == NULL) 3991 "iterable")) == NULL)
3853 goto finally; 3992 goto finally;
3854 ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast); 3993 ncmsgs = PySequence_Fast_GET_SIZE(cmsg_fast);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 4104
3966 finally: 4105 finally:
3967 PyMem_Free(controlbuf); 4106 PyMem_Free(controlbuf);
3968 for (i = 0; i < ncmsgbufs; i++) 4107 for (i = 0; i < ncmsgbufs; i++)
3969 PyBuffer_Release(&cmsgs[i].data); 4108 PyBuffer_Release(&cmsgs[i].data);
3970 PyMem_Free(cmsgs); 4109 PyMem_Free(cmsgs);
3971 Py_XDECREF(cmsg_fast); 4110 Py_XDECREF(cmsg_fast);
3972 for (i = 0; i < ndatabufs; i++) 4111 for (i = 0; i < ndatabufs; i++)
3973 PyBuffer_Release(&databufs[i]); 4112 PyBuffer_Release(&databufs[i]);
3974 PyMem_Free(databufs); 4113 PyMem_Free(databufs);
3975 PyMem_Free(iovs);
3976 Py_XDECREF(data_fast);
3977 return retval; 4114 return retval;
3978 } 4115 }
3979 4116
3980 PyDoc_STRVAR(sendmsg_doc, 4117 PyDoc_STRVAR(sendmsg_doc,
3981 "sendmsg(buffers[, ancdata[, flags[, address]]]) -> count\n\ 4118 "sendmsg(buffers[, ancdata[, flags[, address]]]) -> count\n\
3982 \n\ 4119 \n\
3983 Send normal and ancillary data to the socket, gathering the\n\ 4120 Send normal and ancillary data to the socket, gathering the\n\
3984 non-ancillary data from a series of buffers and concatenating it into\n\ 4121 non-ancillary data from a series of buffers and concatenating it into\n\
3985 a single message. The buffers argument specifies the non-ancillary\n\ 4122 a single message. The buffers argument specifies the non-ancillary\n\
3986 data as an iterable of bytes-like objects (e.g. bytes objects).\n\ 4123 data as an iterable of bytes-like objects (e.g. bytes objects).\n\
3987 The ancdata argument specifies the ancillary data (control messages)\n\ 4124 The ancdata argument specifies the ancillary data (control messages)\n\
3988 as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\ 4125 as an iterable of zero or more tuples (cmsg_level, cmsg_type,\n\
3989 cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\ 4126 cmsg_data), where cmsg_level and cmsg_type are integers specifying the\n\
3990 protocol level and protocol-specific type respectively, and cmsg_data\n\ 4127 protocol level and protocol-specific type respectively, and cmsg_data\n\
3991 is a bytes-like object holding the associated data. The flags\n\ 4128 is a bytes-like object holding the associated data. The flags\n\
3992 argument defaults to 0 and has the same meaning as for send(). If\n\ 4129 argument defaults to 0 and has the same meaning as for send(). If\n\
3993 address is supplied and not None, it sets a destination address for\n\ 4130 address is supplied and not None, it sets a destination address for\n\
3994 the message. The return value is the number of bytes of non-ancillary\n\ 4131 the message. The return value is the number of bytes of non-ancillary\n\
3995 data sent."); 4132 data sent.");
3996 #endif /* CMSG_LEN */ 4133 #endif /* CMSG_LEN */
3997 4134
4135 #ifdef HAVE_SOCKADDR_ALG
4136 static PyObject*
4137 sock_sendmsg_afalg(PySocketSockObject *self, PyObject *args, PyObject *kwds)
4138 {
4139 PyObject *retval = NULL;
4140
4141 Py_ssize_t i, ndatabufs = 0;
4142 Py_buffer *databufs = NULL;
4143 PyObject *data_arg = NULL;
4144
4145 Py_buffer iv = {NULL, NULL};
4146
4147 PyObject *opobj = NULL;
4148 int op = -1;
4149
4150 PyObject *assoclenobj = NULL;
4151 int assoclen = -1;
4152
4153 unsigned int *uiptr;
4154 int flags = 0;
4155
4156 struct msghdr msg;
4157 struct cmsghdr *header = NULL;
4158 struct af_alg_iv *alg_iv = NULL;
4159 struct sock_sendmsg ctx;
4160 Py_ssize_t controllen;
4161 void *controlbuf = NULL;
4162 static char *keywords[] = {"msg", "op", "iv", "assoclen", "flags", 0};
4163
4164 if (self->sock_family != AF_ALG) {
4165 PyErr_SetString(PyExc_OSError,
4166 "algset is only supported for AF_ALG");
4167 return NULL;
4168 }
4169
4170 if (!PyArg_ParseTupleAndKeywords(args, kwds,
4171 "|O$O!y*O!i:sendmsg_afalg", keywords,
4172 &data_arg,
4173 &PyLong_Type, &opobj, &iv,
4174 &PyLong_Type, &assoclenobj, &flags))
4175 return NULL;
4176
4177 /* op is a required, keyword-only argument >= 0 */
4178 if (opobj != NULL) {
4179 op = _PyLong_AsInt(opobj);
4180 }
4181 if (op < 0) {
4182 /* override exception from _PyLong_AsInt() */
4183 PyErr_SetString(PyExc_TypeError,
4184 "Invalid or missing argument 'op'");
4185 goto finally;
4186 }
4187 /* assoclen is optional but must be >= 0 */
4188 if (assoclenobj != NULL) {
4189 assoclen = _PyLong_AsInt(assoclenobj);
4190 if (assoclen == -1 && PyErr_Occurred()) {
4191 goto finally;
4192 }
4193 if (assoclen < 0) {
4194 PyErr_SetString(PyExc_TypeError,
4195 "assoclen must be positive");
4196 goto finally;
4197 }
4198 }
4199
4200 controllen = CMSG_SPACE(4);
4201 if (iv.buf != NULL) {
4202 controllen += CMSG_SPACE(sizeof(*alg_iv) + iv.len);
4203 }
4204 if (assoclen >= 0) {
4205 controllen += CMSG_SPACE(4);
4206 }
4207
4208 controlbuf = PyMem_Malloc(controllen);
4209 if (controlbuf == NULL) {
4210 return PyErr_NoMemory();
4211 }
4212 memset(controlbuf, 0, controllen);
4213
4214 memset(&msg, 0, sizeof(msg));
4215 msg.msg_controllen = controllen;
4216 msg.msg_control = controlbuf;
4217
4218 /* Fill in an iovec for each message part, and save the Py_buffer
4219 structs to release afterwards. */
4220 if (data_arg != NULL) {
4221 if (sock_sendmsg_iovec(self, data_arg, &msg, &databufs, &ndatabufs) == - 1) {
4222 goto finally;
4223 }
4224 }
4225
4226 /* set operation to encrypt or decrypt */
4227 header = CMSG_FIRSTHDR(&msg);
4228 if (header == NULL) {
4229 PyErr_SetString(PyExc_RuntimeError,
4230 "unexpected NULL result from CMSG_FIRSTHDR");
4231 goto finally;
4232 }
4233 header->cmsg_level = SOL_ALG;
4234 header->cmsg_type = ALG_SET_OP;
4235 header->cmsg_len = CMSG_LEN(4);
4236 uiptr = (void*)CMSG_DATA(header);
4237 *uiptr = (unsigned int)op;
4238
4239 /* set initialization vector */
4240 if (iv.buf != NULL) {
4241 header = CMSG_NXTHDR(&msg, header);
4242 if (header == NULL) {
4243 PyErr_SetString(PyExc_RuntimeError,
4244 "unexpected NULL result from CMSG_NXTHDR(iv)");
4245 goto finally;
4246 }
4247 header->cmsg_level = SOL_ALG;
4248 header->cmsg_type = ALG_SET_IV;
4249 header->cmsg_len = CMSG_SPACE(sizeof(*alg_iv) + iv.len);
4250 alg_iv = (void*)CMSG_DATA(header);
4251 alg_iv->ivlen = iv.len;
4252 memcpy(alg_iv->iv, iv.buf, iv.len);
4253 }
4254
4255 /* set length of associated data for AEAD */
4256 if (assoclen >= 0) {
4257 header = CMSG_NXTHDR(&msg, header);
4258 if (header == NULL) {
4259 PyErr_SetString(PyExc_RuntimeError,
4260 "unexpected NULL result from CMSG_NXTHDR(assoc)");
4261 goto finally;
4262 }
4263 header->cmsg_level = SOL_ALG;
4264 header->cmsg_type = ALG_SET_AEAD_ASSOCLEN;
4265 header->cmsg_len = CMSG_LEN(4);
4266 uiptr = (void*)CMSG_DATA(header);
4267 *uiptr = (unsigned int)assoclen;
4268 }
4269
4270 ctx.msg = &msg;
4271 ctx.flags = flags;
4272 if (sock_call(self, 1, sock_sendmsg_impl, &ctx) < 0)
4273 goto finally;
4274
4275 retval = PyLong_FromSsize_t(ctx.result);
4276
4277 finally:
4278 PyMem_Free(controlbuf);
4279 if (iv.buf != NULL) {
4280 PyBuffer_Release(&iv);
4281 }
4282 for (i = 0; i < ndatabufs; i++)
4283 PyBuffer_Release(&databufs[i]);
4284 PyMem_Free(databufs);
4285 return retval;
4286 }
4287
4288 PyDoc_STRVAR(sendmsg_afalg_doc,
4289 "sendmsg_afalg([msg], *, op[, iv[, assoclen[, flags=MSG_MORE]]])\n\
4290 \n\
4291 Set operation mode, IV and length of associated data for an AF_ALG\n\
4292 operation socket.");
4293 #endif
3998 4294
3999 /* s.shutdown(how) method */ 4295 /* s.shutdown(how) method */
4000 4296
4001 static PyObject * 4297 static PyObject *
4002 sock_shutdown(PySocketSockObject *s, PyObject *arg) 4298 sock_shutdown(PySocketSockObject *s, PyObject *arg)
4003 { 4299 {
4004 int how; 4300 int how;
4005 int res; 4301 int res;
4006 4302
4007 how = _PyLong_AsInt(arg); 4303 how = _PyLong_AsInt(arg);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 setsockopt_doc}, 4462 setsockopt_doc},
4167 {"shutdown", (PyCFunction)sock_shutdown, METH_O, 4463 {"shutdown", (PyCFunction)sock_shutdown, METH_O,
4168 shutdown_doc}, 4464 shutdown_doc},
4169 #ifdef CMSG_LEN 4465 #ifdef CMSG_LEN
4170 {"recvmsg", (PyCFunction)sock_recvmsg, METH_VARARGS, 4466 {"recvmsg", (PyCFunction)sock_recvmsg, METH_VARARGS,
4171 recvmsg_doc}, 4467 recvmsg_doc},
4172 {"recvmsg_into", (PyCFunction)sock_recvmsg_into, METH_VARARGS, 4468 {"recvmsg_into", (PyCFunction)sock_recvmsg_into, METH_VARARGS,
4173 recvmsg_into_doc,}, 4469 recvmsg_into_doc,},
4174 {"sendmsg", (PyCFunction)sock_sendmsg, METH_VARARGS, 4470 {"sendmsg", (PyCFunction)sock_sendmsg, METH_VARARGS,
4175 sendmsg_doc}, 4471 sendmsg_doc},
4472 #endif
4473 #ifdef HAVE_SOCKADDR_ALG
4474 {"sendmsg_afalg", (PyCFunction)sock_sendmsg_afalg, METH_VARARGS | METH_K EYWORDS,
4475 sendmsg_afalg_doc},
4176 #endif 4476 #endif
4177 {NULL, NULL} /* sentinel */ 4477 {NULL, NULL} /* sentinel */
4178 }; 4478 };
4179 4479
4180 /* SockObject members */ 4480 /* SockObject members */
4181 static PyMemberDef sock_memberlist[] = { 4481 static PyMemberDef sock_memberlist[] = {
4182 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "t he socket family"}, 4482 {"family", T_INT, offsetof(PySocketSockObject, sock_family), READONLY, "t he socket family"},
4183 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the s ocket type"}, 4483 {"type", T_INT, offsetof(PySocketSockObject, sock_type), READONLY, "the s ocket type"},
4184 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"}, 4484 {"proto", T_INT, offsetof(PySocketSockObject, sock_proto), READONLY, "the socket protocol"},
4185 {0}, 4485 {0},
(...skipping 2083 matching lines...) Expand 10 before | Expand all | Expand 10 after
6269 /* Multiprotocol bridge */ 6569 /* Multiprotocol bridge */
6270 PyModule_AddIntMacro(m, AF_BRIDGE); 6570 PyModule_AddIntMacro(m, AF_BRIDGE);
6271 #endif 6571 #endif
6272 #ifdef AF_ATMPVC 6572 #ifdef AF_ATMPVC
6273 /* ATM PVCs */ 6573 /* ATM PVCs */
6274 PyModule_AddIntMacro(m, AF_ATMPVC); 6574 PyModule_AddIntMacro(m, AF_ATMPVC);
6275 #endif 6575 #endif
6276 #ifdef AF_AAL5 6576 #ifdef AF_AAL5
6277 /* Reserved for Werner's ATM */ 6577 /* Reserved for Werner's ATM */
6278 PyModule_AddIntMacro(m, AF_AAL5); 6578 PyModule_AddIntMacro(m, AF_AAL5);
6579 #endif
6580 #ifdef HAVE_SOCKADDR_ALG
6581 PyModule_AddIntMacro(m, AF_ALG); /* Linux crypto */
6279 #endif 6582 #endif
6280 #ifdef AF_X25 6583 #ifdef AF_X25
6281 /* Reserved for X.25 project */ 6584 /* Reserved for X.25 project */
6282 PyModule_AddIntMacro(m, AF_X25); 6585 PyModule_AddIntMacro(m, AF_X25);
6283 #endif 6586 #endif
6284 #ifdef AF_INET6 6587 #ifdef AF_INET6
6285 PyModule_AddIntMacro(m, AF_INET6); /* IP version 6 */ 6588 PyModule_AddIntMacro(m, AF_INET6); /* IP version 6 */
6286 #endif 6589 #endif
6287 #ifdef AF_ROSE 6590 #ifdef AF_ROSE
6288 /* Amateur Radio X.25 PLP */ 6591 /* Amateur Radio X.25 PLP */
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
6330 #endif 6633 #endif
6331 #ifdef NETLINK_ROUTE6 6634 #ifdef NETLINK_ROUTE6
6332 PyModule_AddIntMacro(m, NETLINK_ROUTE6); 6635 PyModule_AddIntMacro(m, NETLINK_ROUTE6);
6333 #endif 6636 #endif
6334 PyModule_AddIntMacro(m, NETLINK_IP6_FW); 6637 PyModule_AddIntMacro(m, NETLINK_IP6_FW);
6335 #ifdef NETLINK_DNRTMSG 6638 #ifdef NETLINK_DNRTMSG
6336 PyModule_AddIntMacro(m, NETLINK_DNRTMSG); 6639 PyModule_AddIntMacro(m, NETLINK_DNRTMSG);
6337 #endif 6640 #endif
6338 #ifdef NETLINK_TAPBASE 6641 #ifdef NETLINK_TAPBASE
6339 PyModule_AddIntMacro(m, NETLINK_TAPBASE); 6642 PyModule_AddIntMacro(m, NETLINK_TAPBASE);
6643 #endif
6644 #ifdef NETLINK_CRYPTO
6645 PyModule_AddIntMacro(m, NETLINK_CRYPTO);
6340 #endif 6646 #endif
6341 #endif /* AF_NETLINK */ 6647 #endif /* AF_NETLINK */
6342 #ifdef AF_ROUTE 6648 #ifdef AF_ROUTE
6343 /* Alias to emulate 4.4BSD */ 6649 /* Alias to emulate 4.4BSD */
6344 PyModule_AddIntMacro(m, AF_ROUTE); 6650 PyModule_AddIntMacro(m, AF_ROUTE);
6345 #endif 6651 #endif
6346 #ifdef AF_LINK 6652 #ifdef AF_LINK
6347 PyModule_AddIntMacro(m, AF_LINK); 6653 PyModule_AddIntMacro(m, AF_LINK);
6348 #endif 6654 #endif
6349 #ifdef AF_ASH 6655 #ifdef AF_ASH
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
6482 #ifdef TIPC_SUB_CANCEL 6788 #ifdef TIPC_SUB_CANCEL
6483 /* doesn't seem to be available everywhere */ 6789 /* doesn't seem to be available everywhere */
6484 PyModule_AddIntMacro(m, TIPC_SUB_CANCEL); 6790 PyModule_AddIntMacro(m, TIPC_SUB_CANCEL);
6485 #endif 6791 #endif
6486 PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER); 6792 PyModule_AddIntMacro(m, TIPC_WAIT_FOREVER);
6487 PyModule_AddIntMacro(m, TIPC_PUBLISHED); 6793 PyModule_AddIntMacro(m, TIPC_PUBLISHED);
6488 PyModule_AddIntMacro(m, TIPC_WITHDRAWN); 6794 PyModule_AddIntMacro(m, TIPC_WITHDRAWN);
6489 PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT); 6795 PyModule_AddIntMacro(m, TIPC_SUBSCR_TIMEOUT);
6490 PyModule_AddIntMacro(m, TIPC_CFG_SRV); 6796 PyModule_AddIntMacro(m, TIPC_CFG_SRV);
6491 PyModule_AddIntMacro(m, TIPC_TOP_SRV); 6797 PyModule_AddIntMacro(m, TIPC_TOP_SRV);
6798 #endif
6799
6800 #ifdef HAVE_SOCKADDR_ALG
6801 /* Socket options */
6802 PyModule_AddIntMacro(m, ALG_SET_KEY);
6803 PyModule_AddIntMacro(m, ALG_SET_IV);
6804 PyModule_AddIntMacro(m, ALG_SET_OP);
6805 PyModule_AddIntMacro(m, ALG_SET_AEAD_ASSOCLEN);
6806 PyModule_AddIntMacro(m, ALG_SET_AEAD_AUTHSIZE);
6807 PyModule_AddIntMacro(m, ALG_SET_PUBKEY);
6808
6809 /* Operations */
6810 PyModule_AddIntMacro(m, ALG_OP_DECRYPT);
6811 PyModule_AddIntMacro(m, ALG_OP_ENCRYPT);
6812 PyModule_AddIntMacro(m, ALG_OP_SIGN);
6813 PyModule_AddIntMacro(m, ALG_OP_VERIFY);
6492 #endif 6814 #endif
6493 6815
6494 /* Socket types */ 6816 /* Socket types */
6495 PyModule_AddIntMacro(m, SOCK_STREAM); 6817 PyModule_AddIntMacro(m, SOCK_STREAM);
6496 PyModule_AddIntMacro(m, SOCK_DGRAM); 6818 PyModule_AddIntMacro(m, SOCK_DGRAM);
6497 /* We have incomplete socket support. */ 6819 /* We have incomplete socket support. */
6498 #ifdef SOCK_RAW 6820 #ifdef SOCK_RAW
6499 /* SOCK_RAW is marked as optional in the POSIX specification */ 6821 /* SOCK_RAW is marked as optional in the POSIX specification */
6500 PyModule_AddIntMacro(m, SOCK_RAW); 6822 PyModule_AddIntMacro(m, SOCK_RAW);
6501 #endif 6823 #endif
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
6753 PyModule_AddIntConstant(m, "CAN_BCM_RX_DELETE", RX_DELETE); 7075 PyModule_AddIntConstant(m, "CAN_BCM_RX_DELETE", RX_DELETE);
6754 PyModule_AddIntConstant(m, "CAN_BCM_RX_READ", RX_READ); 7076 PyModule_AddIntConstant(m, "CAN_BCM_RX_READ", RX_READ);
6755 PyModule_AddIntConstant(m, "CAN_BCM_TX_STATUS", TX_STATUS); 7077 PyModule_AddIntConstant(m, "CAN_BCM_TX_STATUS", TX_STATUS);
6756 PyModule_AddIntConstant(m, "CAN_BCM_TX_EXPIRED", TX_EXPIRED); 7078 PyModule_AddIntConstant(m, "CAN_BCM_TX_EXPIRED", TX_EXPIRED);
6757 PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS); 7079 PyModule_AddIntConstant(m, "CAN_BCM_RX_STATUS", RX_STATUS);
6758 PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT); 7080 PyModule_AddIntConstant(m, "CAN_BCM_RX_TIMEOUT", RX_TIMEOUT);
6759 PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED); 7081 PyModule_AddIntConstant(m, "CAN_BCM_RX_CHANGED", RX_CHANGED);
6760 #endif 7082 #endif
6761 #ifdef SOL_RDS 7083 #ifdef SOL_RDS
6762 PyModule_AddIntMacro(m, SOL_RDS); 7084 PyModule_AddIntMacro(m, SOL_RDS);
7085 #endif
7086 #ifdef HAVE_SOCKADDR_ALG
7087 PyModule_AddIntMacro(m, SOL_ALG);
6763 #endif 7088 #endif
6764 #ifdef RDS_CANCEL_SENT_TO 7089 #ifdef RDS_CANCEL_SENT_TO
6765 PyModule_AddIntMacro(m, RDS_CANCEL_SENT_TO); 7090 PyModule_AddIntMacro(m, RDS_CANCEL_SENT_TO);
6766 #endif 7091 #endif
6767 #ifdef RDS_GET_MR 7092 #ifdef RDS_GET_MR
6768 PyModule_AddIntMacro(m, RDS_GET_MR); 7093 PyModule_AddIntMacro(m, RDS_GET_MR);
6769 #endif 7094 #endif
6770 #ifdef RDS_FREE_MR 7095 #ifdef RDS_FREE_MR
6771 PyModule_AddIntMacro(m, RDS_FREE_MR); 7096 PyModule_AddIntMacro(m, RDS_FREE_MR);
6772 #endif 7097 #endif
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
7370 return NULL; 7695 return NULL;
7371 memcpy(&packed_addr, src, sizeof(packed_addr)); 7696 memcpy(&packed_addr, src, sizeof(packed_addr));
7372 return strncpy(dst, inet_ntoa(packed_addr), size); 7697 return strncpy(dst, inet_ntoa(packed_addr), size);
7373 } 7698 }
7374 /* Should set errno to EAFNOSUPPORT */ 7699 /* Should set errno to EAFNOSUPPORT */
7375 return NULL; 7700 return NULL;
7376 } 7701 }
7377 7702
7378 #endif 7703 #endif
7379 #endif 7704 #endif
OLDNEW
« Lib/test/test_socket.py ('K') | « Lib/test/test_socket.py ('k') | no next file » | no next file with comments »

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