本文整理汇总了Python中socket.SOL_CAN_RAW属性的典型用法代码示例。如果您正苦于以下问题:Python socket.SOL_CAN_RAW属性的具体用法?Python socket.SOL_CAN_RAW怎么用?Python socket.SOL_CAN_RAW使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.SOL_CAN_RAW属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_socket
# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_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: _set_loopback_enabled
# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_CAN_RAW [as 别名]
def _set_loopback_enabled(self, enable: bool) -> None:
if enable != self._loopback_enabled:
self._sock.setsockopt(socket.SOL_CAN_RAW, socket.CAN_RAW_RECV_OWN_MSGS, int(enable))
self._loopback_enabled = enable
示例3: testLoopback
# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_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))
示例4: testFilter
# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_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))
示例5: testFilter
# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_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))
示例6: __init__
# 需要导入模块: import socket [as 别名]
# 或者: from socket import SOL_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