本文整理汇总了Python中socket.TCP_MAXSEG属性的典型用法代码示例。如果您正苦于以下问题:Python socket.TCP_MAXSEG属性的具体用法?Python socket.TCP_MAXSEG怎么用?Python socket.TCP_MAXSEG使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类socket
的用法示例。
在下文中一共展示了socket.TCP_MAXSEG属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update_tcp_mss
# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_MAXSEG [as 别名]
def _update_tcp_mss(self, local_sock):
self._tcp_mss = TCP_MSS
try:
tcp_mss = local_sock.getsockopt(socket.SOL_TCP, socket.TCP_MAXSEG)
if tcp_mss > 500 and tcp_mss <= 1500:
self._tcp_mss = tcp_mss
logging.debug("TCP MSS = %d" % (self._tcp_mss,))
except:
pass
示例2: handle_tcp_state_tosock
# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_MAXSEG [as 别名]
def handle_tcp_state_tosock(self, ip):
tcp = ip.data
global tun, input
log.debug("=== NAT64 TCP sock-send: %d %s."%(tcp.flags, self.sock))
if self.sock is None:
log.warning("Socket already closed.")
return
if tcp.flags & dpkt.tcp.TH_SYN > 0:
# Use Window size to control max segment?
self.sock.setsockopt(socket.SOL_TCP, socket.TCP_MAXSEG, 1000)
log.debug("Maxseg: %d" % self.sock.getsockopt(socket.SOL_TCP, socket.TCP_MAXSEG))
self.ack = tcp.seq + 1
# We are established...
self.state = TCP_ESTABLISHED
self.window = tcp.win
# Get the MSS of the options
opts = dpkt.tcp.parse_opts(tcp.opts)
for k, v in opts:
if k == dpkt.tcp.TCP_OPT_MSS:
print("MSS:", v)
self.mss, = struct.unpack("!H", v)
print("MSS:", self.mss)
log.debug("TCP State: %d SYN received." % self.mss)
self.tcp_reply(ip, dpkt.tcp.TH_SYN | dpkt.tcp.TH_ACK)
print("IP:", repr(ip))
send_to_tun(bytes(ip))
# sock.send(ip.load)
elif tcp.flags & dpkt.tcp.TH_FIN:
self.state = TCP_FIN_CLOSE_WAIT
self.ack = tcp.seq + 1
self.timeout = time.time()
log.debug("TCP: FIN received - sending FIN. %s" % self)
self.tcp_reply(ip, dpkt.tcp.TH_FIN | dpkt.tcp.TH_ACK)
print("IP:", repr(ip))
send_to_tun(bytes(ip))
# Clean out this socket?
elif tcp.flags & dpkt.tcp.TH_ACK:
if self.state == TCP_ESTABLISHED:
if len(tcp.data) == 0:
log.debug("ESTABLISHED or ACK from other side. seq: %d ack: %d" % (tcp.seq, tcp.ack))
self.seq = tcp.ack
else:
# ACK immediately - we assume that we get data from other side soon...
log.debug("TCP: received %d seq: %d ack%d ." % (len(tcp.data), tcp.seq, tcp.ack))
self.ack = tcp.seq + len(tcp.data)
# We should also handle the sanity checks for the ACK
self.seq = tcp.ack
self.tcp_reply(ip, dpkt.tcp.TH_ACK)
print("IP:", repr(ip))
send_to_tun(bytes(ip))
add_socket(self.sock)
if len(tcp.data) > 0:
self.sock.send(tcp.data)
# Remove the state for this specific socket
示例3: handle_tcp_state_tosock
# 需要导入模块: import socket [as 别名]
# 或者: from socket import TCP_MAXSEG [as 别名]
def handle_tcp_state_tosock(self, ip):
global tun, input
log.debug("=== NAT64 TCP sock-send: %d %s."%(ip.flags, self.sock))
if self.sock is None:
log.warning("Socket already closed.")
return
if ip.flags.S:
# Use Window size to control max segment?
self.sock.setsockopt(socket.SOL_TCP, socket.TCP_MAXSEG, 1000)
log.debug("Maxseg: %d" % self.sock.getsockopt(socket.SOL_TCP, socket.TCP_MAXSEG))
self.ack = ip.seq + 1
# We are established...
self.state = TCP_ESTABLISHED
self.window = ip[TCP].window
# Get the MSS of the options
for k, v in ip[TCP].options:
if k == 'MSS':
self.mss = v
log.debug("TCP State: %s SYN received." % self)
ipv6 = IPv6(src=ip.dst, dst=ip.src)/TCP(sport=ip.dport, dport=ip.sport, flags="SA", seq=self.seq, ack=self.ack)
ipv6.show()
send_to_tun(bytes(IPv6(ipv6)))
# sock.send(ip.load)
elif ip.flags.FA or ip.flags.F:
self.state = TCP_FIN_CLOSE_WAIT
self.ack = ip.seq + 1
self.timeout = time.time()
log.debug("TCP: FIN received - sending FIN. %s" % self)
ipv6 = IPv6(src=ip.dst, dst=ip.src)/TCP(sport=ip.dport, dport=ip.sport, flags="FA", seq=self.seq, ack=self.ack)
ipv6.show()
send_to_tun(bytes(IPv6(ipv6)))
# Clean out this socket?
elif ip.flags.A or ip.flags.AP:
if self.state == TCP_ESTABLISHED:
if not hasattr(ip,'load'):
log.debug("ESTABLISHED or ACK from other side. seq: %d ack: %d" % (ip.seq, ip.ack))
self.seq = ip.ack
else:
# ACK immediately - we assume that we get data from other side soon...
log.debug("TCP: received %d seq: %d ack%d ." % (len(ip.load), ip.seq, ip.ack))
self.ack = ip.seq + len(ip.load)
# We should also handle the sanity checks for the ACK
self.seq = ip.ack
ipv6 = IPv6(src=ip.dst, dst=ip.src)/TCP(sport=ip.dport, dport=ip.sport, flags="A", seq=self.seq, ack=self.ack)
ipv6 = IPv6(ipv6)
ipv6.show()
send_to_tun(bytes(ipv6))
add_socket(self.sock)
if hasattr(ip, 'load'):
self.sock.send(ip.load)