Blame src/socket/ntapi_sc_getpeername_v1.c

5d8625
/********************************************************/
5d8625
/*  ntapi: Native API core library                      */
64e606
/*  Copyright (C) 2013--2021  SysDeer Technologies, LLC */
5d8625
/*  Released under GPLv2 and GPLv3; see COPYING.NTAPI.  */
5d8625
/********************************************************/
5d8625
5d8625
#include <psxtypes/psxtypes.h>
5d8625
#include <ntapi/nt_object.h>
5d8625
#include <ntapi/nt_file.h>
5d8625
#include <ntapi/nt_socket.h>
5d8625
#include <ntapi/ntapi.h>
5d8625
#include "ntapi_impl.h"
5d8625
5d8625
typedef struct _nt_afd_server_socket_name_info {
5d8625
	uint32_t	unknown;
5d8625
	uint32_t	type;
5d8625
	uint32_t	service_flags;
5d8625
	char		sa_data[14];
5d8625
} nt_afd_server_socket_name_info;
5d8625
5d8625
5d8625
struct __addr_memcpy {
5d8625
	uint16_t	d0;
5d8625
	uint16_t	d1;
5d8625
	uint16_t	d2;
5d8625
	uint16_t	d3;
5d8625
	uint16_t	d4;
5d8625
	uint16_t	d5;
5d8625
	uint16_t	d6;
5d8625
	uint16_t	d7;
5d8625
};
5d8625
5d8625
5d8625
int32_t __cdecl __ntapi_sc_getpeername_v1(
5d8625
	__in	nt_socket *		hssocket,
5d8625
	__in	nt_sockaddr *		addr,
5d8625
	__in	uint16_t *		addrlen,
2e04e9
	__out	nt_iosb volatile *	iosb	__optional)
5d8625
{
2e04e9
	nt_iosb volatile		siosb;
5d8625
	nt_afd_server_socket_name_info	sock_name_info;
5d8625
5d8625
	struct __addr_memcpy *		asrc;
5d8625
	struct __addr_memcpy *		adst;
5d8625
5d8625
	iosb = iosb ? iosb : &siosb;
5d8625
5d8625
	hssocket->iostatus = __ntapi->zw_device_io_control_file(
5d8625
			hssocket->hsocket,
5d8625
			hssocket->hevent,
5d8625
			0,
5d8625
			0,
5d8625
			iosb,
5d8625
			NT_AFD_IOCTL_GET_PEER_NAME,
5d8625
			0,
5d8625
			0,
5d8625
			&sock_name_info,
5d8625
			sizeof(sock_name_info));
5d8625
5d8625
	__ntapi->sc_wait(hssocket,iosb,0);
5d8625
5d8625
	if (!hssocket->iostatus) {
5d8625
		addr->sa_addr_in4.sa_family = hssocket->domain;
5d8625
5d8625
		asrc = (struct __addr_memcpy *)&(sock_name_info.sa_data);
5d8625
		adst = (struct __addr_memcpy *)addr;
5d8625
5d8625
		adst->d1 = asrc->d0;
5d8625
		adst->d2 = asrc->d1;
5d8625
		adst->d3 = asrc->d2;
5d8625
		adst->d4 = asrc->d3;
5d8625
		adst->d5 = asrc->d4;
5d8625
		adst->d6 = asrc->d5;
5d8625
		adst->d7 = asrc->d6;
5d8625
5d8625
		*addrlen = (uint16_t)iosb->info;
5d8625
	};
5d8625
5d8625
	return hssocket->iostatus;
5d8625
}