]> Chaos Git - corbenik/ctrulib.git/commitdiff
added gethostname
authorLectem <lectem@gmail.com>
Tue, 19 Jan 2016 19:14:32 +0000 (14:14 -0500)
committerLectem <lectem@gmail.com>
Tue, 19 Jan 2016 19:20:34 +0000 (14:20 -0500)
libctru/include/3ds/services/soc.h
libctru/source/services/soc/soc_gethostname.c [new file with mode: 0644]

index 60f7b274b8fa9e4d0e15f3296ba73a5e5c918c0b..bec38e7f73148dfa64e6087d4bfd69e5e3b0f3d0 100644 (file)
@@ -20,13 +20,16 @@ Result socInit(u32 *context_addr, u32 context_size);
  */
 Result socExit(void);
 
-// this is supposed to be in unistd.h but newlib only puts it for cygwin
+// this is supposed to be in unistd.h but newlib only puts it for cygwin, waiting for newlib patch from dkA
 /**
  * @brief Gets the system's host ID.
  * @return The system's host ID.
  */
 long gethostid(void);
 
+// this is supposed to be in unistd.h but newlib only puts it for cygwin, waiting for newlib patch from dkA
+int gethostname(char *name, size_t namelen);
+
 int SOCU_ShutdownSockets();
 
 int SOCU_CloseSockets();
diff --git a/libctru/source/services/soc/soc_gethostname.c b/libctru/source/services/soc/soc_gethostname.c
new file mode 100644 (file)
index 0000000..966ed3c
--- /dev/null
@@ -0,0 +1,14 @@
+#include <arpa/inet.h>
+#include <3ds/result.h>       // To be removed when dkA patch to newlib is applied
+#include <3ds/services/soc.h> // To be changed to unistd.h when dkA patch to newlib is applied
+
+
+// The 3DS doesn't give any host name for its own IP through gethostbyaddr
+// For compatibility, the host ASCII name will be given (IPv4 dotted notation)
+int gethostname(char *name, size_t namelen)
+{
+       long hostid = gethostid();
+       const char * hostname = inet_ntop(AF_INET,&hostid,name,namelen);
+       if(hostname == NULL)return -1;
+       return 0;
+}