Posted 娣卞叆鍘熺悊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。
鐐瑰嚮馃憜钃濊壊鈥?nbsp;娣卞叆鍘熺悊鈥濓紝鍏虫敞骞垛€?/span>璁句负鏄熸爣鈥?/span>
鎶€鏈共璐э紝绗竴鏃堕棿鎺ㄩ€?/span>
涓€ TCP锛氫紶杈撴帶鍒跺崗璁姤鏂囨牸寮?/h2>
1 TCP鏈嶅姟
鎻愪緵闈㈠悜杩炴帴銆佸彲闈犵殑瀛楄妭娴佹湇鍔?/p>
闈㈠悜杩炴帴鎰忓懗鐫€涓ゆ柟閫氫俊锛屼笉鏀寔澶氭挱鍜屽箍鎾?/p>
鍙潬鎬х殑鏀寔锛?/p>
搴旂敤鏁版嵁琚垎鍓叉垚TCP璁や负鏈€閫傚悎鍙戦€佺殑鏁版嵁鍧椼€傜敱TCP浼犻€掔粰IP鐨勪俊鎭崟浣嶇О涓?span>鎶ユ枃娈垫垨娈?/strong>锛坰egment锛夈€?/p>
褰揟CP鍙戝嚭涓€涓鍚庯紝瀹冨惎鍔ㄤ竴涓?span>瀹氭椂鍣?/strong>锛岀瓑寰呯洰鐨勭纭鏀跺埌杩欎釜鎶ユ枃娈点€傚鏋滀笉鑳藉強鏃舵敹鍒颁竴涓‘璁わ紝灏嗛噸鍙戣繖涓姤鏂囨銆?/p>
褰揟CP鏀跺埌鍙戣嚜TCP杩炴帴鍙︿竴绔殑鏁版嵁锛屽畠灏嗗搷搴斾竴涓?span>纭銆?/p>
TCP灏嗕繚鎸佸畠棣栭儴鍜屾暟鎹殑妫€楠屽拰銆?/p>
TCP灏嗗鏀跺埌鐨勬暟鎹繘琛?span>閲嶆柊鎺掑簭锛屽皢鏀跺埌鐨勬暟鎹互姝g‘鐨勯『搴忎氦缁欏簲鐢ㄥ眰銆?/p>
IP鏁版嵁鎶ヤ細鍙戠敓閲嶅锛孴CP鐨勬帴鏀剁蹇呴』涓㈠純閲嶅鐨勬暟鎹€?/p>
TCP杩樿兘鎻愪緵娴侀噺鎺у埗锛孴CP杩炴帴鐨勬瘡涓€鏂归兘鏈夊浐瀹氬ぇ灏忕殑缂撳啿绌洪棿锛岄槻姝㈣緝蹇富鏈鸿嚧浣胯緝鎱富鏈虹殑缂撳啿鍖烘孩鍑恒€?/p>
TCP瀵瑰瓧鑺傛祦鐨勫唴瀹逛笉浣滀换浣曡В閲娿€傚瀛楄妭娴佺殑瑙i噴鐢盩CP杩炴帴鍙屾柟鐨勫簲鐢ㄥ眰瑙i噴銆?/p>
2 TCP棣栭儴
鎻愪緵闈㈠悜杩炴帴銆佸彲闈犵殑瀛楄妭娴佹湇鍔?/p>
闈㈠悜杩炴帴鎰忓懗鐫€涓ゆ柟閫氫俊锛屼笉鏀寔澶氭挱鍜屽箍鎾?/p>
鍙潬鎬х殑鏀寔锛?/p>
搴旂敤鏁版嵁琚垎鍓叉垚TCP璁や负鏈€閫傚悎鍙戦€佺殑鏁版嵁鍧椼€傜敱TCP浼犻€掔粰IP鐨勪俊鎭崟浣嶇О涓?span>鎶ユ枃娈垫垨娈?/strong>锛坰egment锛夈€?/p>
褰揟CP鍙戝嚭涓€涓鍚庯紝瀹冨惎鍔ㄤ竴涓?span>瀹氭椂鍣?/strong>锛岀瓑寰呯洰鐨勭纭鏀跺埌杩欎釜鎶ユ枃娈点€傚鏋滀笉鑳藉強鏃舵敹鍒颁竴涓‘璁わ紝灏嗛噸鍙戣繖涓姤鏂囨銆?/p>
褰揟CP鏀跺埌鍙戣嚜TCP杩炴帴鍙︿竴绔殑鏁版嵁锛屽畠灏嗗搷搴斾竴涓?span>纭銆?/p>
TCP灏嗕繚鎸佸畠棣栭儴鍜屾暟鎹殑妫€楠屽拰銆?/p>
TCP灏嗗鏀跺埌鐨勬暟鎹繘琛?span>閲嶆柊鎺掑簭锛屽皢鏀跺埌鐨勬暟鎹互姝g‘鐨勯『搴忎氦缁欏簲鐢ㄥ眰銆?/p>
IP鏁版嵁鎶ヤ細鍙戠敓閲嶅锛孴CP鐨勬帴鏀剁蹇呴』涓㈠純閲嶅鐨勬暟鎹€?/p>
TCP杩樿兘鎻愪緵娴侀噺鎺у埗锛孴CP杩炴帴鐨勬瘡涓€鏂归兘鏈夊浐瀹氬ぇ灏忕殑缂撳啿绌洪棿锛岄槻姝㈣緝蹇富鏈鸿嚧浣胯緝鎱富鏈虹殑缂撳啿鍖烘孩鍑恒€?/p>
TCP瀵瑰瓧鑺傛祦鐨勫唴瀹逛笉浣滀换浣曡В閲娿€傚瀛楄妭娴佺殑瑙i噴鐢盩CP杩炴帴鍙屾柟鐨勫簲鐢ㄥ眰瑙i噴銆?/p>
TCP棣栭儴涓?0涓瓧鑺?/p>
婧?span>绔彛鍙?/strong>鍜岀洰鐨?span>绔彛鍙?/strong> 锛?涓瓧鑺傦紝鐢ㄤ簬瀵绘壘鍙戠涓庢敹绔殑搴旂敤杩涚▼銆?/p>
32浣嶅簭鍙凤細4涓瓧鑺傦紝鐢ㄤ簬璇嗗埆浠嶵CP鍙戠鍚戞敹绔彂閫佺殑鏁版嵁瀛楄妭娴侊紝寰幆鍒╃敤锛岄€愪釜閫掑銆?/p>
32浣嶇‘璁ゅ簭鍙凤細4涓瓧鑺傦紝涓婃宸叉垚鍔熸敹鍒版暟鎹瓧鑺傚簭鍙峰姞1锛堝彧鏈夊湪ACK鏍囧織涓?鏃讹紝璇ュ瓧娈垫墠鏈夋晥锛?/p>
棣栭儴闀垮害锛?浣嶏紝鐢ㄤ簬鏍囪瘑棣栭儴鐨勯暱搴︼紝鍗充负5 * 4~15 * 4瀛楄妭绛変簬20~60瀛楄妭锛堝浐瀹氭姤澶达紙20瀛楄妭锛?+ 鍙€夐€夐」锛?/p>
鏍囧織姣旂壒锛?/p>
URG锛氱揣鎬ユ寚閽?/p>
ACK锛氱‘璁ゅ簭鍙锋湁鏁?/p>
PSH锛氭帴鍙楁柟搴斿敖蹇皢鎶ユ枃娈典氦缁欏簲鐢ㄥ眰
RST锛氶噸寤鸿繛鎺?/p>
SYN锛氬悓姝ュ簭鍙风敤鏉ュ彂璧蜂竴涓繛鎺?/p>
FIN锛氬彂绔畬鎴愬彂閫佷换鍔?/p>
绐楀彛澶у皬锛氱敤浜庢祦閲忔帶鍒讹紝鏈€澶т负65535瀛楄妭锛?6浣嶏級
妫€楠屽拰锛氳鐩栨暣涓猅CP鎶ユ枃娈碉紙TCP棣栭儴鍜屾暟鎹級锛屽彂绔绠楀拰瀛樺偍锛屾敹绔獙璇?/p>
绱ф€ユ寚閽堬細褰揢RG涓?鏃讹紝鎵嶆湁鏁堛€?/p>
浜?TCP杩炴帴鐨勫缓绔嬩笌缁堟
1 杩炴帴鐨勫缓绔嬩笌缁堟
锛?锛夊缓绔嬭繛鎺ュ崗璁紙涓夋鎻℃墜杩炴帴锛?/h4>
Client鍙戦€丼YN娈垫寚鏄庢墦绠楄繛鎺erer鐨勭鍙d互鍙婂垵濮嬪簭鍙凤紙ISN锛夛紝SYN涓?
Server鍝嶅簲Server鐨勫垵濮嬪簭鍙凤紙ISN锛変綔涓哄簲绛旓紝鍚屾椂灏嗙‘璁ゅ簭鍙疯缃负Client鐨処SN+1浠ュClient鐨凷YN鎶ユ枃杩涜纭銆?/p>
Client灏嗙‘璁ゅ簭鍙疯缃负Server鐨処SN+1浠ュServer鐨凷YN鎶ユ枃杩涜纭銆?/p>
锛?锛塛ireShark鎶撳寘鍒嗘瀽涓夋鎻℃墜杩炴帴
# client鐨凷YN鎶ユ枃
Transmission Control Protocol, Src Port: 1682, Dst Port: 1883, Seq: 0, Len: 0
Source Port: 1682 # 婧愮鍙?br> Destination Port: 1883 # 鐩爣绔彛
Sequence number: 0 (relative sequence number) # 搴忓彿
Acknowledgment number: 0 # 纭搴忓彿
1000 .... = Header Length: 32 bytes (8) # 棣栭儴闀垮害
Flags: 0x002 (SYN) # 鏍囪瘑绗?br> Window size value: 64240 # 绐楀彛澶у皬
Checksum: 0xa6f3 [unverified] # 妫€楠屽拰
Urgent pointer: 0 # 鐢变簬URG涓?锛屾墍浠ョ揣鎬ユ寚閽堜负0
Options: (12 bytes), Maximum segment size, No-Operation (NOP), Window scale, No-Operation (NOP), No-Operation (NOP), SACK permitted # 鍙€夐€夐」锛屽悗缁瑙?br> TCP Option - Maximum segment size: 1460 bytes # 鏈€澶ф姤鏂囩闀垮害
TCP Option - No-Operation (NOP) # 鏃犳搷浣?br> TCP Option - Window scale: 8 (multiply by 256) # 绐楀彛鎵╁ぇ鍥犲瓙
TCP Option - No-Operation (NOP)
TCP Option - No-Operation (NOP)
TCP Option - SACK permitted
# server鐨勫搷搴旀姤鏂囧拰SYN鎶ユ枃
Transmission Control Protocol, Src Port: 1883, Dst Port: 1682, Seq: 0, Ack: 1, Len: 0
Source Port: 1883
Destination Port: 1682
Sequence number: 0 (relative sequence number)
Acknowledgment number: 1 (relative ack number) # client鐨凷quence number plus one
1000 .... = Header Length: 32 bytes (8)
Flags: 0x012 (SYN, ACK) # 璁剧疆SYN鍜孉CK锛堝搷搴旓級
Window size value: 14600
Checksum: 0xfd7c [unverified]
Urgent pointer: 0
Options: (12 bytes), Maximum segment size, No-Operation (NOP), No-Operation (NOP), SACK permitted, No-Operation (NOP), Window scale
TCP Option - Maximum segment size: 1412 bytes
TCP Option - No-Operation (NOP)
TCP Option - No-Operation (NOP)
TCP Option - SACK permitted
TCP Option - No-Operation (NOP)
TCP Option - Window scale: 6 (multiply by 64)
# client鐨勫搷搴旀姤鏂?br>Transmission Control Protocol, Src Port: 1682, Dst Port: 1883, Seq: 1, Ack: 1, Len: 0
Source Port: 1682
Destination Port: 1883
Sequence number: 1 (relative sequence number)
Acknowledgment number: 1 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x010 (ACK)
Window size value: 259
Checksum: 0xa6e7 [unverified]
Urgent pointer: 0
锛?锛夎繛鎺ョ粓姝㈠崗璁?/h4>
Client鍙戦€丗IN鎶ユ枃锛屾鏃禖lient涓嶅啀鍙戦€佷笟鍔℃暟鎹埌Server锛屽苟绛夊緟Server鐨勫搷搴旀姤鏂囷紙Client搴旂敤绋嬪簭鍏抽棴锛?/p>
Server鏀跺埌Client鐨勬姤鏂囷紝鍝嶅簲ACK鎶ユ枃銆?/p>
Server鍙戦€丗IN鎶ユ枃锛屾鏃跺弻鏂归兘涓嶅啀鍙戦€佷笟鍔℃暟鎹暟鎹紝骞剁瓑寰匔lient鐨勫搷搴旀姤鏂囷紙Server搴旂敤绋嬪簭鍏抽棴锛夛級
Server鏀跺埌Client鐨凙CK鎶ユ枃鍗崇粓姝㈣繛鎺ャ€?/p>
锛?锛塛ireShark鎶撳寘鍒嗘瀽姝e父鍏抽棴
# Client鍙戦€丗IN鎶ユ枃
Transmission Control Protocol, Src Port: 1682, Dst Port: 1883, Seq: 3, Ack: 1, Len: 0
Source Port: 1682
Destination Port: 1883
Sequence number: 3 (relative sequence number)
Acknowledgment number: 1 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x011 (FIN, ACK) # ACK鏄敱浜庨渶瑕佸搷搴斿厛鍓嶇殑浜や簰
Window size value: 259
Checksum: 0xa6e7 [unverified]
Urgent pointer: 0
# Server鍙戦€丄CK
Transmission Control Protocol, Src Port: 1883, Dst Port: 1682, Seq: 1, Ack: 4, Len: 0
Source Port: 1883
Destination Port: 1682
Sequence number: 1 (relative sequence number)
Acknowledgment number: 4 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x011 (FIN, ACK)
Window size value: 229
Checksum: 0x759f [unverified]
Urgent pointer: 0
# Server鍙戦€丗IN
Transmission Control Protocol, Src Port: 1883, Dst Port: 1682, Seq: 1, Ack: 4, Len: 0
Source Port: 1883
Destination Port: 1682
Sequence number: 1 (relative sequence number)
Acknowledgment number: 4 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x011 (FIN, ACK)
Window size value: 229
Checksum: 0x759f [unverified]
Urgent pointer: 0
# Client鍙戦€丄CK
Transmission Control Protocol, Src Port: 1682, Dst Port: 1883, Seq: 4, Ack: 2, Len: 0
Source Port: 1682
Destination Port: 1883
Sequence number: 4 (relative sequence number)
Acknowledgment number: 2 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x010 (ACK)
Window size value: 259
Checksum: 0xa6e7 [unverified]
Urgent pointer: 0
2 杩炴帴寤虹珛鐨勮秴鏃堕噸璇?/h3>
绗竴娆¤秴鏃?/p>
6绉掑悗閲嶈瘯
24绉掑悗閲嶈瘯
......
闈炲浐瀹氾紝鍙皟鏁?/p>
3 鏈€澶ф姤鏂囨闀垮害锛歁SS
鏈€澶ф姤鏂囬暱搴︼紙MSS锛夎〃绀篢CP浼犲線鍙︿竴绔殑鏈€澶у潡鏁版嵁鐨勯暱搴︺€?/p>
榛樿536瀛楄妭锛岃秴鍑洪渶瑕佸垎鑺傦紙Segment锛夛紝璇ュ€兼潵婧愪簬IPv4鐨勬渶灏忛噸缁勭紦鍐插尯澶у皬锛?76瀛楄妭锛夛紝IP棣栭儴+TCP棣栭儴涓?0瀛楄妭锛屾墍浠ヤ紶杈撴暟鎹负576-40=536瀛楄妭銆?/p>
4 TCP鐨勫崐鍏抽棴
绗竴娆¤秴鏃?/p>
6绉掑悗閲嶈瘯
24绉掑悗閲嶈瘯
......
闈炲浐瀹氾紝鍙皟鏁?/p>
鏈€澶ф姤鏂囬暱搴︼紙MSS锛夎〃绀篢CP浼犲線鍙︿竴绔殑鏈€澶у潡鏁版嵁鐨勯暱搴︺€?/p>
榛樿536瀛楄妭锛岃秴鍑洪渶瑕佸垎鑺傦紙Segment锛夛紝璇ュ€兼潵婧愪簬IPv4鐨勬渶灏忛噸缁勭紦鍐插尯澶у皬锛?76瀛楄妭锛夛紝IP棣栭儴+TCP棣栭儴涓?0瀛楄妭锛屾墍浠ヤ紶杈撴暟鎹负576-40=536瀛楄妭銆?/p>
TCP鎻愪緵浜嗚繛鎺ョ殑涓€绔湪缁撴潫瀹冪殑鍙戦€佸悗杩樿兘鎺ュ彈鏉ヨ嚜鍙︿竴绔暟鎹殑鑳藉姏銆?/p>
鍗虫垜宸茬粡瀹屾垚浜嗘暟鎹紶閫侊紝鍥犳鍙戦€佷竴涓枃浠剁粨鏉燂紙FIN锛夌粰鍙︿竴绔紝浣嗘垜杩樻兂鎺ユ敹鍙︿竴绔彂鏉ョ殑鏁版嵁锛岀洿鍒板畠缁欐垜鍙戞潵鏂囦欢缁撴潫锛團IN锛?/p>
5 澶嶄綅鎶ユ枃娈碉細RST
锛?锛夊彂鍒颁笉瀛樺湪鐨勭鍙g殑杩炴帴璇锋眰
锛?锛夊紓甯哥粓姝竴涓繛鎺?/h4>
# 鏌愪竴绔洿鎺ュ叧闂繛鎺?br>Transmission Control Protocol, Src Port: 2446, Dst Port: 1883, Seq: 1, Ack: 1, Len: 0
Source Port: 2446
Destination Port: 1883
Sequence number: 1 (relative sequence number)
Acknowledgment number: 1 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x014 (RST, ACK) # 澶嶄綅鎶ユ枃
Window size value: 0
Checksum: 0xa6e7 [unverified]
Urgent pointer: 0
浼樼偣
搴旂敤绋嬪簭涓㈠純浠讳綍浠e彂鐨勬暟鎹苟绔嬪嵆鍙戦€佸浣嶆姤鏂囨
RST鐨勬帴鏀舵柟浼氬尯鍒嗗彟涓€绔墽琛岀殑鏄紓甯稿叧闂繕鏄甯稿叧闂?/p>
锛?锛夋娴嬪崐鎵撳紑杩炴帴
鍗婃墦寮€锛氫竴鏂圭粓姝紝涓€鏂硅繕涓嶇煡閬撱€?/p>
鍑虹幇鍘熷洜锛氭帀鐢碉紙妯℃嫙鏈虹洿鎺ュ叧闂嵆鍙級
6 鍚屾椂鎵撳紑
# 鏌愪竴绔洿鎺ュ叧闂繛鎺?br>Transmission Control Protocol, Src Port: 2446, Dst Port: 1883, Seq: 1, Ack: 1, Len: 0
Source Port: 2446
Destination Port: 1883
Sequence number: 1 (relative sequence number)
Acknowledgment number: 1 (relative ack number)
0101 .... = Header Length: 20 bytes (5)
Flags: 0x014 (RST, ACK) # 澶嶄綅鎶ユ枃
Window size value: 0
Checksum: 0xa6e7 [unverified]
Urgent pointer: 0
浼樼偣
搴旂敤绋嬪簭涓㈠純浠讳綍浠e彂鐨勬暟鎹苟绔嬪嵆鍙戦€佸浣嶆姤鏂囨
RST鐨勬帴鏀舵柟浼氬尯鍒嗗彟涓€绔墽琛岀殑鏄紓甯稿叧闂繕鏄甯稿叧闂?/p>
鍗婃墦寮€锛氫竴鏂圭粓姝紝涓€鏂硅繕涓嶇煡閬撱€?/p>
鍑虹幇鍘熷洜锛氭帀鐢碉紙妯℃嫙鏈虹洿鎺ュ叧闂嵆鍙級
鍙屾柟鍚屾椂鎵ц涓诲姩鎵撳紑锛屽嵆姣忎竴鏂归兘鍙戦€丼YN锛屼絾鏈€缁堝彧寤虹珛浜嗕竴涓繛鎺ャ€?/p>
妯℃嫙杩欎釜鍙互閫氳繃杈i浮VPN杩涜娴嬭瘯锛屽浜氶┈閫婄殑鍏嶈垂浜戯紙鍗冲線杩旀椂闂存瘮杈冮暱锛屼究浜庢ā鎷燂級銆?/p>
7 鍚屾椂鍏抽棴
鍚屾椂鍏抽棴涓庢甯稿叧闂娇鐢ㄧ殑娈典氦鎹㈡暟鐩浉鍚屻€?/p>
8 TCP閫夐」
閫夐」琛ㄧ粨鏉燂細kind=0锛?瀛楄妭锛?/p>
鏃犳搷浣滐細kind=1锛?瀛楄妭锛?/p>
鏈€澶ф姤鏂囬暱搴︼細kind=2锛?瀛楄妭锛夛紝len=4锛?瀛楄妭锛夛紝鏈€澶ф姤鏂囨闀垮害锛?瀛楄妭锛?/p>
绐楀彛鎵╁ぇ鍥犲瓙锛歬ind=3锛?瀛楄妭锛夛紝len=3锛?瀛楄妭锛夛紝绉讳綅鏁帮紙1瀛楄妭锛?/p>
鏃堕棿鎴筹細kind=8锛?瀛楄妭锛夛紝len=10锛?瀛楄妭锛夛紝鏃堕棿鎴冲€硷紙4瀛楄妭锛夛紝鏃堕棿鎴冲洖鏄惧簲绛旓紙4瀛楄妭锛?/p>
# 鍙戦€丮SS
TCP Option - Maximum segment size: 1460 bytes
Kind: Maximum Segment Size (2)
Length: 4
MSS Value: 1460
# NOP
TCP Option - No-Operation (NOP)
Kind: No-Operation (1)
# 绐楀彛鎵╁ぇ鍥犲瓙
TCP Option - Window scale: 8 (multiply by 256)
Kind: Window Scale (3)
Length: 3
Shift count: 8
涓?鏈潵璁″垝
瀛︿範TCP鏄负浜嗘洿濂藉湴鐞嗚ВMQTT鍗忚锛堝嵆鑷《鍚戜笅鐨勫涔犳柟寮忥紝浠ュ墠鑷簳鍚戜笂瀛﹁繃涓€娈垫椂闂达紝鏁堟灉涓€鑸紝鍥犱负娌℃湁搴旂敤鍦烘櫙锛?/p>
TCP瀛﹀畬涔嬪悗锛屽皢琛ュ厖HTTP鍗忚锛堝熀浜嶵CP鍗忚锛?/p>
HTTP鍗忚涔嬪悗锛屽皢瀛︿範WebSocket鍗忚锛屽苟鏈€缁堝洖鍒癕QTT鍗忚锛堣兘澶熷熀浜嶹ebSocket鍗忚杩涜浼犺緭锛?/p>
鍘熸枃锛?span class="code-snippet__symbol">https://www.cnblogs.com/linzhanfly/p/9960932.html
-娣卞叆鍘熺悊-
鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧
以上是关于的主要内容,如果未能解决你的问题,请参考以下文章