From ca90f6fce9ec7cab923160cddf108bfe999cd94e Mon Sep 17 00:00:00 2001 From: christiaans Date: Mon, 10 Oct 2005 07:25:35 +0000 Subject: [PATCH] Some build fixes for OpenBSD. --- ports/unix/netif/sio.c | 5 +++-- ports/unix/netif/tunif.c | 5 +++++ ports/unix/netif/unixif.c | 2 +- ports/unix/proj/minimal/Makefile | 1 + ports/unix/proj/minimal/echo.c | 4 ++++ ports/unix/proj/minimal/lwipopts.h | 6 +++--- ports/unix/proj/minimal/main.c | 15 +++++++++++++-- ports/unix/proj/minimal/mintapif.c | 22 ++++++++++++++++------ ports/unix/proj/unixsim/Makefile | 2 +- ports/unix/proj/unixsim/apps/shell.c | 16 ++++++++-------- 10 files changed, 55 insertions(+), 23 deletions(-) diff --git a/ports/unix/netif/sio.c b/ports/unix/netif/sio.c index d34a200..3120d21 100644 --- a/ports/unix/netif/sio.c +++ b/ports/unix/netif/sio.c @@ -20,6 +20,7 @@ #undef NTOHS #include +#include #include #include #include @@ -28,7 +29,7 @@ #include #include -#if PPP_SUPPORT +#if PPP_SUPPORT && defined(linux) #include #endif @@ -295,7 +296,7 @@ sio_status_t * sio_open( int devnum ) fifoInit( &siostate->myfifo ); #endif /* ! PPP_SUPPORT */ - sprintf( dev, "/dev/ttyS%d", devnum ); + snprintf( dev, sizeof(dev), "/dev/ttyS%d", devnum ); if ( (devnum == 1) || (devnum == 0) ) { diff --git a/ports/unix/netif/tunif.c b/ports/unix/netif/tunif.c index 2e492e2..640b36a 100644 --- a/ports/unix/netif/tunif.c +++ b/ports/unix/netif/tunif.c @@ -267,9 +267,14 @@ tunif_input(struct netif *netif) return; } +#if 0 +/* CS: ip_lookup() was removed */ if (ip_lookup(p->payload, netif)) { +#endif netif->input(p, netif); +#if 0 } +#endif } /*-----------------------------------------------------------------------------------*/ /* diff --git a/ports/unix/netif/unixif.c b/ports/unix/netif/unixif.c index dd955a7..44e396c 100644 --- a/ports/unix/netif/unixif.c +++ b/ports/unix/netif/unixif.c @@ -89,7 +89,7 @@ unix_socket_client(char *name) /* fill socket address structure w/our address */ memset(&unix_addr, 0, sizeof(unix_addr)); unix_addr.sun_family = AF_UNIX; - sprintf(unix_addr.sun_path, "%s%05d", "/var/tmp/", getpid()); + snprintf(unix_addr.sun_path, sizeof(unix_addr.sun_path), "%s%05d", "/var/tmp/", getpid()); #if !defined(linux) && !defined(cygwin) len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) + strlen(unix_addr.sun_path) + 1; diff --git a/ports/unix/proj/minimal/Makefile b/ports/unix/proj/minimal/Makefile index 8bce05d..f84291b 100644 --- a/ports/unix/proj/minimal/Makefile +++ b/ports/unix/proj/minimal/Makefile @@ -33,6 +33,7 @@ CCDEP=gcc CC=gcc #To compile for linux: make ARCH=linux #To compile for cygwin: make ARCH=cygwin +#To compile for openbsd: make ARCH=openbsd ARCH=unix CFLAGS=-g -Wall -D$(ARCH) -DIPv4 -Os -fpack-struct ARFLAGS=rs diff --git a/ports/unix/proj/minimal/echo.c b/ports/unix/proj/minimal/echo.c index 6c612ce..11363a6 100644 --- a/ports/unix/proj/minimal/echo.c +++ b/ports/unix/proj/minimal/echo.c @@ -46,6 +46,7 @@ echo_err(void *arg, err_t err) struct echo_state *es = arg; if (arg != NULL) { + LWIP_ASSERT("es->p != NULL", es->p != NULL); pbuf_free(es->p); mem_free(arg); } @@ -60,7 +61,9 @@ close_conn(struct tcp_pcb *pcb, struct echo_state *es) tcp_recv(pcb, NULL); #endif /* 0 */ if (es != NULL) { + if (es->p != NULL) { pbuf_free(es->p); + } mem_free(es); } tcp_close(pcb); @@ -80,6 +83,7 @@ send_buf(struct tcp_pcb *pcb, struct echo_state *es) return; } tcp_recved(pcb, q->len); + LWIP_ASSERT("q != NULL", q != NULL); pbuf_free(q); } while (es->p != NULL); } diff --git a/ports/unix/proj/minimal/lwipopts.h b/ports/unix/proj/minimal/lwipopts.h index ff16c92..19321f4 100644 --- a/ports/unix/proj/minimal/lwipopts.h +++ b/ports/unix/proj/minimal/lwipopts.h @@ -43,12 +43,12 @@ /* MEM_SIZE: the size of the heap memory. If the application will send a lot of data that needs to be copied, this should be set high. */ -#define MEM_SIZE 1000 +#define MEM_SIZE 3000 /* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application sends a lot of data out of ROM (or other static memory), this should be set high. */ -#define MEMP_NUM_PBUF 8 +#define MEMP_NUM_PBUF 30 /* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One per active UDP "connection". */ #define MEMP_NUM_UDP_PCB 4 @@ -60,7 +60,7 @@ a lot of data that needs to be copied, this should be set high. */ #define MEMP_NUM_TCP_PCB_LISTEN 8 /* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. */ -#define MEMP_NUM_TCP_SEG 8 +#define MEMP_NUM_TCP_SEG 16 /* The following four are used only with the sequential API and can be set to 0 if the application only will use the raw API. */ diff --git a/ports/unix/proj/minimal/main.c b/ports/unix/proj/minimal/main.c index 7cb5736..727ddde 100644 --- a/ports/unix/proj/minimal/main.c +++ b/ports/unix/proj/minimal/main.c @@ -77,6 +77,8 @@ main(int argc, char **argv) netif_set_default(&netif); + netif_set_up(&netif); + echo_init(); printf("Applications started.\n"); @@ -84,8 +86,17 @@ main(int argc, char **argv) while (1) { - if (mintapif_wait(&netif, TCP_TMR_INTERVAL) == MINTAPIF_TIMEOUT) { - tcp_tmr(); + if (mintapif_wait(&netif, TCP_FAST_INTERVAL) == MINTAPIF_TIMEOUT) { + static u8_t slow_timer = 0; + + tcp_fasttmr(); + + if (slow_timer == 4) { + slow_timer = 0; + tcp_slowtmr(); + } else { + slow_timer++; + } } } diff --git a/ports/unix/proj/minimal/mintapif.c b/ports/unix/proj/minimal/mintapif.c index b621920..551be6c 100644 --- a/ports/unix/proj/minimal/mintapif.c +++ b/ports/unix/proj/minimal/mintapif.c @@ -43,14 +43,21 @@ #include #include -#ifdef linux +#if defined(linux) #include #include #include #define DEVTAP "/dev/net/tun" -#else /* linux */ +#define IFCONFIG_ARGS "tap0 inet %d.%d.%d.%d" + +#elif defined(openbsd) +#define DEVTAP "/dev/tun0" +#define IFCONFIG_ARGS "tun0 inet %d.%d.%d.%d link0" + +#else /* freebsd, cygwin? */ #define DEVTAP "/dev/tap0" -#endif /* linux */ +#define IFCONFIG_ARGS "tap0 inet %d.%d.%d.%d" +#endif #include "lwip/stats.h" #include "lwip/mem.h" @@ -113,7 +120,7 @@ low_level_init(struct netif *netif) } #endif /* Linux */ - snprintf(buf, sizeof(buf), "ifconfig tap0 inet %d.%d.%d.%d", + snprintf(buf, sizeof(buf), "/sbin/ifconfig " IFCONFIG_ARGS, ip4_addr1(&(netif->gw)), ip4_addr2(&(netif->gw)), ip4_addr3(&(netif->gw)), @@ -263,14 +270,15 @@ mintapif_input(struct netif *netif) switch (htons(ethhdr->type)) { case ETHTYPE_IP: - q = etharp_ip_input(netif, p); + etharp_ip_input(netif, p); pbuf_header(p, -14); netif->input(p, netif); break; case ETHTYPE_ARP: - q = etharp_arp_input(netif, mintapif->ethaddr, p); + etharp_arp_input(netif, mintapif->ethaddr, p); break; default: + LWIP_ASSERT("p != NULL", p != NULL); pbuf_free(p); break; } @@ -302,6 +310,8 @@ mintapif_init(struct netif *netif) mintapif->ethaddr = (struct eth_addr *)&(netif->hwaddr[0]); low_level_init(netif); + + return ERR_OK; } /*-----------------------------------------------------------------------------------*/ enum mintapif_signal diff --git a/ports/unix/proj/unixsim/Makefile b/ports/unix/proj/unixsim/Makefile index 2e012a0..f3db66f 100644 --- a/ports/unix/proj/unixsim/Makefile +++ b/ports/unix/proj/unixsim/Makefile @@ -76,7 +76,7 @@ NETIFFILES+=$(LWIPDIR)/netif/ppp/auth.c $(LWIPDIR)/netif/ppp/chap.c \ $(LWIPARCH)/netif/sio.c # ARCHFILES: Architecture specific files. -ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)/netif/tapif.c $(LWIPARCH)/netif/unixif.c $(LWIPARCH)/netif/list.c $(LWIPARCH)/netif/tcpdump.c) +ARCHFILES=$(wildcard $(LWIPARCH)/*.c $(LWIPARCH)/netif/tapif.c $(LWIPARCH)/netif/tunif.c $(LWIPARCH)/netif/unixif.c $(LWIPARCH)/netif/list.c $(LWIPARCH)/netif/tcpdump.c) # APPFILES: Applications. APPFILES=apps/fs.c apps/httpd.c \ diff --git a/ports/unix/proj/unixsim/apps/shell.c b/ports/unix/proj/unixsim/apps/shell.c index 2317877..64dd0a2 100644 --- a/ports/unix/proj/unixsim/apps/shell.c +++ b/ports/unix/proj/unixsim/apps/shell.c @@ -275,7 +275,7 @@ com_open(struct command *com) } sendstr("Opened connection, connection identifier is ", com->conn); - sprintf((char *)buffer, "%d\n", i); + snprintf((char *)buffer, sizeof(buffer), "%d\n", i); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS; @@ -337,7 +337,7 @@ com_lstn(struct command *com) } sendstr("Opened connection, connection identifier is ", com->conn); - sprintf((char *)buffer, "%d\n", i); + snprintf((char *)buffer, sizeof(buffer), "%d\n", i); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS; @@ -417,7 +417,7 @@ com_acpt(struct command *com) } sendstr("Accepted connection, connection identifier for new connection is ", com->conn); - sprintf((char *)buffer, "%d\n", j); + snprintf((char *)buffer, sizeof(buffer), "%d\n", j); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS; @@ -432,7 +432,7 @@ com_stat(struct command *com) u16_t len; for(i = 0; i < sizeof(struct stats_) / 2; i++) { - len = sprintf(buf, "%d", ((u16_t *)&lwip_stats)[i]); + len = snprintf(buf, sizeof(buffer), "%d", ((u16_t *)&lwip_stats)[i]); sendstr(stat_msgs[i], com->conn); netconn_write(com->conn, buf, len, NETCONN_COPY); sendstr("\n", com->conn); @@ -594,7 +594,7 @@ com_udpc(struct command *com) } sendstr("Connection set up, connection identifier is ", com->conn); - sprintf((char *)buffer, "%d\n", i); + snprintf((char *)buffer, sizeof(buffer), "%d\n", i); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS; @@ -666,7 +666,7 @@ com_udpl(struct command *com) } sendstr("Connection set up, connection identifier is ", com->conn); - sprintf((char *)buffer, "%d\n", i); + snprintf((char *)buffer, sizeof(buffer), "%d\n", i); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS; @@ -738,7 +738,7 @@ com_udpn(struct command *com) } sendstr("Connection set up, connection identifier is ", com->conn); - sprintf((char *)buffer, "%d\n", i); + snprintf((char *)buffer, sizeof(buffer), "%d\n", i); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS; @@ -810,7 +810,7 @@ com_udpb(struct command *com) } sendstr("Connection set up, connection identifier is ", com->conn); - sprintf((char *)buffer, "%d\n", i); + snprintf((char *)buffer, sizeof(buffer), "%d\n", i); netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY); return ESUCCESS;