當前位置: 首頁>>代碼示例>>Python>>正文


Python socket.TCP_MAXSEG屬性代碼示例

本文整理匯總了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 
開發者ID:hao35954514,項目名稱:shadowsocksR-b,代碼行數:11,代碼來源:tcprelay.py

示例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 
開發者ID:joakimeriksson,項目名稱:ai-smarthome,代碼行數:61,代碼來源:nat64-dpkt.py

示例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) 
開發者ID:joakimeriksson,項目名稱:ai-smarthome,代碼行數:52,代碼來源:nat64.py


注:本文中的socket.TCP_MAXSEG屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。