Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit ac2efc1

Browse files
authored
Add support for getsockopt() (#40)
* Add support for getsockopt() * Repair Windows build
1 parent 1e108d9 commit ac2efc1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

libndt.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,16 +1516,20 @@ bool Client::query_mlabns_curl(const std::string &url, long timeout,
15161516

15171517
#ifdef _WIN32
15181518
#define AS_OS_SOCKLEN(n) ((int)n)
1519+
#define AS_OS_SOCKLEN_STAR(n) ((int *)n)
15191520
#define AS_OS_BUFFER(b) ((char *)b)
15201521
#define AS_OS_BUFFER_LEN(n) ((int)n)
15211522
#define OS_SSIZE_MAX INT_MAX
15221523
#define OS_EINVAL WSAEINVAL
1524+
#define AS_OS_OPTION_VALUE(x) ((char *)x)
15231525
#else
15241526
#define AS_OS_SOCKLEN(n) ((socklen_t)n)
1527+
#define AS_OS_SOCKLEN_STAR(n) ((socklen_t *)n)
15251528
#define AS_OS_BUFFER(b) ((char *)b)
15261529
#define AS_OS_BUFFER_LEN(n) ((size_t)n)
15271530
#define OS_SSIZE_MAX SSIZE_MAX
15281531
#define OS_EINVAL EINVAL
1532+
#define AS_OS_OPTION_VALUE(x) ((void *)x)
15291533
#endif
15301534

15311535
int Client::get_last_system_error() noexcept {
@@ -1618,5 +1622,12 @@ int Client::fcntl3i(Socket s, int cmd, int arg) noexcept {
16181622
}
16191623
#endif
16201624

1625+
int Client::getsockopt(int socket, int level, int name, void *value,
1626+
SockLen *len) noexcept {
1627+
static_assert(sizeof(*len) == sizeof(int), "invalid SockLen size");
1628+
return ::getsockopt(socket, level, name, AS_OS_OPTION_VALUE(value),
1629+
AS_OS_SOCKLEN_STAR(len));
1630+
}
1631+
16211632
} // namespace libndt
16221633
} // namespace measurement_kit

libndt.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ class Client {
380380
virtual int fcntl3i(Socket s, int cmd, int arg) noexcept;
381381
#endif
382382

383+
virtual int getsockopt(int socket, int level, int name, void *value,
384+
SockLen *len) noexcept;
385+
383386
private:
384387
class Impl;
385388
std::unique_ptr<Impl> impl;

0 commit comments

Comments
 (0)