"Guenter" <li...@gknw.net> wrote:
If its not possible to check if initialisation is required or not then its probably worth to talk to the lwip team and suggest an enhancement to lwip_init() so that it does simply nothing if the stack is already initialized.
I can only speak for Windows. We can probably assume that lwIP on Win can never replace the real tcp/ip stack (Winsock). So the init of lwIP+libcurl is per process. There is AFAICS no global settings at the bottom of lwIP. And the win32 port (src/contrib/ports/Win32/*.c) doesn't use registry or a config-file. It could though. Such things are deliberately left to the implementors of a specific OS-port of lwIP. And the core function lwip_init() does not initialise stuff like netif, mask & address. But only things that are common to most tcp/ip-stacks; like loopback address etc. See core/init.c.
Since lwip+libcurl needs to be configured per process the mask/address etc. should be called from libcurl. Where else? Similar to how the lwip application samples does this. I have looked into this some time ago. Can you Guenter take a look at the attached lwip-thread.c and see what you think? curl_lwip_init() should be called from win32_init() in easy.c. I'm not happy with this either since the stuff therein are hardcoded ATM.
--gv
/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * Copyright (C) 1998 - 2012, Daniel Stenberg, <dan...@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms * are also available at http://curl.haxx.se/docs/copyright.html. * * You may opt to use, copy, modify, merge, publish, distribute and/or sell * copies of the Software, and permit persons to whom the Software is * furnished to do so, under the terms of the COPYING file. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ***************************************************************************/ #include "setup.h" #include "curl_threads.h" #if defined(USE_LWIPSOCK) #include <conio.h> #include <lwip/netif.h> #include <lwip/dhcp.h> #include <lwip/sys.h> #include <lwip/tcpip.h> #include <pcapif.h> /* in <lwIP-root>/src/contrib/ports/win32/ */ static struct netif netif; static unsigned char debug_flags; static ip_addr_t ipaddr, netmask, gw; /* (manually) host IP configuration */ static sys_sem_t init_sem; static BOOL quit = FALSE; static DWORD CURL_STDCALL main_thread(void *arg); void curl_lwip_init (void) { struct packet_adapter *pa; IP4_ADDR(&gw, 10,0,0,1); IP4_ADDR(&netmask, 255,255,255,0); IP4_ADDR(&ipaddr, 10,0,0,3); lwip_init(); sys_sem_new(&init_sem, 0); netif_init(); #if 0 if (!netif.state) abort(); #endif sys_thread_new("main_thread", (lwip_thread_fn)main_thread, &init_sem, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); } static void tcpip_init_done (void *arg) { sys_sem_t *sem = (sys_sem_t*)arg; struct netif *iface = netif_add(&netif, &ipaddr, &netmask, &gw, NULL, pcapif_init, tcpip_input); netif_set_default(iface); netif_set_up(&netif); sys_sem_signal(sem); } static DWORD CURL_STDCALL main_thread (void *arg) { struct in_addr inaddr; char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0}; sys_sem_t *sem = (sys_sem_t*) arg; tcpip_init(tcpip_init_done, sem); sys_sem_wait(sem); inaddr.s_addr = ipaddr.addr; strncpy(ip_str,inet_ntoa(inaddr),sizeof(ip_str)); inaddr.s_addr = netmask.addr; strncpy(nm_str,inet_ntoa(inaddr),sizeof(nm_str)); inaddr.s_addr = gw.addr; strncpy(gw_str,inet_ntoa(inaddr),sizeof(gw_str)); printf("TCP/IP initialized. Using IP %s, netmask %s, gateway %s\n", ip_str, nm_str, gw_str); while (!_kbhit()) { netif_poll(&netif); Sleep (10); } sys_sem_free(sem); } #endif
------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.html