From 1e8456414848e36950f72ce87ba97052ab106dec Mon Sep 17 00:00:00 2001 From: esevece Date: Fri, 22 Nov 2013 18:42:34 +0000 Subject: [PATCH] C file for network.obj library git-svn-id: svn://kolibrios.org@4283 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../menuetlibc/src/libc/menuetos/network.c | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 programs/develop/libraries/menuetlibc/src/libc/menuetos/network.c diff --git a/programs/develop/libraries/menuetlibc/src/libc/menuetos/network.c b/programs/develop/libraries/menuetlibc/src/libc/menuetos/network.c new file mode 100644 index 0000000000..d9f0bd8b85 --- /dev/null +++ b/programs/develop/libraries/menuetlibc/src/libc/menuetos/network.c @@ -0,0 +1,75 @@ +#include + + +#define NULL 0 +#define __stdcall __attribute__((stdcall)) + +extern int dll_load(); +extern int mem_Free(); +extern int mem_Alloc(); +extern int mem_ReAlloc(); + +int kol_exit(){ + __menuet__sys_exit(); +} + + +int (* __stdcall network_init)(); +void (* __stdcall freeaddrinfo)(struct addrinfo* ai); +int (* __stdcall getaddrinfo)( const char* hostname, const char* servname, const struct addrinfo* hints, struct addrinfo **res); +char * (* __stdcall inet_ntoa)(struct in_addr in); +unsigned long (* __stdcall inet_addr)( const char* hostname); + + +int NETWORK_YAY(){ +asm volatile ("pusha\n\ +movl $mem_Alloc, %eax\n\ +movl $mem_Free, %ebx\n\ +movl $mem_ReAlloc, %ecx\n\ +movl $dll_load, %edx\n\ +movl network_init, %esi\n\ +call *%esi\n\ +popa\n"); +} + + +void NETWORK_INIT() +{ +IMP_ENTRY *imp; + +imp = __kolibri__cofflib_load("/sys/lib/network.obj"); +if (imp == NULL) + kol_exit(); + +network_init = ( __stdcall int(*)()) +__kolibri__cofflib_getproc (imp, "lib_init"); +if (network_init == NULL) + kol_exit(); + +freeaddrinfo = ( __stdcall void (*)(struct addrinfo*)) +__kolibri__cofflib_getproc (imp, "freeaddrinfo"); +if (freeaddrinfo == NULL) + kol_exit(); + +getaddrinfo = ( __stdcall int (*)(const char*, const char*, const struct addrinfo*, struct addrinfo **)) +__kolibri__cofflib_getproc (imp, "getaddrinfo"); +if (getaddrinfo == NULL) + kol_exit(); + +inet_ntoa = ( __stdcall char * (*)(struct in_addr)) +__kolibri__cofflib_getproc (imp, "inet_ntoa"); +if (inet_ntoa == NULL) + kol_exit(); + +inet_addr = ( __stdcall unsigned long (*)(const char *)) +__kolibri__cofflib_getproc (imp, "inet_addr"); +if (inet_addr == NULL) + kol_exit(); + +__menuet__debug_out("NETWORK init...\n"); + +NETWORK_YAY(); + +__menuet__debug_out("ok...\n"); + +} \ No newline at end of file