英文:
How to determine unknown socket options?
问题
在反向工程一个专为Android设计的so库时,我看到了以下用于TCP连接的代码行。
int v28[2];
v28[1] = 0;
v28[0] = 10;
setsockopt(socket_ref, 1, 21, v28, 8);
setsockopt(socket_ref, 1, 20, v28, 8);
第二个参数将级别定义为SOL_SOCKET。但选项值20和21是未知的。有人能解释一下发生了什么吗?
(我阅读了许多不同网站的文档,希望找到这些选项的解释。但我没有找到任何解释选项20和21的文档。)
英文:
While reverse engineering a so library designed for android, I saw following code lines for a tcp connection.
int v28[2];
v28[1] = 0;
v28[0] = 10;
setsockopt(socket_ref, 1, 21, v28, 8);
setsockopt(socket_ref, 1, 20, v28, 8);
Second parameter defines level as SOL_SOCKET. But option values 20 and 21 is unknown. Can someone explain what is going on?
(I read many documentations from different websites with hoping to find those options. But I didn't find any documentation that explains options 20 and 21.)
答案1
得分: 2
你可能不会在文档中找到这些特定代码映射的详细信息,因为这是您的环境的实现细节。您可以在定义 SOL_SOCKET
的系统头文件中搜索,看看是否可以找到匹配的选项。
例如,在我的 CentOS 7 机器上,我搜索了 SOL_SOCKET
级别的定义:
[dbush@db-centos7 ~]$ grep -r SOL_SOCKET /usr/include
/usr/include/asm-generic/socket.h:#define SOL_SOCKET 1
/usr/include/linux/atm.h: * SOL_SOCKET is 0xFFFF, so that's a bit of a problem
/usr/include/linux/dn.h: * DNPROTO_NSP can't be the same as SOL_SOCKET,
我在 /usr/include/asm-generic/socket.h
中找到了它。查看这个文件,我找到了以下内容:
/* 用于 setsockopt(2) */
#define SOL_SOCKET 1
#define SO_DEBUG 1
#define SO_REUSEADDR 2
#define SO_TYPE 3
#define SO_ERROR 4
#define SO_DONTROUTE 5
#define SO_BROADCAST 6
#define SO_SNDBUF 7
#define SO_RCVBUF 8
#define SO_SNDBUFFORCE 32
#define SO_RCVBUFFORCE 33
#define SO_KEEPALIVE 9
#define SO_OOBINLINE 10
#define SO_NO_CHECK 11
#define SO_PRIORITY 12
#define SO_LINGER 13
#define SO_BSDCOMPAT 14
#define SO_REUSEPORT 15
#ifndef SO_PASSCRED /* powerpc only differs in these */
#define SO_PASSCRED 16
#define SO_PEERCRED 17
#define SO_RCVLOWAT 18
#define SO_SNDLOWAT 19
#define SO_RCVTIMEO 20
#define SO_SNDTIMEO 21
#endif
所以,至少在我的系统上,选项 20 和 21 分别是 SO_RCVTIMEO
和 SO_SNDTIMEO
。这可能在您的系统上有所不同,因此请搜索头文件以确保。
英文:
You likely won't find documentation on what those specific codes map to, as that's an implementation detail of your environment. What you can do is search the system header files where SOL_SOCKET
is defined and see if you can find the matching options.
For example, on my CentOS 7 machine, I searched for the defintion of the SOL_SOCKET
level:
[dbush@db-centos7 ~]$ grep -r SOL_SOCKET /usr/include
/usr/include/asm-generic/socket.h:#define SOL_SOCKET 1
/usr/include/linux/atm.h: * SOL_SOCKET is 0xFFFF, so that's a bit of a problem
/usr/include/linux/dn.h: * DNPROTO_NSP can't be the same as SOL_SOCKET,
Where I found it in /usr/include/asm-generic/socket.h. Looking at this file, I found this:
/* For setsockopt(2) */
#define SOL_SOCKET 1
#define SO_DEBUG 1
#define SO_REUSEADDR 2
#define SO_TYPE 3
#define SO_ERROR 4
#define SO_DONTROUTE 5
#define SO_BROADCAST 6
#define SO_SNDBUF 7
#define SO_RCVBUF 8
#define SO_SNDBUFFORCE 32
#define SO_RCVBUFFORCE 33
#define SO_KEEPALIVE 9
#define SO_OOBINLINE 10
#define SO_NO_CHECK 11
#define SO_PRIORITY 12
#define SO_LINGER 13
#define SO_BSDCOMPAT 14
#define SO_REUSEPORT 15
#ifndef SO_PASSCRED /* powerpc only differs in these */
#define SO_PASSCRED 16
#define SO_PEERCRED 17
#define SO_RCVLOWAT 18
#define SO_SNDLOWAT 19
#define SO_RCVTIMEO 20
#define SO_SNDTIMEO 21
#endif
So, at least on my system, options 20 and 21 are SO_RCVTIMEO
and SO_SNDTIMEO
respectively. These may differ on your system, so search the header files to be sure.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论