summaryrefslogtreecommitdiffhomepage
path: root/src/socket/ntapi_sc_getsockopt.c
blob: e70ba28c470a611dca940390171c5836cb590950 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/********************************************************/
/*  ntapi: Native API core library                      */
/*  Copyright (C) 2013--2017  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_getsockopt(
	__in	nt_socket *		hssocket,
	__in	int32_t			level,
	__in	int32_t			optname,
	__out	void *			optval,
	__in	uint32_t		optlen,
	__out	nt_iosb volatile *	iosb)
{
	nt_afd_sockopt_info afd_sockopt;

	if (!iosb)
		return NT_STATUS_INVALID_PARAMETER_6;

	/* tcp socket info? */
	if (optname == NT_SO_IOCTL_GET_TCP_INFO) {
		afd_sockopt.mode    = NT_AFD_SOCKOPT_GET | NT_AFD_SOCKOPT_SET;
		afd_sockopt.optval  = &(uint32_t){0};
		afd_sockopt.optlen  = sizeof(uint32_t);
	} else {
		afd_sockopt.mode    = NT_AFD_SOCKOPT_GET;
		afd_sockopt.optval  = 0;
		afd_sockopt.optlen  = 0;
	}

	/* afd_sockopt */
	afd_sockopt.level   = level;
	afd_sockopt.optname = optname;
	afd_sockopt.ding    = 1;

	/* ioctl */
	hssocket->iostatus = __ntapi->zw_device_io_control_file(
			hssocket->hsocket,
			hssocket->hevent,
			0,
			0,
			iosb,
			NT_AFD_IOCTL_SOCKOPT,
			&afd_sockopt,
			sizeof(afd_sockopt),
			optval,
			optlen);

	return hssocket->iostatus
		? __ntapi->sc_wait(hssocket,iosb,0)
		: NT_STATUS_SUCCESS;
}