From 877689448e30ca9165f0450ef2da31e2f8bd61e7 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 11 Aug 2013 11:12:42 +0800 Subject: [PATCH] Usermode/libpsockets - Added basic services to getaddrinfo --- Usermode/Libraries/libpsocket.so_src/Makefile | 2 +- .../Libraries/libpsocket.so_src/getaddrinfo.c | 32 ++++++++++++++++--- .../include_exp/sys/socket.h | 2 +- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Usermode/Libraries/libpsocket.so_src/Makefile b/Usermode/Libraries/libpsocket.so_src/Makefile index 81418ad7..bd7f38d0 100644 --- a/Usermode/Libraries/libpsocket.so_src/Makefile +++ b/Usermode/Libraries/libpsocket.so_src/Makefile @@ -6,7 +6,7 @@ CPPFLAGS += CFLAGS += -Wall LDFLAGS += -lc -soname libpsocket.so -lnet -OBJ = main.o getaddrinfo.o socket.o +OBJ = main.o getaddrinfo.o socket.o pton.o BIN = libpsocket.so include ../Makefile.tpl diff --git a/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c b/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c index d4d6ce8d..aa8128d9 100644 --- a/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c +++ b/Usermode/Libraries/libpsocket.so_src/getaddrinfo.c @@ -13,6 +13,17 @@ #include // strtol #include +static const struct { + const char *Name; + int SockType; + int Protocol; + int Port; +} caLocalServices[] = { + {"telnet", SOCK_STREAM, 0, 23}, + {"http", SOCK_STREAM, 0, 80}, +}; +static const int ciNumLocalServices = sizeof(caLocalServices)/sizeof(caLocalServices[0]); + // === CODE === int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) { @@ -40,7 +51,6 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi else { // 1. Check if the node is an IP address - // TODO: Break this function out into inet_pton? { int type; char addrdata[16]; @@ -106,15 +116,29 @@ int getaddrinfo(const char *node, const char *service, const struct addrinfo *hi char *end; default_port = strtol(service, &end, 0); - if( *end != '\0' && !(hints->ai_flags & AI_NUMERICSERV) ) + if( *end != '\0' && (hints->ai_flags & AI_NUMERICSERV) ) + { + return EAI_NONAME; + } + + if( *end != '\0' ) { // TODO: Read something like /Acess/Conf/services - _SysDebug("getaddrinfo: TODO Service translation"); + for( int i = 0; i < ciNumLocalServices; i ++ ) + { + if( strcmp(service, caLocalServices[i].Name) == 0 ) { + end = service + strlen(service); + default_socktype = caLocalServices[i].SockType; + default_protocol = caLocalServices[i].Protocol; + default_port = caLocalServices[i].Port; + break; + } + } } if( *end != '\0' ) { - return EAI_NONAME; + _SysDebug("getaddrinfo: TODO Service translation"); } } diff --git a/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h b/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h index bba73978..4d052db1 100644 --- a/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h +++ b/Usermode/Libraries/libpsocket.so_src/include_exp/sys/socket.h @@ -29,7 +29,7 @@ typedef enum struct sockaddr { sa_family_t sa_family; - char sa_data[16]; + char sa_data[16+2]; }; struct msghdr -- 2.20.1