Merge pull request #244 from Lectem/more_soc

SOC:u added close/shutdown sockets and inet_pton/ntop
This commit is contained in:
Dave Murphy 2016-01-17 18:36:06 +00:00
commit 28b3775118
6 changed files with 90 additions and 3 deletions

View File

@ -27,3 +27,6 @@ Result socExit(void);
*/
long gethostid(void);
int SOCU_ShutdownSockets();
int SOCU_CloseSockets();

View File

@ -31,6 +31,9 @@ extern "C" {
int inet_aton(const char *cp, struct in_addr *inp);
char* inet_ntoa(struct in_addr in);
const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size);
int inet_pton(int af, const char *restrict src, void *restrict dst);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,15 @@
#include "soc_common.h"
#include <3ds/ipc.h>
#include <3ds/result.h>
int SOCU_CloseSockets()
{
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x21,0,2); // 0x210002;
cmdbuf[1] = IPC_Desc_CurProcessHandle();
int ret = svcSendSyncRequest(SOCU_handle);
if(R_FAILED(ret))return ret;
return cmdbuf[1];
}

View File

@ -0,0 +1,28 @@
#include "soc_common.h"
#include <arpa/inet.h>
#include <stdio.h>
static const char *inet_ntop4(const void *restrict src, char *restrict dst, socklen_t size)
{
const u8 * ip = src;
if(size < INET_ADDRSTRLEN)
{
errno = ENOSPC;
return NULL;
}
snprintf(dst,size,"%hhu.%hhu.%hhu.%hhu",ip[0], ip[1], ip[2], ip[3]);
return dst;
}
const char *inet_ntop(int af, const void *restrict src, char *restrict dst, socklen_t size)
{
if(af == AF_INET)
{
return inet_ntop4(src,dst,size);
}
// only support IPv4
errno = EAFNOSUPPORT;
return NULL;
}

View File

@ -0,0 +1,24 @@
#include "soc_common.h"
#include <arpa/inet.h>
#include <stdio.h>
static int inet_pton4(const char *restrict src, void *restrict dst)
{
u8 ip[4];
if(sscanf(src,"%hhu.%hhu.%hhu.%hhu",&ip[0], &ip[1], &ip[2], &ip[3]) != 4) return 0;
*(u32*)dst = *(u32*)ip;
return 1;
}
int inet_pton(int af, const char *restrict src, void *restrict dst)
{
if(af == AF_INET)
{
return inet_pton4(src,dst);
}
// only support IPv4
errno = EAFNOSUPPORT;
return -1;
}

View File

@ -0,0 +1,14 @@
#include "soc_common.h"
#include <3ds/ipc.h>
#include <3ds/result.h>
int SOCU_ShutdownSockets()
{
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0x19,0,0); // 0x190000
int ret = svcSendSyncRequest(SOCU_handle);
if(R_FAILED(ret))return ret;
return cmdbuf[1];
}