Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r48254:82601a1c1f1d Date: 2011-10-20 10:58 +0200 http://bitbucket.org/pypy/pypy/changeset/82601a1c1f1d/
Log: Change the detection of 'AF_PACKET': instead of detecting it automatically, force it to be True on Linux only. According to http://bugs.python.org/issue8852: The AF_PACKET support was original meant for Linux. When Solaris now also supports that socket family, and with a similar interface, it might be interesting to port that support to Solaris. Notably, "similar" means "but not identical". diff --git a/pypy/rlib/_rsocket_rffi.py b/pypy/rlib/_rsocket_rffi.py --- a/pypy/rlib/_rsocket_rffi.py +++ b/pypy/rlib/_rsocket_rffi.py @@ -16,6 +16,7 @@ _MINGW = target_platform.name == "mingw32" _SOLARIS = sys.platform == "sunos5" _MACOSX = sys.platform == "darwin" +_HAS_AF_PACKET = sys.platform.startswith('linux') # only Linux for now if _POSIX: includes = ('sys/types.h', @@ -34,11 +35,12 @@ 'stdint.h', 'errno.h', ) + if _HAS_AF_PACKET: + includes += ('netpacket/packet.h', + 'sys/ioctl.h', + 'net/if.h') - cond_includes = [('AF_NETLINK', 'linux/netlink.h'), - ('AF_PACKET', 'netpacket/packet.h'), - ('AF_PACKET', 'sys/ioctl.h'), - ('AF_PACKET', 'net/if.h')] + cond_includes = [('AF_NETLINK', 'linux/netlink.h')] libraries = () calling_conv = 'c' @@ -320,18 +322,18 @@ ('events', rffi.SHORT), ('revents', rffi.SHORT)]) - CConfig.sockaddr_ll = platform.Struct('struct sockaddr_ll', + if _HAS_AF_PACKET: + CConfig.sockaddr_ll = platform.Struct('struct sockaddr_ll', [('sll_ifindex', rffi.INT), ('sll_protocol', rffi.INT), ('sll_pkttype', rffi.INT), ('sll_hatype', rffi.INT), ('sll_addr', rffi.CFixedArray(rffi.CHAR, 8)), - ('sll_halen', rffi.INT)], - ifdef='AF_PACKET') + ('sll_halen', rffi.INT)]) - CConfig.ifreq = platform.Struct('struct ifreq', [('ifr_ifindex', rffi.INT), - ('ifr_name', rffi.CFixedArray(rffi.CHAR, 8))], - ifdef='AF_PACKET') + CConfig.ifreq = platform.Struct('struct ifreq', + [('ifr_ifindex', rffi.INT), + ('ifr_name', rffi.CFixedArray(rffi.CHAR, 8))]) if _WIN32: CConfig.WSAEVENT = platform.SimpleType('WSAEVENT', rffi.VOIDP) @@ -386,6 +388,8 @@ constants[name] = value else: constants[name] = default +if not _HAS_AF_PACKET and 'AF_PACKET' in constants: + del constants['AF_PACKET'] constants['has_ipv6'] = True # This is a configuration option in CPython for name, value in constants.items(): @@ -439,21 +443,14 @@ if _POSIX: nfds_t = cConfig.nfds_t pollfd = cConfig.pollfd - if cConfig.sockaddr_ll is not None: + if _HAS_AF_PACKET: sockaddr_ll = cConfig.sockaddr_ll - ifreq = cConfig.ifreq + ifreq = cConfig.ifreq if WIN32: WSAEVENT = cConfig.WSAEVENT WSANETWORKEVENTS = cConfig.WSANETWORKEVENTS timeval = cConfig.timeval -#if _POSIX: -# includes = list(includes) -# for _name, _header in cond_includes: -# if getattr(cConfig, _name) is not None: -# includes.append(_header) -# eci = ExternalCompilationInfo(includes=includes, libraries=libraries, -# separate_module_sources=sources) def external(name, args, result, **kwds): return rffi.llexternal(name, args, result, compilation_info=eci, @@ -544,7 +541,7 @@ socketpair_t = rffi.CArray(socketfd_type) socketpair = external('socketpair', [rffi.INT, rffi.INT, rffi.INT, lltype.Ptr(socketpair_t)], rffi.INT) - if ifreq is not None: + if _HAS_AF_PACKET: ioctl = external('ioctl', [socketfd_type, rffi.INT, lltype.Ptr(ifreq)], rffi.INT) diff --git a/pypy/rlib/rsocket.py b/pypy/rlib/rsocket.py --- a/pypy/rlib/rsocket.py +++ b/pypy/rlib/rsocket.py @@ -8,6 +8,7 @@ # Known missing features: # # - address families other than AF_INET, AF_INET6, AF_UNIX, AF_PACKET +# - AF_PACKET is only supported on Linux # - methods makefile(), # - SSL # _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit