当前位置: 首页>>代码示例>>Python>>正文


Python socket.PF_CAN属性代码示例

本文整理汇总了Python中socket.PF_CAN属性的典型用法代码示例。如果您正苦于以下问题:Python socket.PF_CAN属性的具体用法?Python socket.PF_CAN怎么用?Python socket.PF_CAN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在socket的用法示例。


在下文中一共展示了socket.PF_CAN属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __bind_socket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def __bind_socket(self, sock, iface, sid, did):
            socket_id = ctypes.c_int(sock.fileno())
            ifr = self.__get_sock_ifreq(sock, iface)

            if sid > 0x7ff:
                sid = sid | socket.CAN_EFF_FLAG
            if did > 0x7ff:
                did = did | socket.CAN_EFF_FLAG

            # select the CAN interface and bind the socket to it
            addr = SOCKADDR_CAN(ctypes.c_uint16(socket.PF_CAN),
                                ifr.ifr_ifindex,
                                ADDR_INFO(TP(ctypes.c_uint32(did),
                                             ctypes.c_uint32(sid))))

            error = LIBC.bind(socket_id, ctypes.byref(addr),
                              ctypes.sizeof(addr))

            if error < 0:
                warning("Couldn't bind socket") 
开发者ID:secdev,项目名称:scapy,代码行数:22,代码来源:isotp.py

示例2: __bindSocket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def __bindSocket(self, sock, iface, sid, did):
        socketID = ctypes.c_int(sock.fileno())
        ifr = self.__getSockIfreq(sock, iface)

        if sid > 0x7ff:
            sid = sid | socket.CAN_EFF_FLAG
        if did > 0x7ff:
            did = did | socket.CAN_EFF_FLAG

        # select the CAN interface and bind the socket to it
        addr = SOCKADDR_CAN(ctypes.c_uint16(socket.PF_CAN),
                            ifr.ifr_ifindex,
                            ADDR_INFO(TP(ctypes.c_uint32(sid),
                                         ctypes.c_uint32(did))))

        error = libc.bind(socketID, ctypes.byref(addr), ctypes.sizeof(addr))

        if error < 0:
            warning("Couldn't bind socket") 
开发者ID:phaethon,项目名称:kamene,代码行数:21,代码来源:isotp.py

示例3: __init__

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def __init__(self, iface=None, sid=0, did=0, extended_addr=None, extended_rx_addr=None, listen_only=False, basecls=ISOTP):
        if iface is None:
            iface = conf.CANiface
        self.ins = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, CAN_ISOTP)
        self.__setOptionFlags(self.ins, extended_addr, extended_rx_addr, listen_only)

        self.ins.setsockopt(SOL_CAN_ISOTP,
                            CAN_ISOTP_RECV_FC,
                            self.__build_can_isotp_fc_options())
        self.ins.setsockopt(SOL_CAN_ISOTP,
                            CAN_ISOTP_LL_OPTS,
                            self.__build_can_isotp_ll_options())

        self.__bindSocket(self.ins, iface, sid, did)
        self.outs = self.ins
        if basecls is None:
            warning('Provide a basecls ')
        self.basecls = basecls 
开发者ID:phaethon,项目名称:kamene,代码行数:20,代码来源:isotp.py

示例4: _have_socket_can

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def _have_socket_can():
    """Check whether CAN sockets are supported on this host."""
    try:
        s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
    except (AttributeError, OSError):
        return False
    else:
        s.close()
    return True 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_socket.py

示例5: setUp

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def setUp(self):
        self.s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
        self.addCleanup(self.s.close)
        try:
            self.s.bind((self.interface,))
        except OSError:
            self.skipTest('network interface `%s` does not exist' %
                           self.interface) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_socket.py

示例6: clientSetUp

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def clientSetUp(self):
        self.cli = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
        try:
            self.cli.bind((self.interface,))
        except OSError:
            # skipTest should not be called here, and will be called in the
            # server instead
            pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_socket.py

示例7: testCrucialConstants

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testCrucialConstants(self):
        socket.AF_CAN
        socket.PF_CAN
        socket.CAN_RAW 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_socket.py

示例8: testCreateSocket

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testCreateSocket(self):
        with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
            pass 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_socket.py

示例9: testBindAny

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testBindAny(self):
        with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
            s.bind(('', )) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_socket.py

示例10: testTooLongInterfaceName

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testTooLongInterfaceName(self):
        # most systems limit IFNAMSIZ to 16, take 1024 to be sure
        with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
            self.assertRaisesRegex(OSError, 'interface name too long',
                                   s.bind, ('x' * 1024,)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_socket.py

示例11: testLoopback

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testLoopback(self):
        with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
            for loopback in (0, 1):
                s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_LOOPBACK,
                             loopback)
                self.assertEqual(loopback,
                    s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_LOOPBACK)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:test_socket.py

示例12: testFilter

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testFilter(self):
        can_id, can_mask = 0x200, 0x700
        can_filter = struct.pack("=II", can_id, can_mask)
        with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
            s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter)
            self.assertEqual(can_filter,
                    s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8))
            s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, bytearray(can_filter)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_socket.py

示例13: testBCM

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testBCM(self):
        bcm = socket.socket(socket.PF_CAN, socket.SOCK_DGRAM, socket.CAN_BCM)
        self.addCleanup(bcm.close)
        bcm.connect((self.interface,))
        self.can_id = 0x123
        self.data = bytes([0xc0, 0xff, 0xee])
        self.cf = self.build_can_frame(self.can_id, self.data)
        opcode = socket.CAN_BCM_TX_SEND
        flags = 0
        count = 0
        ival1_seconds = ival1_usec = ival2_seconds = ival2_usec = 0
        bcm_can_id = 0x0222
        nframes = 1
        assert len(self.cf) == 16
        header = struct.pack(self.bcm_cmd_msg_fmt,
                    opcode,
                    flags,
                    count,
                    ival1_seconds,
                    ival1_usec,
                    ival2_seconds,
                    ival2_usec,
                    bcm_can_id,
                    nframes,
                    )
        header_plus_frame = header + self.cf
        bytes_sent = bcm.send(header_plus_frame)
        self.assertEqual(bytes_sent, len(header_plus_frame)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:30,代码来源:test_socket.py

示例14: testFilter

# 需要导入模块: import socket [as 别名]
# 或者: from socket import PF_CAN [as 别名]
def testFilter(self):
        can_id, can_mask = 0x200, 0x700
        can_filter = struct.pack("=II", can_id, can_mask)
        with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
            s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, can_filter)
            self.assertEqual(can_filter,
                    s.getsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FILTER, 8)) 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:9,代码来源:test_socket.py


注:本文中的socket.PF_CAN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。