本文整理匯總了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