From 464d6c636321f8d3f6b20d368a8ff3e749e7c9fb Mon Sep 17 00:00:00 2001 From: Lectem Date: Sat, 16 Jan 2016 21:13:22 -0500 Subject: [PATCH 1/3] SOC:u added close/shutdown sockets --- libctru/include/3ds/services/soc.h | 3 +++ libctru/source/services/soc/soc_closesockets.c | 15 +++++++++++++++ libctru/source/services/soc/soc_shutdownsockets.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 libctru/source/services/soc/soc_closesockets.c create mode 100644 libctru/source/services/soc/soc_shutdownsockets.c diff --git a/libctru/include/3ds/services/soc.h b/libctru/include/3ds/services/soc.h index b5ac85e..60f7b27 100644 --- a/libctru/include/3ds/services/soc.h +++ b/libctru/include/3ds/services/soc.h @@ -27,3 +27,6 @@ Result socExit(void); */ long gethostid(void); +int SOCU_ShutdownSockets(); + +int SOCU_CloseSockets(); diff --git a/libctru/source/services/soc/soc_closesockets.c b/libctru/source/services/soc/soc_closesockets.c new file mode 100644 index 0000000..6b5a8aa --- /dev/null +++ b/libctru/source/services/soc/soc_closesockets.c @@ -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]; +} diff --git a/libctru/source/services/soc/soc_shutdownsockets.c b/libctru/source/services/soc/soc_shutdownsockets.c new file mode 100644 index 0000000..1649846 --- /dev/null +++ b/libctru/source/services/soc/soc_shutdownsockets.c @@ -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]; +} From 389807c6a39741ec70994c55738001ffd7eb2146 Mon Sep 17 00:00:00 2001 From: Lectem Date: Sun, 17 Jan 2016 12:25:41 -0500 Subject: [PATCH 2/3] fix alignment in arpa/inet.h --- libctru/include/arpa/inet.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libctru/include/arpa/inet.h b/libctru/include/arpa/inet.h index 197877b..1052c6b 100644 --- a/libctru/include/arpa/inet.h +++ b/libctru/include/arpa/inet.h @@ -27,9 +27,9 @@ static inline uint16_t ntohs(uint16_t netshort) extern "C" { #endif - in_addr_t inet_addr(const char *cp); - int inet_aton(const char *cp, struct in_addr *inp); - char* inet_ntoa(struct in_addr in); + in_addr_t inet_addr(const char *cp); + int inet_aton(const char *cp, struct in_addr *inp); + char* inet_ntoa(struct in_addr in); #ifdef __cplusplus } From 45ff5c4ee6234d784844f0480cc6e79fb37b242f Mon Sep 17 00:00:00 2001 From: Lectem Date: Sun, 17 Jan 2016 12:58:21 -0500 Subject: [PATCH 3/3] added inet_pton and inet_ntop --- libctru/include/arpa/inet.h | 3 +++ libctru/source/services/soc/soc_inet_ntop.c | 28 +++++++++++++++++++++ libctru/source/services/soc/soc_inet_pton.c | 24 ++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 libctru/source/services/soc/soc_inet_ntop.c create mode 100644 libctru/source/services/soc/soc_inet_pton.c diff --git a/libctru/include/arpa/inet.h b/libctru/include/arpa/inet.h index 1052c6b..5e044a9 100644 --- a/libctru/include/arpa/inet.h +++ b/libctru/include/arpa/inet.h @@ -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 diff --git a/libctru/source/services/soc/soc_inet_ntop.c b/libctru/source/services/soc/soc_inet_ntop.c new file mode 100644 index 0000000..68016d4 --- /dev/null +++ b/libctru/source/services/soc/soc_inet_ntop.c @@ -0,0 +1,28 @@ +#include "soc_common.h" +#include +#include + + +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; +} diff --git a/libctru/source/services/soc/soc_inet_pton.c b/libctru/source/services/soc/soc_inet_pton.c new file mode 100644 index 0000000..dc8bba9 --- /dev/null +++ b/libctru/source/services/soc/soc_inet_pton.c @@ -0,0 +1,24 @@ +#include "soc_common.h" +#include +#include + + +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; +}