From 034a27adaa9e5d27cd8a3e53f1b3b16bc20f4ce8 Mon Sep 17 00:00:00 2001 From: Lectem Date: Thu, 27 Aug 2015 14:24:10 -0400 Subject: [PATCH 1/6] Protocol numbers and sockopt options Protocol numbers are based on both RFC 1700 p.7 and the Internet Assigned Numbers Authority (IANA) http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml Those are to be used with the added sockopt options. The various options have been tested with wireshark. --- libctru/include/netinet/in.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libctru/include/netinet/in.h b/libctru/include/netinet/in.h index bc8d6f8..5d274b0 100644 --- a/libctru/include/netinet/in.h +++ b/libctru/include/netinet/in.h @@ -3,15 +3,25 @@ #include #include -#define INADDR_ANY 0x00000000 -#define INADDR_BROADCAST 0xFFFFFFFF -#define INADDR_NONE 0xFFFFFFFF +#define INADDR_ANY 0x00000000 +#define INADDR_BROADCAST 0xFFFFFFFF +#define INADDR_NONE 0xFFFFFFFF #define INET_ADDRSTRLEN 16 -//#define IPPROTO_IP ??? -//#define IPPROTO_TCP ??? -//#define IPPROTO_UDP ??? +/* + * Protocols (See RFC 1700 and the IANA) + */ +#define IPPROTO_IP 0 /* dummy for IP */ +#define IPPROTO_UDP 17 /* user datagram protocol */ +#define IPPROTO_TCP 6 /* tcp */ + +#define IP_TOS 7 +#define IP_TTL 8 +#define IP_MULTICAST_LOOP 9 +#define IP_MULTICAST_TTL 10 +#define IP_ADD_MEMBERSHIP 11 +#define IP_DROP_MEMBERSHIP 12 typedef uint16_t in_port_t; typedef uint32_t in_addr_t; @@ -26,3 +36,9 @@ struct sockaddr_in { struct in_addr sin_addr; unsigned char sin_zero[8]; }; + +/* Request struct for multicast socket ops */ +struct ip_mreq { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_interface; /* local IP address of interface */ +}; \ No newline at end of file From 1a24e0e0546f385302c03554c7819de8beb40d31 Mon Sep 17 00:00:00 2001 From: Lectem Date: Tue, 6 Oct 2015 11:16:29 -0400 Subject: [PATCH 2/6] fixed some netinet/in.h formating --- libctru/include/netinet/in.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libctru/include/netinet/in.h b/libctru/include/netinet/in.h index 5d274b0..795aa04 100644 --- a/libctru/include/netinet/in.h +++ b/libctru/include/netinet/in.h @@ -5,9 +5,9 @@ #define INADDR_ANY 0x00000000 #define INADDR_BROADCAST 0xFFFFFFFF -#define INADDR_NONE 0xFFFFFFFF +#define INADDR_NONE 0xFFFFFFFF -#define INET_ADDRSTRLEN 16 +#define INET_ADDRSTRLEN 16 /* * Protocols (See RFC 1700 and the IANA) @@ -16,25 +16,25 @@ #define IPPROTO_UDP 17 /* user datagram protocol */ #define IPPROTO_TCP 6 /* tcp */ -#define IP_TOS 7 -#define IP_TTL 8 +#define IP_TOS 7 +#define IP_TTL 8 #define IP_MULTICAST_LOOP 9 -#define IP_MULTICAST_TTL 10 -#define IP_ADD_MEMBERSHIP 11 -#define IP_DROP_MEMBERSHIP 12 +#define IP_MULTICAST_TTL 10 +#define IP_ADD_MEMBERSHIP 11 +#define IP_DROP_MEMBERSHIP 12 typedef uint16_t in_port_t; typedef uint32_t in_addr_t; struct in_addr { - in_addr_t s_addr; + in_addr_t s_addr; }; struct sockaddr_in { - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - unsigned char sin_zero[8]; + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + unsigned char sin_zero[8]; }; /* Request struct for multicast socket ops */ From 70e7fb35bc1c2572fa265536fea61c03aee7a963 Mon Sep 17 00:00:00 2001 From: Lectem Date: Tue, 6 Oct 2015 12:48:25 -0400 Subject: [PATCH 3/6] fix SOL_SOCKET level options --- libctru/include/netinet/in.h | 2 +- libctru/include/netinet/tcp.h | 8 +++++-- libctru/include/sys/socket.h | 41 ++++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/libctru/include/netinet/in.h b/libctru/include/netinet/in.h index 795aa04..6778855 100644 --- a/libctru/include/netinet/in.h +++ b/libctru/include/netinet/in.h @@ -41,4 +41,4 @@ struct sockaddr_in { struct ip_mreq { struct in_addr imr_multiaddr; /* IP multicast address of group */ struct in_addr imr_interface; /* local IP address of interface */ -}; \ No newline at end of file +}; diff --git a/libctru/include/netinet/tcp.h b/libctru/include/netinet/tcp.h index b95b127..3619f94 100644 --- a/libctru/include/netinet/tcp.h +++ b/libctru/include/netinet/tcp.h @@ -1,5 +1,9 @@ #pragma once -//#define SOL_TCP ??? +#define SOL_TCP 6 /* TCP level */ -//#define TCP_NODELAY ??? +enum{ + _CTRU_TCP_OPT = 0x2000, /* Flag for tcp opt values */ + TCP_NODELAY = 1 | _CTRU_TCP_OPT, /* Don't delay send to coalesce packets */ + TCP_MAXSEG = 2 | _CTRU_TCP_OPT, +}; diff --git a/libctru/include/sys/socket.h b/libctru/include/sys/socket.h index 02fa98c..597deb2 100644 --- a/libctru/include/sys/socket.h +++ b/libctru/include/sys/socket.h @@ -28,24 +28,29 @@ #define SHUT_WR 1 #define SHUT_RDWR 2 -#define SO_DEBUG 0x0001 -#define SO_ACCEPTCONN 0x0002 -#define SO_REUSEADDR 0x0004 -#define SO_KEEPALIVE 0x0008 -#define SO_DONTROUTE 0x0010 -#define SO_BROADCAST 0x0020 -#define SO_USELOOPBACK 0x0040 -#define SO_LINGER 0x0080 -#define SO_OOBINLINE 0x0100 -#define SO_REUSEPORT 0x0200 -#define SO_SNDBUF 0x1001 -#define SO_RCVBUF 0x1002 -#define SO_SNDLOWAT 0x1003 -#define SO_RCVLOWAT 0x1004 -#define SO_SNDTIMEO 0x1005 -#define SO_RCVTIMEO 0x1006 -#define SO_ERROR 0x1007 -#define SO_TYPE 0x1008 +//#define SO_DEBUG 0x0001 // not working +//#define SO_ACCEPTCONN 0x0002 // not working +#define SO_REUSEADDR 0x0004 +//#define SO_KEEPALIVE 0x0008 // not working +//#define SO_DONTROUTE 0x0010 // not working +//#define SO_BROADCAST 0x0020 // not working +#define SO_USELOOPBACK 0x0040 +#define SO_LINGER 0x0080 +#define SO_OOBINLINE 0x0100 +//#define SO_REUSEPORT 0x0200 // not working + +/* + * Additional options, not kept in so_options. + */ +#define SO_SNDBUF 0x1001 /* send buffer size */ +#define SO_RCVBUF 0x1002 /* receive buffer size */ +#define SO_SNDLOWAT 0x1003 /* send low-water mark */ +#define SO_RCVLOWAT 0x1004 /* receive low-water mark */ +//#define SO_SNDTIMEO 0x1005 /* send timeout */ // not working +//#define SO_RCVTIMEO 0x1006 /* receive timeout */ // not working + +#define SO_TYPE 0x1008 /* get socket type */ +#define SO_ERROR 0x1009 /* get error status and clear */ typedef uint32_t socklen_t; typedef uint16_t sa_family_t; From be64a95c749dd354e507c87c6b5e55d39d2faf6e Mon Sep 17 00:00:00 2001 From: Lectem Date: Fri, 9 Oct 2015 13:37:01 -0400 Subject: [PATCH 4/6] Added INADDR_LOOPBACK define --- libctru/include/netinet/in.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libctru/include/netinet/in.h b/libctru/include/netinet/in.h index 6778855..eabc4a9 100644 --- a/libctru/include/netinet/in.h +++ b/libctru/include/netinet/in.h @@ -3,6 +3,7 @@ #include #include +#define INADDR_LOOPBACK 0x7f000001 #define INADDR_ANY 0x00000000 #define INADDR_BROADCAST 0xFFFFFFFF #define INADDR_NONE 0xFFFFFFFF From af34e85ab262a01950dd8bd7c7ed466df7b47266 Mon Sep 17 00:00:00 2001 From: smea Date: Tue, 27 Oct 2015 10:59:52 -0700 Subject: [PATCH 5/6] added support for other cfg service names --- libctru/source/services/cfgu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libctru/source/services/cfgu.c b/libctru/source/services/cfgu.c index 6b89bba..73f8a18 100644 --- a/libctru/source/services/cfgu.c +++ b/libctru/source/services/cfgu.c @@ -8,7 +8,14 @@ static Handle CFGU_handle = 0; Result initCfgu() { - return srvGetServiceHandle(&CFGU_handle, "cfg:u"); + Result ret; + + // cfg:i has the most commands, then cfg:s, then cfg:u + ret = srvGetServiceHandle(&CFGU_handle, "cfg:i"); + if(ret) ret = srvGetServiceHandle(&CFGU_handle, "cfg:s"); + if(ret) ret = srvGetServiceHandle(&CFGU_handle, "cfg:u"); + + return ret; } Result exitCfgu() From 76e47c02c807f6dc774bfe3101a4d3f83dcb0ed7 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Tue, 27 Oct 2015 19:34:07 -0400 Subject: [PATCH 6/6] Changed gfxSwapBuffers() to gfxSwapBuffersGpu() in consoleInit(). This fixes the black-screen issue with the text-console on certain systems(such as old3ds v9.0-v9.2). --- libctru/source/console.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libctru/source/console.c b/libctru/source/console.c index e7ea8bd..e195638 100644 --- a/libctru/source/console.c +++ b/libctru/source/console.c @@ -528,7 +528,7 @@ PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console) { gfxSetScreenFormat(screen,GSP_RGB565_OES); gfxSetDoubleBuffering(screen,false); - gfxSwapBuffers(); + gfxSwapBuffersGpu(); gspWaitForVBlank(); console->frameBuffer = (u16*)gfxGetFramebuffer(screen, GFX_LEFT, NULL, NULL);