设置TCP用C接收窗口,并在Linux中使用tcpdump工作 [英] Setting TCP receive window in C and working with tcpdump in Linux

查看:466
本文介绍了设置TCP用C接收窗口,并在Linux中使用tcpdump工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行的Linux机器上运行2.6.9-55.ELsmp,x86_64的。

I am running a Linux box running 2.6.9-55.ELsmp, x86_64.

我想设置TCP接收窗口通过使用setsockopt()函数中使用C.我尝试以下方法:

I am trying to set the TCP receive window by using the setsockopt() function using C. I try the following:

rwnd = 1024;
setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&rwnd, sizeof(rwnd));

上面的code段是从服务器接收数据的客户端程序。当我开球的程序来接收并观察tcpdump的输出,我观察窗口谈判,像这样:

The code segment above is in a client program that receives data from a server. When I kick off the program to receive and observe tcpdump output, I observe window negotiation like so:

11:34:40.257755 IP clientReceiver.42464 > serverSender.8991: 
S 1742042788:1742042788(0) win 5840 
<mss 1460,sackOK,timestamp 1688222886 0,nop,wscale 2>

我们看到,客户端程序其实是在谈判从我的客户端程序都设置不同的窗口。然而,我怎么能跨preT史蒂芬的文本(TCP / IP详解,卷1)第20.4节,我相信你使用setsockopt影响,他指的是在第二块引用什么第20.4节()调用我使用(见上文)。

We see that the client program is in fact negotiating a window different from what I have set in the client program. However, from how I can interpret Steven's text ("TCP/IP Illustrated, Volume 1") Section 20.4, I believe you effect what he refers to in the second block quote in Section 20.4 using the setsockopt() call I use (see above).

我想明白的地方我已经错了。

I'd like to understand where I have gone wrong.

也许什么史蒂文斯在说我跨pretation不正确。在这种情况下,你可以指出我设置接收缓冲区大小的正确方法是什么?由于我的困惑的证明,我是指Linux的TCP套接字手册页在 http://linux.die.net/man/ 7 / TCP (见SO_RCFBUF评论)

Perhaps my interpretation of what Stevens is saying is incorrect. In that case, could you point me to the correct way of setting the receive buffer size? As a proof of my confusion, I refer the Linux TCP sockets man page at http://linux.die.net/man/7/tcp (see comment on SO_RCFBUF).

那我在这个故事里缺少什么?我如何控制接收缓冲区的大小(并将其显示在tcpdump的输出)?请注意,我指这里的套接字选项SO_RCFBUF的设置 - 我明白那是在SYN窗口谈判中显示的内容。

What am I missing in this story? How do I control the receive buffer size (and have it show in the tcpdump output)? Please note that I allude to here a setting of the socket option SO_RCFBUF--I understand that's what shows up in the window negotiation in the SYN.

任何输入AP preciated。

Any input is appreciated.

推荐答案

您也需要使用 TCP_WINDOW_CLAMP

rcvbuf = 2048;
setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)& rcvbuf, sizeof(rcvbuf));
clamp = 1024;
setsockopt(sock, SOL_SOCKET, TCP_WINDOW_CLAMP, (char *)& clamp, sizeof(clamp));

请注意的rcvbuf是夹紧两次,也可能是更。你可以让它自动调谐,窗夹具仍然可以工作。这是不可移植的。

Note the rcvbuf is twice the clamp, it could be more. You can let it autotune, the window clamp will still work. This isn't portable.

这篇关于设置TCP用C接收窗口,并在Linux中使用tcpdump工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆