Blame src/socket/ntapi_sc_server_accept_connection_v1.c

dd89bb
/********************************************************/
dd89bb
/*  ntapi: Native API core library                      */
dde53a
/*  Copyright (C) 2013--2017  Z. Gilboa                 */
dd89bb
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
dd89bb
/********************************************************/
dd89bb
dd89bb
#include <psxtypes/psxtypes.h>
dd89bb
#include <ntapi/nt_object.h>
dd89bb
#include <ntapi/nt_file.h>
dd89bb
#include <ntapi/nt_socket.h>
dd89bb
#include <ntapi/ntapi.h>
dd89bb
#include "ntapi_impl.h"
dd89bb
dd89bb
typedef struct _nt_afd_server_accept_info {
dd89bb
	uint32_t	sequence;
dd89bb
	uint32_t	unknown;
dd89bb
	uint32_t	service_flags;
dd89bb
	char		sa_data[14];
dd89bb
} nt_afd_server_accept_info;
dd89bb
dd89bb
typedef struct __addr_memcpy {
dd89bb
	uint16_t	d0;
dd89bb
	uint16_t	d1;
dd89bb
	uint16_t	d2;
dd89bb
	uint16_t	d3;
dd89bb
	uint16_t	d4;
dd89bb
	uint16_t	d5;
dd89bb
	uint16_t	d6;
dd89bb
	uint16_t	d7;
dd89bb
} _addr_memcpy;
dd89bb
dd89bb
int32_t __cdecl __ntapi_sc_server_accept_connection_v1(
dd89bb
	__in	nt_socket *		hssocket,
dd89bb
	__out	nt_afd_accept_info *	accept_info,
2e04e9
	__out	nt_iosb volatile *	iosb	__optional)
dd89bb
{
2e04e9
	nt_iosb volatile		siosb;
dd89bb
	nt_afd_server_accept_info	accept_info_buffer;
dd89bb
dd89bb
	_addr_memcpy *			asrc;
dd89bb
	_addr_memcpy *			adst;
dd89bb
dd89bb
	iosb = iosb ? iosb : &siosb;
dd89bb
dd89bb
	hssocket->iostatus = __ntapi->zw_device_io_control_file(
dd89bb
			hssocket->hsocket,
dd89bb
			hssocket->hevent,
dd89bb
			0,
dd89bb
			0,
dd89bb
			iosb,
dd89bb
			NT_AFD_IOCTL_ACCEPT,
dd89bb
			0,
dd89bb
			0,
dd89bb
			&accept_info_buffer,
dd89bb
			sizeof(accept_info_buffer));
dd89bb
dd89bb
	if (hssocket->iostatus && (hssocket->ntflags & __NT_FILE_SYNC_IO))
dd89bb
		__ntapi->sc_wait(hssocket,iosb,&hssocket->timeout);
dd89bb
dd89bb
	if (hssocket->iostatus)
dd89bb
		return hssocket->iostatus;
dd89bb
dd89bb
	accept_info->sequence = accept_info_buffer.sequence;
dd89bb
	accept_info->addr.sa_addr_in4.sa_family = hssocket->domain;
dd89bb
dd89bb
	asrc = (_addr_memcpy *)&(accept_info_buffer.sa_data);
dd89bb
	adst = (_addr_memcpy *)&(accept_info->addr);
dd89bb
dd89bb
	adst->d1 = asrc->d0;
dd89bb
	adst->d2 = asrc->d1;
dd89bb
	adst->d3 = asrc->d2;
dd89bb
	adst->d4 = asrc->d3;
dd89bb
	adst->d5 = asrc->d4;
dd89bb
	adst->d6 = asrc->d5;
dd89bb
	adst->d7 = asrc->d6;
dd89bb
dd89bb
	return hssocket->iostatus;
dd89bb
}