|
|
dd89bb |
/********************************************************/
|
|
|
dd89bb |
/* ntapi: Native API core library */
|
|
|
4256e2 |
/* Copyright (C) 2013--2016 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_bind_request {
|
|
|
dd89bb |
uint32_t unknown;
|
|
|
dd89bb |
nt_sockaddr addr;
|
|
|
dd89bb |
} nt_afd_bind_request;
|
|
|
dd89bb |
|
|
|
dd89bb |
typedef struct _nt_afd_bind_reply {
|
|
|
dd89bb |
nt_sockaddr addr;
|
|
|
dd89bb |
} nt_afd_bind_reply;
|
|
|
dd89bb |
|
|
|
dd89bb |
typedef struct __addr_memcpy {
|
|
|
f34a58 |
uint64_t d0;
|
|
|
f34a58 |
uint64_t d1;
|
|
|
f34a58 |
uint64_t d2;
|
|
|
dd89bb |
uint32_t d3;
|
|
|
dd89bb |
} _addr_memcpy;
|
|
|
dd89bb |
|
|
|
dd89bb |
|
|
|
dd89bb |
int32_t __cdecl __ntapi_sc_bind_v2(
|
|
|
dd89bb |
__in nt_socket * hssocket,
|
|
|
dd89bb |
__in const nt_sockaddr * addr,
|
|
|
dd89bb |
__in uintptr_t addrlen,
|
|
|
dd89bb |
__in uintptr_t service_flags __optional,
|
|
|
dd89bb |
__out nt_sockaddr * sockaddr __optional,
|
|
|
dd89bb |
__out nt_io_status_block * iosb __optional)
|
|
|
dd89bb |
{
|
|
|
dd89bb |
nt_io_status_block siosb;
|
|
|
dd89bb |
nt_afd_bind_request afd_bind_req;
|
|
|
dd89bb |
nt_afd_bind_reply afd_bind_rep;
|
|
|
dd89bb |
|
|
|
dd89bb |
_addr_memcpy * src;
|
|
|
dd89bb |
_addr_memcpy * dst;
|
|
|
dd89bb |
|
|
|
c713d8 |
(void)service_flags;
|
|
|
c713d8 |
|
|
|
f34a58 |
if ((addrlen != sizeof(nt_sockaddr_in4))
|
|
|
f34a58 |
&& (addrlen != sizeof(nt_sockaddr_in6)))
|
|
|
f34a58 |
return NT_STATUS_INVALID_PARAMETER_3;
|
|
|
f34a58 |
|
|
|
dd89bb |
iosb = iosb ? iosb : &siosb;
|
|
|
dd89bb |
|
|
|
dd89bb |
/* request */
|
|
|
dd89bb |
afd_bind_req.unknown = hssocket->domain;
|
|
|
dd89bb |
|
|
|
dd89bb |
src = (_addr_memcpy *)addr;
|
|
|
dd89bb |
dst = (_addr_memcpy *)&(afd_bind_req.addr);
|
|
|
dd89bb |
|
|
|
dd89bb |
dst->d0 = src->d0;
|
|
|
dd89bb |
dst->d1 = src->d1;
|
|
|
f34a58 |
|
|
|
f34a58 |
if (addrlen == sizeof(nt_sockaddr_in6)) {
|
|
|
f34a58 |
dst->d2 = src->d2;
|
|
|
f34a58 |
dst->d3 = src->d3;
|
|
|
f34a58 |
} else {
|
|
|
f34a58 |
dst->d2 = 0;
|
|
|
f34a58 |
dst->d3 = 0;
|
|
|
f34a58 |
}
|
|
|
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_BIND,
|
|
|
dd89bb |
&afd_bind_req,
|
|
|
dd89bb |
sizeof(afd_bind_req),
|
|
|
dd89bb |
&afd_bind_rep,
|
|
|
dd89bb |
sizeof(afd_bind_rep));
|
|
|
dd89bb |
|
|
|
dd89bb |
__ntapi->sc_wait(hssocket,iosb,0);
|
|
|
dd89bb |
|
|
|
dd89bb |
if (!hssocket->iostatus && sockaddr) {
|
|
|
dd89bb |
/* return updated address information */
|
|
|
dd89bb |
src = (_addr_memcpy *)&(afd_bind_rep);
|
|
|
dd89bb |
dst = (_addr_memcpy *)sockaddr;
|
|
|
dd89bb |
|
|
|
dd89bb |
dst->d0 = src->d0;
|
|
|
dd89bb |
dst->d1 = src->d1;
|
|
|
f34a58 |
|
|
|
f34a58 |
if (addrlen == sizeof(nt_sockaddr_in6)) {
|
|
|
f34a58 |
dst->d2 = src->d2;
|
|
|
f34a58 |
dst->d3 = src->d3;
|
|
|
f34a58 |
}
|
|
|
dd89bb |
}
|
|
|
dd89bb |
|
|
|
dd89bb |
return hssocket->iostatus;
|
|
|
dd89bb |
}
|