def __init__(self, interface_name, on_ip_incoming, on_ip_outgoing):
self.interface_name = interface_name
self.on_ip_incoming = on_ip_incoming
self.on_ip_outgoing = on_ip_outgoing
# The raw in (listen) socket is a L2 raw socket that listens
# for all packets going through a specific interface.
# SOL_SOCKET: SO_LINGER, SO_RCVBUF, SO_SNDBUF, TCP_NODELAY
# SO_LINGER ???????????????????TIME_WAIT?????
# ????????????????????tcp??
# SO_RCVBUF?SO_SNDBUF ????????????????
# SO_SNDBUF ?? MSS??????? 2MSS
# TCP_NODELAY ?? nagle ??
self.sock = socket.socket(
socket.AF_PACKET, socket.SOCK_RAW, socket.htons(ETH_P_IP))
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2 ** 30)
self.sock.bind((self.interface_name, ETH_P_IP))
评论列表
文章目录