Blame src/socket/ntapi_sc_getsockopt.c

419228
/********************************************************/
419228
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
419228
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
419228
/********************************************************/
419228
419228
#include <psxtypes/psxtypes.h>
419228
#include <ntapi/nt_object.h>
419228
#include <ntapi/nt_file.h>
419228
#include <ntapi/nt_socket.h>
419228
#include <ntapi/ntapi.h>
419228
#include "ntapi_impl.h"
419228
419228
int32_t __cdecl __ntapi_sc_getsockopt(
419228
	__in	nt_socket *		hssocket,
419228
	__in	int32_t			level,
419228
	__in	int32_t			optname,
419228
	__out	void *			optval,
419228
	__in	uint32_t		optlen,
2e04e9
	__out	nt_iosb volatile *	iosb)
419228
{
419228
	nt_afd_sockopt_info afd_sockopt;
419228
419228
	if (!iosb)
419228
		return NT_STATUS_INVALID_PARAMETER_6;
419228
c8cd7a
	/* tcp socket info? */
c8cd7a
	if (optname == NT_SO_IOCTL_GET_TCP_INFO) {
c8cd7a
		afd_sockopt.mode    = NT_AFD_SOCKOPT_GET | NT_AFD_SOCKOPT_SET;
c8cd7a
		afd_sockopt.optval  = &(uint32_t){0};
c8cd7a
		afd_sockopt.optlen  = sizeof(uint32_t);
c8cd7a
	} else {
c8cd7a
		afd_sockopt.mode    = NT_AFD_SOCKOPT_GET;
c8cd7a
		afd_sockopt.optval  = 0;
c8cd7a
		afd_sockopt.optlen  = 0;
c8cd7a
	}
c8cd7a
419228
	/* afd_sockopt */
419228
	afd_sockopt.level   = level;
419228
	afd_sockopt.optname = optname;
419228
	afd_sockopt.ding    = 1;
419228
c8cd7a
	/* ioctl */
419228
	hssocket->iostatus = __ntapi->zw_device_io_control_file(
419228
			hssocket->hsocket,
419228
			hssocket->hevent,
419228
			0,
419228
			0,
419228
			iosb,
419228
			NT_AFD_IOCTL_SOCKOPT,
419228
			&afd_sockopt,
419228
			sizeof(afd_sockopt),
419228
			optval,
419228
			optlen);
419228
419228
	return hssocket->iostatus
419228
		? __ntapi->sc_wait(hssocket,iosb,0)
419228
		: NT_STATUS_SUCCESS;
419228
}