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

Side by Side Diff: Modules/socketmodule.c

Issue 1522400: irda socket support
Patch Set: Created 1 year 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
« no previous file with comments | « no previous file | Modules/socketmodule.h » ('j') | 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 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 { 1253 {
1254 struct sockaddr_ctl *a = (struct sockaddr_ctl *)addr; 1254 struct sockaddr_ctl *a = (struct sockaddr_ctl *)addr;
1255 return Py_BuildValue("(II)", a->sc_id, a->sc_unit); 1255 return Py_BuildValue("(II)", a->sc_id, a->sc_unit);
1256 } 1256 }
1257 #endif 1257 #endif
1258 default: 1258 default:
1259 PyErr_SetString(PyExc_ValueError, 1259 PyErr_SetString(PyExc_ValueError,
1260 "Invalid address type"); 1260 "Invalid address type");
1261 return 0; 1261 return 0;
1262 } 1262 }
1263 #endif
1264
1265 #ifdef AF_IRDA
1266 case AF_IRDA:
1267 {
1268 struct sockaddr_irda *a = (struct sockaddr_irda *)addr;
1269
1270 return Py_BuildValue("iO&", a->sir_addr,
1271 PyUnicode_DecodeFSDefault, a->sir_name);
1272 }
1263 #endif 1273 #endif
1264 1274
1265 /* More cases here... */ 1275 /* More cases here... */
1266 1276
1267 default: 1277 default:
1268 /* If we don't know the address family, don't raise an 1278 /* If we don't know the address family, don't raise an
1269 exception -- return it as an (int, bytes) tuple. */ 1279 exception -- return it as an (int, bytes) tuple. */
1270 return Py_BuildValue("iy#", 1280 return Py_BuildValue("iy#",
1271 addr->sa_family, 1281 addr->sa_family,
1272 addr->sa_data, 1282 addr->sa_data,
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 1760
1751 *len_ret = sizeof(*addr); 1761 *len_ret = sizeof(*addr);
1752 return 1; 1762 return 1;
1753 } 1763 }
1754 #endif 1764 #endif
1755 default: 1765 default:
1756 PyErr_SetString(PyExc_OSError, 1766 PyErr_SetString(PyExc_OSError,
1757 "getsockaddrarg: unsupported PF_SYSTEM protocol"); 1767 "getsockaddrarg: unsupported PF_SYSTEM protocol");
1758 return 0; 1768 return 0;
1759 } 1769 }
1770 #endif
1771
1772 #ifdef HAVE_IRDA_H
1773 case AF_IRDA:
1774 {
1775 struct sockaddr_irda *addr;
1776 int daddr;
1777 PyObject *service;
1778 addr = (struct sockaddr_irda *)addr_ret;
1779 Py_ssize_t len;
1780
1781 if (!PyArg_ParseTuple(args, "iO&", &daddr,
1782 PyUnicode_FSConverter, &service))
1783 return 0;
1784
1785 len = PyBytes_GET_SIZE(service);
1786
1787 if (len <= 0 || len >= sizeof(addr->sir_name)) {
1788 PyErr_SetString(PyExc_OSError, "AF_IRDA service name too long");
1789 Py_DECREF(service);
1790 return 0;
1791 }
1792
1793 #ifdef HAVE_LINUX_IRDA_H
1794 addr->sir_family = AF_IRDA;
1795 addr->sir_lsap_sel = LSAP_ANY;
1796 addr->sir_addr = daddr;
1797 strcpy(addr->sir_name, PyBytes_AS_STRING(service));
1798 #else /* Windows */
1799 addr->irdaAddressFamily = AF_IRDA;
1800 addr->irdaDeviceID[0] = (daddr >> 24) & Oxff;
1801 addr->irdaDeviceID[1] = (daddr >> 16) & Oxff;
1802 addr->irdaDeviceID[2] = (daddr >> 8) & Oxff;
1803 addr->irdaDeviceID[3] = daddr & Oxff;
1804 strcpy(addr->irdaServiceName, PyBytes_AS_STRING(service));
1805 #endif
1806
1807 Py_DECREF(service);
1808 *len_ret = sizeof(*addr);
1809 return 1;
1810 }
1760 #endif 1811 #endif
1761 1812
1762 /* More cases here... */ 1813 /* More cases here... */
1763 1814
1764 default: 1815 default:
1765 PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family"); 1816 PyErr_SetString(PyExc_OSError, "getsockaddrarg: bad family");
1766 return 0; 1817 return 0;
1767 1818
1768 } 1819 }
1769 } 1820 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 *len_ret = sizeof (struct sockaddr_ctl); 1924 *len_ret = sizeof (struct sockaddr_ctl);
1874 return 1; 1925 return 1;
1875 #endif 1926 #endif
1876 default: 1927 default:
1877 PyErr_SetString(PyExc_OSError, "getsockaddrlen: " 1928 PyErr_SetString(PyExc_OSError, "getsockaddrlen: "
1878 "unknown PF_SYSTEM protocol"); 1929 "unknown PF_SYSTEM protocol");
1879 return 0; 1930 return 0;
1880 } 1931 }
1881 #endif 1932 #endif
1882 1933
1934 #ifdef AF_IRDA
1935 case AF_IRDA:
1936 {
1937 *len_ret = sizeof (struct sockaddr_irda);
1938 return 1;
1939 }
1940 #endif
1941
1883 /* More cases here... */ 1942 /* More cases here... */
1884 1943
1885 default: 1944 default:
1886 PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family"); 1945 PyErr_SetString(PyExc_OSError, "getsockaddrlen: bad family");
1887 return 0; 1946 return 0;
1888 1947
1889 } 1948 }
1890 } 1949 }
1891 1950
1892 1951
(...skipping 3921 matching lines...) Expand 10 before | Expand all | Expand 10 after
5814 #ifdef PF_RDS 5873 #ifdef PF_RDS
5815 PyModule_AddIntConstant(m, "PF_RDS", PF_RDS); 5874 PyModule_AddIntConstant(m, "PF_RDS", PF_RDS);
5816 #endif 5875 #endif
5817 5876
5818 /* Kernel event messages */ 5877 /* Kernel event messages */
5819 #ifdef PF_SYSTEM 5878 #ifdef PF_SYSTEM
5820 PyModule_AddIntConstant(m, "PF_SYSTEM", PF_SYSTEM); 5879 PyModule_AddIntConstant(m, "PF_SYSTEM", PF_SYSTEM);
5821 #endif 5880 #endif
5822 #ifdef AF_SYSTEM 5881 #ifdef AF_SYSTEM
5823 PyModule_AddIntConstant(m, "AF_SYSTEM", AF_SYSTEM); 5882 PyModule_AddIntConstant(m, "AF_SYSTEM", AF_SYSTEM);
5883 #endif
5884
5885 /* Infrared Data Association */
5886 #ifdef AF_IRDA
5887 PyModule_AddIntConstant(m, "AF_IRDA", AF_IRDA);
5888 #endif
5889 #ifdef PF_IRDA
5890 PyModule_AddIntConstant(m, "PF_IRDA", PF_IRDA);
5824 #endif 5891 #endif
5825 5892
5826 #ifdef AF_PACKET 5893 #ifdef AF_PACKET
5827 PyModule_AddIntMacro(m, AF_PACKET); 5894 PyModule_AddIntMacro(m, AF_PACKET);
5828 #endif 5895 #endif
5829 #ifdef PF_PACKET 5896 #ifdef PF_PACKET
5830 PyModule_AddIntMacro(m, PF_PACKET); 5897 PyModule_AddIntMacro(m, PF_PACKET);
5831 #endif 5898 #endif
5832 #ifdef PACKET_HOST 5899 #ifdef PACKET_HOST
5833 PyModule_AddIntMacro(m, PACKET_HOST); 5900 PyModule_AddIntMacro(m, PACKET_HOST);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
5886 #ifdef TIPC_SUB_CANCEL 5953 #ifdef TIPC_SUB_CANCEL
5887 /* doesn't seem to be available everywhere */ 5954 /* doesn't seem to be available everywhere */
5888 PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL); 5955 PyModule_AddIntConstant(m, "TIPC_SUB_CANCEL", TIPC_SUB_CANCEL);
5889 #endif 5956 #endif
5890 PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER); 5957 PyModule_AddIntConstant(m, "TIPC_WAIT_FOREVER", TIPC_WAIT_FOREVER);
5891 PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED); 5958 PyModule_AddIntConstant(m, "TIPC_PUBLISHED", TIPC_PUBLISHED);
5892 PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN); 5959 PyModule_AddIntConstant(m, "TIPC_WITHDRAWN", TIPC_WITHDRAWN);
5893 PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT); 5960 PyModule_AddIntConstant(m, "TIPC_SUBSCR_TIMEOUT", TIPC_SUBSCR_TIMEOUT);
5894 PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV); 5961 PyModule_AddIntConstant(m, "TIPC_CFG_SRV", TIPC_CFG_SRV);
5895 PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV); 5962 PyModule_AddIntConstant(m, "TIPC_TOP_SRV", TIPC_TOP_SRV);
5963 #endif
5964
5965 #ifdef HAVE_IRDA_H
5966 PyModule_AddIntConstant(m, "SOL_IRLMP", SOL_IRLMP);
5967 PyModule_AddIntConstant(m, "IRLMP_ENUMDEVICES", IRLMP_ENUMDEVICES);
5968 PyModule_AddIntConstant(m, "IRLMP_IAS_SET", IRLMP_IAS_SET);
5969 PyModule_AddIntConstant(m, "IRLMP_IAS_QUERY", IRLMP_IAS_QUERY);
5896 #endif 5970 #endif
5897 5971
5898 /* Socket types */ 5972 /* Socket types */
5899 PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM); 5973 PyModule_AddIntConstant(m, "SOCK_STREAM", SOCK_STREAM);
5900 PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM); 5974 PyModule_AddIntConstant(m, "SOCK_DGRAM", SOCK_DGRAM);
5901 /* We have incomplete socket support. */ 5975 /* We have incomplete socket support. */
5902 PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW); 5976 PyModule_AddIntConstant(m, "SOCK_RAW", SOCK_RAW);
5903 PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET); 5977 PyModule_AddIntConstant(m, "SOCK_SEQPACKET", SOCK_SEQPACKET);
5904 #if defined(SOCK_RDM) 5978 #if defined(SOCK_RDM)
5905 PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM); 5979 PyModule_AddIntConstant(m, "SOCK_RDM", SOCK_RDM);
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
6723 return NULL; 6797 return NULL;
6724 memcpy(&packed_addr, src, sizeof(packed_addr)); 6798 memcpy(&packed_addr, src, sizeof(packed_addr));
6725 return strncpy(dst, inet_ntoa(packed_addr), size); 6799 return strncpy(dst, inet_ntoa(packed_addr), size);
6726 } 6800 }
6727 /* Should set errno to EAFNOSUPPORT */ 6801 /* Should set errno to EAFNOSUPPORT */
6728 return NULL; 6802 return NULL;
6729 } 6803 }
6730 6804
6731 #endif 6805 #endif
6732 #endif 6806 #endif
OLDNEW
« no previous file with comments | « no previous file | Modules/socketmodule.h » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7