When I was learning network programming, I noticed two functions, namely setsockopt()
and getsockopt()
. Among them, their fourth parameter is a pointer. However, in practical use, I feel that the fourth parameter almost always transfers numbers or Boolean values. So what is the meaning of using the fourth parameter as a pointer?
// Platform used for demonstration: Windows 10
// exmple 1
BOOL enable = TRUE;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(enable));
// or
// exmple 2
DWORD size = 2048;
setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*)&size, sizeof(size));
And I have checked the relevant documents, which do not mention the usage of this parameter as a buffer for strings or similar, so I am puzzled why this parameter must be a pointer.
- getsockopt function (winsock.h)
- setsockopt function (winsock.h)
- getsockopt – get the socket options
- setsockopt – set the socket options