summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-06-16 13:22:38 -0400
committermidipix <writeonce@midipix.org>2016-06-16 13:22:38 -0400
commit830346bf1600a38dbbacc569599da55895cfd033 (patch)
treea64218ef4b7fdbac932516a636f70e5078af180a
parenta867b08c1bdfa631cd117be7d23a4ad90246d27e (diff)
downloadntapi-830346bf1600a38dbbacc569599da55895cfd033.tar.bz2
ntapi-830346bf1600a38dbbacc569599da55895cfd033.tar.xz
__ntapi_sc_setsockopt(): initial implementation and integration.
-rw-r--r--include/ntapi/nt_socket.h9
-rw-r--r--include/ntapi/ntapi.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/internal/ntapi.c1
-rw-r--r--src/internal/ntapi_fnapi.h1
-rw-r--r--src/socket/ntapi_sc_setsockopt.c50
6 files changed, 63 insertions, 0 deletions
diff --git a/include/ntapi/nt_socket.h b/include/ntapi/nt_socket.h
index c6f47b9..1f8dd14 100644
--- a/include/ntapi/nt_socket.h
+++ b/include/ntapi/nt_socket.h
@@ -509,6 +509,15 @@ typedef int32_t __cdecl ntapi_sc_server_duplicate_socket(
__out nt_io_status_block * iosb __optional);
+typedef int32_t __cdecl ntapi_sc_setsockopt(
+ __in nt_socket * hssocket,
+ __in int32_t level,
+ __in int32_t optname,
+ __in const void * optval,
+ __in uint32_t optlen,
+ __out nt_io_status_block * iosb __optional);
+
+
typedef int32_t __cdecl ntapi_sc_wait(nt_socket * hssocket, nt_iosb * iosb, nt_timeout * timeout);
#endif
diff --git a/include/ntapi/ntapi.h b/include/ntapi/ntapi.h
index 17d9871..904a563 100644
--- a/include/ntapi/ntapi.h
+++ b/include/ntapi/ntapi.h
@@ -547,6 +547,7 @@ typedef struct _ntapi_vtbl {
ntapi_sc_getpeername * sc_getpeername;
ntapi_sc_server_accept_connection * sc_server_accept_connection;
ntapi_sc_server_duplicate_socket * sc_server_duplicate_socket;
+ ntapi_sc_setsockopt * sc_setsockopt;
ntapi_sc_wait * sc_wait;
/* nt_mount.h */
diff --git a/project/common.mk b/project/common.mk
index 0e3bb9a..bc41360 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -61,6 +61,7 @@ COMMON_SRCS = \
src/socket/ntapi_sc_server_accept_connection_v1.c \
src/socket/ntapi_sc_server_accept_connection_v2.c \
src/socket/ntapi_sc_server_duplicate_socket.c \
+ src/socket/ntapi_sc_setsockopt.c \
src/socket/ntapi_sc_shutdown.c \
src/socket/ntapi_sc_socket_v1.c \
src/socket/ntapi_sc_socket_v2.c \
diff --git a/src/internal/ntapi.c b/src/internal/ntapi.c
index 885fe61..451ccd7 100644
--- a/src/internal/ntapi.c
+++ b/src/internal/ntapi.c
@@ -308,6 +308,7 @@ static int32_t __fastcall __ntapi_init_once(ntapi_vtbl ** pvtbl)
__ntapi->sc_recv = __ntapi_sc_recv;
__ntapi->sc_shutdown = __ntapi_sc_shutdown;
__ntapi->sc_server_duplicate_socket = __ntapi_sc_server_duplicate_socket;
+ __ntapi->sc_setsockopt = __ntapi_sc_setsockopt;
__ntapi->sc_wait = __ntapi_sc_wait;
/* nt_mount.h */
diff --git a/src/internal/ntapi_fnapi.h b/src/internal/ntapi_fnapi.h
index a22c659..05f4707 100644
--- a/src/internal/ntapi_fnapi.h
+++ b/src/internal/ntapi_fnapi.h
@@ -203,6 +203,7 @@ ntapi_sc_getpeername __ntapi_sc_getpeername_v2;
ntapi_sc_server_accept_connection __ntapi_sc_server_accept_connection_v1;
ntapi_sc_server_accept_connection __ntapi_sc_server_accept_connection_v2;
ntapi_sc_server_duplicate_socket __ntapi_sc_server_duplicate_socket;
+ntapi_sc_setsockopt __ntapi_sc_setsockopt;
ntapi_sc_listen __ntapi_sc_listen;
ntapi_sc_accept __ntapi_sc_accept;
ntapi_sc_send __ntapi_sc_send;
diff --git a/src/socket/ntapi_sc_setsockopt.c b/src/socket/ntapi_sc_setsockopt.c
new file mode 100644
index 0000000..4989e54
--- /dev/null
+++ b/src/socket/ntapi_sc_setsockopt.c
@@ -0,0 +1,50 @@
+/********************************************************/
+/* ntapi: Native API core library */
+/* Copyright (C) 2013--2016 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.NTAPI. */
+/********************************************************/
+
+#include <psxtypes/psxtypes.h>
+#include <ntapi/nt_object.h>
+#include <ntapi/nt_file.h>
+#include <ntapi/nt_socket.h>
+#include <ntapi/ntapi.h>
+#include "ntapi_impl.h"
+
+int32_t __cdecl __ntapi_sc_setsockopt(
+ __in nt_socket * hssocket,
+ __in int32_t level,
+ __in int32_t optname,
+ __in const void * optval,
+ __in uint32_t optlen,
+ __out nt_io_status_block * iosb)
+{
+ nt_afd_sockopt_info afd_sockopt;
+ nt_io_status_block siosb;
+
+ iosb = iosb ? iosb : &siosb;
+
+ /* afd_sockopt */
+ afd_sockopt.mode = NT_AFD_SOCKOPT_SET;
+ afd_sockopt.level = level;
+ afd_sockopt.optname = optname;
+ afd_sockopt.optval = optval;
+ afd_sockopt.optlen = optlen;
+ afd_sockopt.ding = 1;
+
+ hssocket->iostatus = __ntapi->zw_device_io_control_file(
+ hssocket->hsocket,
+ hssocket->hevent,
+ 0,
+ 0,
+ iosb,
+ NT_AFD_IOCTL_SOCKOPT,
+ &afd_sockopt,
+ sizeof(afd_sockopt),
+ 0,
+ 0);
+
+ return hssocket->iostatus
+ ? __ntapi->sc_wait(hssocket,iosb,0)
+ : NT_STATUS_SUCCESS;
+}