本文整理汇总了Python中socket.CAN_RAW属性的典型用法代码示例。如果您正苦于以下问题:Python socket.CAN_RAW属性的具体用法?Python socket.CAN_RAW怎么用?Python socket.CAN_RAW使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.CAN_RAW属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_socket
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [as 别名]
def _make_socket(iface_name: str, can_fd: bool) -> socket.SocketType:
s = socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW)
try:
s.bind((iface_name,))
s.setsockopt(socket.SOL_SOCKET, _SO_TIMESTAMP, 1) # timestamping
if can_fd:
s.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_FD_FRAMES, 1)
s.setblocking(False)
if 0 != s.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR):
raise OSError('Could not configure the socket: getsockopt(SOL_SOCKET, SO_ERROR) != 0')
except BaseException:
with contextlib.suppress(Exception):
s.close()
raise
return s
示例2: _have_socket_can
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [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
示例3: setUp
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [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)
示例4: clientSetUp
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [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
示例5: testCreateSocket
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [as 别名]
def testCreateSocket(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
pass
示例6: testBindAny
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [as 别名]
def testBindAny(self):
with socket.socket(socket.PF_CAN, socket.SOCK_RAW, socket.CAN_RAW) as s:
s.bind(('', ))
示例7: testLoopback
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [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))
示例8: testFilter
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [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))
示例9: testFilter
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [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))
示例10: __init__
# 需要导入模块: import socket [as 别名]
# 或者: from socket import CAN_RAW [as 别名]
def __init__(self, channel=None, receive_own_messages=False,
can_filters=None, remove_padding=True, basecls=CAN, **kwargs):
bustype = kwargs.pop("bustype", None)
if bustype and bustype != "socketcan":
warning("You created a NativeCANSocket. "
"If you're providing the argument 'bustype', please use "
"the correct one to achieve compatibility with python-can"
"/PythonCANSocket. \n'bustype=socketcan'")
self.basecls = basecls
self.remove_padding = remove_padding
self.channel = conf.contribs['NativeCANSocket']['channel'] if \
channel is None else channel
self.ins = socket.socket(socket.PF_CAN,
socket.SOCK_RAW,
socket.CAN_RAW)
try:
self.ins.setsockopt(socket.SOL_CAN_RAW,
socket.CAN_RAW_RECV_OWN_MSGS,
struct.pack("i", receive_own_messages))
except Exception as exception:
raise Scapy_Exception(
"Could not modify receive own messages (%s)", exception
)
if can_filters is None:
can_filters = [{
"can_id": 0,
"can_mask": 0
}]
can_filter_fmt = "={}I".format(2 * len(can_filters))
filter_data = []
for can_filter in can_filters:
filter_data.append(can_filter["can_id"])
filter_data.append(can_filter["can_mask"])
self.ins.setsockopt(socket.SOL_CAN_RAW,
socket.CAN_RAW_FILTER,
struct.pack(can_filter_fmt, *filter_data))
self.ins.bind((self.channel,))
self.outs = self.ins