mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-28 01:27:09 +03:00
minimal server for lwip demo (no coap yet)
This commit is contained in:
1 parent
77c5856ad9
commit
691a87d812
4 files changed
+157
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# not going for submodules here to keep things easy
|
||||
lwip
|
||||
lwip-contrib
|
||||
|
||||
# never objects, and not the resulting binary
|
||||
*.o
|
||||
server
|
||||
@@ -0,0 +1,31 @@
|
||||
all: server
|
||||
|
||||
lwip:
|
||||
git clone git://git.savannah.nongnu.org/lwip.git -b DEVEL-1_4_1
|
||||
|
||||
lwip-contrib:
|
||||
git clone git://git.savannah.nongnu.org/lwip/lwip-contrib.git -b master
|
||||
|
||||
LWIPOBJS = def.o init.o mintapif.o etharp.o netif.o timer.o timers.o stats.o mem.o memp.o udp.o tcp.o pbuf.o ip_addr.o ip.o inet_chksum.o tcp_in.o tcp_out.o icmp.o raw.o ip_frag.o sys_arch.o
|
||||
vpath %.c lwip/src/core/ lwip-contrib/ports/unix/proj/minimal/ lwip/src/netif/ lwip/src/core/ipv4/ lwip-contrib/ports/unix/
|
||||
|
||||
# flags from lwip
|
||||
CFLAGS += -g -Wall -pedantic -Dopenbsd -DIPv4 -Os -fpack-struct -DLWIP_DEBUG
|
||||
|
||||
# lwip opts (include early to shadow the
|
||||
# lwip-contrib/ports/unix/proj/minimal/ file)
|
||||
CFLAGS += -I.
|
||||
|
||||
# lwip library
|
||||
CFLAGS += -Ilwip/src/include/ -Ilwip/src/include/ipv4/ -Ilwip-contrib/ports/unix/include/ -Ilwip-contrib/ports/unix/proj/minimal/
|
||||
|
||||
${LWIPOBJS}: lwip lwip-contrib
|
||||
|
||||
OBJS = server.o ${LWIPOBJS}
|
||||
|
||||
server: ${OBJS}
|
||||
|
||||
clean:
|
||||
rm -f ${OBJS}
|
||||
|
||||
.PHONY: clean
|
||||
@@ -0,0 +1,11 @@
|
||||
#define NO_SYS 1
|
||||
|
||||
/* they'd require NO_SYS=0, but are enabled by default */
|
||||
#define LWIP_SOCKET 0
|
||||
#define LWIP_NETCONN 0
|
||||
|
||||
#define LWIP_USE_CUSTOM_POOLS 1
|
||||
|
||||
|
||||
/* +1 for a missing timeout in the default list i could not yet track down */
|
||||
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + 1)
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Demo for libcoap on lwIP
|
||||
*
|
||||
* partially copied from lwip-contrib/ports/unix/proj/minimal/main.c
|
||||
*
|
||||
*
|
||||
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* Author: Adam Dunkels <adam@sics.se>
|
||||
* RT timer modifications by Christiaan Simons
|
||||
* lwip adaptions: chrysn <chrysn@fsfe.org>
|
||||
* also, https://savannah.nongnu.org/bugs/?40245 was applied */
|
||||
|
||||
#include <lwip/init.h>
|
||||
#include <lwip/timers.h>
|
||||
|
||||
#include <mintapif.h>
|
||||
#include <netif/etharp.h>
|
||||
|
||||
#include "timer.h"
|
||||
#include <signal.h>
|
||||
|
||||
static ip_addr_t ipaddr, netmask, gw;
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct netif netif;
|
||||
sigset_t mask, oldmask, empty;
|
||||
|
||||
/* startup defaults (may be overridden by one or more opts) */
|
||||
IP4_ADDR(&gw, 192,168,0,1);
|
||||
IP4_ADDR(&ipaddr, 192,168,0,2);
|
||||
IP4_ADDR(&netmask, 255,255,255,0);
|
||||
|
||||
lwip_init();
|
||||
|
||||
printf("TCP/IP initialized.\n");
|
||||
|
||||
netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ethernet_input);
|
||||
netif_set_default(&netif);
|
||||
netif_set_up(&netif);
|
||||
#if LWIP_IPV6
|
||||
netif_create_ip6_linklocal_address(&netif, 1);
|
||||
#endif
|
||||
|
||||
timer_init();
|
||||
|
||||
sys_timeouts_init();
|
||||
|
||||
/* start applications here */
|
||||
|
||||
printf("Applications started.\n");
|
||||
|
||||
|
||||
while (1) {
|
||||
|
||||
/* poll for input packet and ensure
|
||||
select() or read() arn't interrupted */
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGALRM);
|
||||
sigprocmask(SIG_BLOCK, &mask, &oldmask);
|
||||
|
||||
/* start of critical section,
|
||||
poll netif, pass packet to lwIP */
|
||||
if (mintapif_select(&netif) > 0)
|
||||
{
|
||||
/* work, immediatly end critical section
|
||||
hoping lwIP ended quickly ... */
|
||||
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no work, wait a little (10 msec) for SIGALRM */
|
||||
sigemptyset(&empty);
|
||||
sigsuspend(&empty);
|
||||
/* ... end critical section */
|
||||
sigprocmask(SIG_SETMASK, &oldmask, NULL);
|
||||
}
|
||||
|
||||
sys_check_timeouts();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user