日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言sgoto 标志位,如何在Go中设置TCP数据包的“不分段”标志位?(How to set “don't fragment” flag bit for TCP packet in Go?)...

發(fā)布時間:2025/3/12 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言sgoto 标志位,如何在Go中设置TCP数据包的“不分段”标志位?(How to set “don't fragment” flag bit for TCP packet in Go?)... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

如何在Go中設置TCP數(shù)據(jù)包的“不分段”標志位?(How to set “don't fragment” flag bit for TCP packet in Go?)

我打算在Go中設置“do not fragment”標志位,與C中的這個標志位相同。我檢查了常量列表,但沒有找到該選項。 那么Go的相應選項是什么?

提前致謝!

I intend to set the "don't fragment" flag bit in Go, the same thing as this post while it is in C. I checked the constant list but I didn't find this option. So what is the corresponding option in Go?

Thanks in advance!

原文:https://stackoverflow.com/questions/37761538

更新時間:2019-11-05 23:35

最滿意答案

如何在Go中設置TCP數(shù)據(jù)包的“不分段”標志位?

首先你應該知道TCP確實不喜歡IP碎片。 大部分(如果不是全部)主要實現(xiàn)通過使用路徑MTU發(fā)現(xiàn)來避免TCP段的碎片。

TL; DR是包含TCP段的典型IP包具有DF位置位。 你可以(也應該)嘗試一下。 在這里,我嗅探了我的機器和stackoverflow.com之間的幾秒鐘的流量:

% tshark -w /tmp/tcp.pcap tcp and host stackoverflow.com

% tshark -r /tmp/tcp.pcap -T fields -e ip.flags | sort | uniq -c

186 0x00000002

0x02表示DF位置位。 我承認在其他捕獲中,我看到了沒有DF位的IP??數(shù)據(jù)包中的偶爾TCP段; 我懷疑rfc1191對此有解釋。

現(xiàn)在回到你的問題,我認為沒有可移植的方式來設置DF位,這是一個更廣泛的問題(甚至沒有POSIX便攜式方法)。 golang.org/x/sys下的相關軟件包中可能會有一個(可能)逃脫孵化器。

例如,在支持IP_DONTFRAG的Unix(如FreeBSD)上,可以使用unix.SetsockoptInt并挖掘相關的常量值。

在Linux上沒有IP_DONTFRAG ,正如你從你鏈接的問題中發(fā)現(xiàn)的那樣。 解決方法似乎是使用IP_MTU_DISCOVER ,它恰好在unix包中作為常量提供。 你可以使用相同的unix.SetsockoptInt來設置它。

How to set "don't fragment" flag bit for TCP packet in Go?

First up you should know that TCP really doesn't like IP fragments. Most if not all major implementations avoid fragmentation for TCP segments by using path MTU discovery.

The TL;DR is that the typical IP packet containing a TCP segment has a DF bit set. You can (and should) try this out. Here I am sniffing a few seconds of traffic between my machine and stackoverflow.com:

% tshark -w /tmp/tcp.pcap tcp and host stackoverflow.com

% tshark -r /tmp/tcp.pcap -T fields -e ip.flags | sort | uniq -c

186 0x00000002

0x02 means the DF bit is set. I confess in other captures I have seen the occasional TCP segment in an IP packet without a DF bit; I suspect rfc1191 has an explanation for this.

Now back to your question, I think there's no portable way to set the DF bit and this is a more widespread question (there isn't even a POSIX-portable way). There is (likely) an escape hatch in the relevant package for your implementation under golang.org/x/sys.

For example, on a Unix that supports IP_DONTFRAG such as FreeBSD one could use unix.SetsockoptInt and dig the relevant constant value.

On Linux there is not IP_DONTFRAG, as you discovered from the question you linked. The workaround seems to be to use IP_MTU_DISCOVER which happens to be available as a constant in the unix package. You can use that same unix.SetsockoptInt to set it.

2017-05-23

相關問答

自己解決。 指向發(fā)送者IP的是sin.sin_addr.s_addr ,但它必須是服務器ip! 要小心,因為在代碼中看到這樣的錯誤并不容易! :-) 現(xiàn)在數(shù)據(jù)包包含正確的MAC信息。 接下來的問題是為什么我沒有從服務器獲得任何syn-acks ,但我會為這個問題提出一個新問題。 Solved it myself. It was the sin.sin_addr.s_addr that pointed at the senders IP, but it had to be the servers i

...

如何在Go中設置TCP數(shù)據(jù)包的“不分段”標志位? 首先你應該知道TCP確實不喜歡IP碎片。 大部分(如果不是全部)主要實現(xiàn)通過使用路徑MTU發(fā)現(xiàn)來避免TCP段的碎片。 TL; DR是包含TCP段的典型IP包具有DF位置位。 你可以(也應該)嘗試一下。 在這里,我嗅探了我的機器和stackoverflow.com之間的幾秒鐘的流量: % tshark -w /tmp/tcp.pcap tcp and host stackoverflow.com

% tsha

...

前一段時間想出來但忘記發(fā)布我發(fā)現(xiàn)的內容。 答案是你不可能真的。 在udp頭文件中設置標志需要創(chuàng)建原始套接字,這需要root權限,這在iOS中是不具備的。 謝謝蘋果! 幸運的是,在我的特殊情況下,我能夠讓我的客戶改進他們的固件。 Figured this out awhile ago but forgot to post what I found. The answer is you can't really. Setting flags on the udp header requires the

...

這看起來很好。 TH_SYN是單個位,因此如果在th_flags設置該位,則表達式將為真(非零)。 That looks fine to me. TH_SYN is a single bit, so that expression will be true (nonzero) if that bit is set in th_flags.

tcp_dissect_pdus沒有wslua API。 但你可以自己實現(xiàn)它。 如果你想組裝跨越兩個或更多數(shù)據(jù)包的pdu,那就相當簡單了: function slicer.dissector(tvb, pinfo, tree)

...

local pdu_length = get_pdu_length(...)

if pdu_length > tvb:len() then

pinfo.desegment_len = pdu_length - tvb:len(

...

就像@Sivir所說,你需要建立三次握手,因為你想使用TCP協(xié)議。 從理論上講,握手應該是這樣的 YourProgram :發(fā)送SYN數(shù)據(jù)包 服務器 :發(fā)送SYNACK數(shù)據(jù)包 YourProgram :發(fā)送ACK數(shù)據(jù)包 有關這方面的更多信息,請點擊此處 。 Like @Sivir said you need to establish a three way handshake because you want to use the TCP protocol. In theory the hands

...

以這種方式調整TCP連接是不可能的,控制它是沒有意義的。 如果您需要使用此行為產(chǎn)生流量,則無法使用普通的TCP套接字,但需要使用原始套接字 ,您可以根據(jù)需要設置標頭。 您當然需要在應用程序中重新實現(xiàn)所需的TCP連接的所有部分才能實現(xiàn)此功能。 Tuning a TCP connection this way can not be done and it would not make really sense to control it. If you need to produce traffic

...

發(fā)送字符串時,可能會在多個TCP數(shù)據(jù)包中發(fā)送。 如果發(fā)送多個字符串,它們可能都在一個TCP數(shù)據(jù)包中發(fā)送。 您沒有接觸到數(shù)據(jù)包,TCP套接字只是一個恒定的數(shù)據(jù)流。 不要指望對recv()每次調用都與recv()的單個調用配對,因為這不是真的。 您可以發(fā)送"abcd"和"efg" ,并可以從recv()讀取"a" , "bcde"和"fg" 。 最好在收到數(shù)據(jù)后立即發(fā)送數(shù)據(jù),以便網(wǎng)絡堆棧盡可能快地提供有關您要發(fā)送的內容的信息。 它將確切地決定做什么。 您可以根據(jù)需要發(fā)送大字符串,如有必要,它將被分解為

...

不,因為永遠不會發(fā)送目標主機名。 發(fā)件人使用DNS查找要與之通信的主機的IP地址,然后將數(shù)據(jù)包發(fā)送到該IP地址。 (更低級別,IP地址轉換為MAC地址,這是硬件層使用的) 您的TCP套接字層應該允許您查看套接字的源和目標IP地址,然后您必須執(zhí)行反向DNS查找以將其轉換回主機名。 但請記住,一個IP地址可以轉換為多個主機名... No, because the destination hostname is never sent. The sender uses DNS to find the IP

...

首先,讓我們澄清MTU和MSS之間的區(qū)別。 這些屬于堆棧的不同層(2和3)。 TCP / IP是一個非常不幸的分層蛋糕,它們都支持碎片,但不同,它們在這個問題上沒有合作。 IP碎片是TCP不知道的事情。 事實上,如果其中一個IP片段丟失,整個系列就會被宣告丟失。 TCP不是這樣:如果屬于同一TCP流的IP數(shù)據(jù)報之一丟失,并且它們被TCP分段,則只需要重新傳輸丟失的部分。 這種混亂的核心原因是路由器必須能夠在具有不同MTU的兩個物理網(wǎng)絡之間進行阻抗匹配, 而無需了解更高(TCP)協(xié)議 。 現(xiàn)在,所有

...

總結

以上是生活随笔為你收集整理的c语言sgoto 标志位,如何在Go中设置TCP数据包的“不分段”标志位?(How to set “don't fragment” flag bit for TCP packet in Go?)...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。