是否可以从命令行 setsockopt()
我需要将程序应用程序的sk_rcvlowat
更改为性能测试。有没有办法从命令行更改套接字选项?否则,我们必须更改应用程序的所有源代码并重新编译。我猜想每个套接字都与一个inode
关联,这样我们就可以通过inode
更改套接字选项。
顺便说一句,请任何人告诉我进程创建“套接字文件”时它所在的位置。我已经检查过 /proc/
但它们只是像这样的符号链接 10 ->;套接字:[13895]
任何建议表示赞赏。提前致谢。
I need to change the sk_rcvlowat
of program applications to to performance test. Is there a way to change the socket options from command line? Otherwise, we have to change all the source code of application program and re-compile them. I guess that each socket is associated with an inode
, so that we can change the socket option via the inode
.
By the way, please can anyone show me where the "socket file" located when the process created it. I have already checked /proc/<pid>/fd/<fd[X]>
but they are only symbolic links like this one 10 -> socket:[13895]
Any suggestions are appreciated. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个包装器库,它将拦截对
setsockopt
的所有调用,并能够更改一些参数。如果您的应用程序调用了setsockopt,则此方法有效。在另一种情况下,您可以使用相同的方法包装不同的函数,例如socket
。在socket
的包装器中,您需要使用 __socket 创建一个套接字,然后更改您想要的任何参数。包装库必须是动态库,具有
setsockopt
功能。该函数允许被glibc重载。然后,按如下方式启动您的程序:该库将被注入(链接)到程序中,并将替换setsockopt函数。
这仅适用于动态链接的程序(使用 ldd ./you_program 检查它 - 如果是动态链接的,将会有一些 /lib/*.so )。
可以使用
__
前缀:__setsockopt
或使用dlsym(RTLD_NEXT, "setsockopt");
从代码中调用原始函数。一些示例(不是setsockopt,而是预加载包装器的想法):http://scaryreasoner.wordpress.com/2007/11/17/using-ld_preload-libraries-and-glibc-backtrace-function-for-debugging/ 或http://developers.sun.com/solaris/articles/lib_interposers_code.html
编译为动态库:
You can create a wrapper library, which will intercept all calls to
setsockopt
and will be able to change some parameters. This works if your application have the call to setsockopt. In another case, you can wrap different function, e.g.socket
using the same approach. In wrapper ofsocket
you need to create a socket with __socket and then change any parameter you want.Wrapper library must be a dynamic one, with
setsockopt
function. This function is allowed to be overloaded by glibc. Then, start your programm as follows:The library will be injected (linked) into programm and will replace the setsockopt function.
This works only with dynamically linked programms (check it with
ldd ./you_program
- there will be some /lib/*.so if it is dynamically linked).Original function can be called from your code with
__
prefix:__setsockopt
or usingdlsym(RTLD_NEXT, "setsockopt");
.Some examples (not a setsockopt, but the idea of preload wrapper): http://scaryreasoner.wordpress.com/2007/11/17/using-ld_preload-libraries-and-glibc-backtrace-function-for-debugging/ or http://developers.sun.com/solaris/articles/lib_interposers_code.html
Compile to dynamic library with: