summaryrefslogtreecommitdiffhomepage
path: root/src/socket/ntapi_sc_server_duplicate_socket.c
blob: b8f3e9f2d981c9e3d3fa1bb61efbdedd4b4857fe (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
/********************************************************/
/*  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_server_duplicate_socket(
	__in	nt_socket *		hssock_listen,
	__in	nt_socket *		hssock_dedicated,
	__in	nt_afd_accept_info *	accept_info,
	__out	nt_io_status_block *	iosb		__optional)
{
	nt_afd_duplicate_info	duplicate_info;
	nt_io_status_block	siosb;

	iosb = iosb ? iosb : &siosb;

	/* duplicate_info */
	duplicate_info.unknown  = 0;
	duplicate_info.sequence = accept_info->sequence;
	duplicate_info.hsocket_dedicated = hssock_dedicated->hsocket;

	hssock_dedicated->iostatus = __ntapi->zw_device_io_control_file(
			hssock_listen->hsocket,
			hssock_dedicated->hevent,
			0,
			0,
			iosb,
			NT_AFD_IOCTL_DUPLICATE,
			&duplicate_info,
			sizeof(duplicate_info),
			0,
			0);

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