diff --git a/src/core/netif.c b/src/core/netif.c index 549a3972..31396e1a 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -55,7 +55,7 @@ struct netif * netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, - void (* init)(struct netif *netif), + err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif)) { struct netif *netif; @@ -74,8 +74,11 @@ netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, ip_addr_set(&(netif->netmask), netmask); ip_addr_set(&(netif->gw), gw); - init(netif); - + if (init(netif) != ERR_OK) { + mem_free(netif); + return NULL; + } + netif->next = netif_list; netif_list = netif; #if NETIF_DEBUG diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index c7a52e2b..baab539d 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -58,6 +58,7 @@ typedef s8_t err_t; #define ERR_USE -10 /* Address in use. */ +#define ERR_IF -11 /* Low-level netif error */ #ifdef LWIP_DEBUG diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 9fbc4826..e92ead72 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -114,7 +114,7 @@ void netif_init(void); struct netif *netif_add(struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, - void (* init)(struct netif *netif), + err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif)); void netif_remove(struct netif * netif); diff --git a/src/include/netif/loopif.h b/src/include/netif/loopif.h index cdd6dd23..086f8121 100644 --- a/src/include/netif/loopif.h +++ b/src/include/netif/loopif.h @@ -34,6 +34,6 @@ #include "lwip/netif.h" -void loopif_init(struct netif *netif); +err_t loopif_init(struct netif *netif); #endif /* __NETIF_LOOPIF_H__ */ diff --git a/src/include/netif/slipif.h b/src/include/netif/slipif.h index af9393f0..bf70046a 100644 --- a/src/include/netif/slipif.h +++ b/src/include/netif/slipif.h @@ -36,7 +36,7 @@ #include "lwip/netif.h" -void slipif_init(struct netif * netif); +err_t slipif_init(struct netif * netif); #endif diff --git a/src/netif/loopif.c b/src/netif/loopif.c index 40b85edf..bdfef854 100644 --- a/src/netif/loopif.c +++ b/src/netif/loopif.c @@ -67,12 +67,13 @@ loopif_output(struct netif *netif, struct pbuf *p, return ERR_MEM; } /*-----------------------------------------------------------------------------------*/ -void +err_t loopif_init(struct netif *netif) { netif->name[0] = 'l'; netif->name[1] = 'o'; netif->output = loopif_output; + return ERR_OK; } /*-----------------------------------------------------------------------------------*/ diff --git a/src/netif/slipif.c b/src/netif/slipif.c index 7f360f51..49136f1b 100644 --- a/src/netif/slipif.c +++ b/src/netif/slipif.c @@ -197,7 +197,7 @@ slipif_loop(void *nf) * Call the arch specific sio_open and remember * the opened device in the state field of the netif. */ -void +err_t slipif_init(struct netif *netif) { @@ -209,6 +209,9 @@ slipif_init(struct netif *netif) netif->mtu = 1500; netif->state = sio_open(netif->num); + if (!netif->state) + return ERR_IF; sys_thread_new(slipif_loop, netif); + return ERR_OK; }