From e20a0719774dfc5231695d0cf2fa7ab55d1b8d6e Mon Sep 17 00:00:00 2001 From: sg Date: Fri, 24 Apr 2015 21:23:15 +0200 Subject: [PATCH] added functions dhcp/autoip_supplied_address() to check for the source of address assignemnt (replacement for NETIF_FLAG_DHCP) --- CHANGELOG | 4 ++++ src/core/dhcp.c | 18 ++++++++++++++++++ src/core/ipv4/autoip.c | 17 +++++++++++++++++ src/include/lwip/autoip.h | 3 +++ src/include/lwip/dhcp.h | 3 +++ 5 files changed, 45 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index d166da3f..2b144a65 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,10 @@ HISTORY ++ New features: + 2015-04-24: Simon Goldschmidt + * dhcp.h/c, autoip.h/.c: added functions dhcp/autoip_supplied_address() to + check for the source of address assignemnt (replacement for NETIF_FLAG_DHCP) + 2015-04-10: Simon Goldschmidt * many files: task #13480: added LWIP_IPV4 define - IPv4 can be disabled, leaving an IPv6-only stack diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 634ec4ec..aa769791 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -1820,4 +1820,22 @@ dhcp_option_trailer(struct dhcp *dhcp) } } +/** check if DHCP supplied netif->ip_addr + * + * @param netif the netif to check + * @return 1 if DHCP supplied netif->ip_addr (states BOUND or RENEWING), + * 0 otherwise + */ +u8_t +dhcp_supplied_address(struct netif *netif) +{ + if ((netif != NULL) && (netif->dhcp != NULL)) { + if ((netif->dhcp->state == DHCP_BOUND) || + (netif->dhcp->state == DHCP_RENEWING)) { + return 1; + } + } + return 0; +} + #endif /* LWIP_IPV4 && LWIP_DHCP */ diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 4837df2f..920d67ff 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -520,4 +520,21 @@ autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) } } +/** check if AutoIP supplied netif->ip_addr + * + * @param netif the netif to check + * @return 1 if AutoIP supplied netif->ip_addr (state BOUND), + * 0 otherwise + */ +u8_t +autoip_supplied_address(struct netif *netif) +{ + if ((netif != NULL) && (netif->autoip != NULL)) { + if (netif->autoip->state == AUTOIP_STATE_BOUND) { + return 1; + } + } + return 0; +} + #endif /* LWIP_IPV4 && LWIP_AUTOIP */ diff --git a/src/include/lwip/autoip.h b/src/include/lwip/autoip.h index e405aa22..392622ea 100644 --- a/src/include/lwip/autoip.h +++ b/src/include/lwip/autoip.h @@ -112,6 +112,9 @@ void autoip_tmr(void); /** Handle a possible change in the network configuration */ void autoip_network_changed(struct netif *netif); +/** check if AutoIP supplied netif->ip_addr */ +u8_t autoip_supplied_address(struct netif *netif); + #ifdef __cplusplus } #endif diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index 407868db..c9c0608b 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -129,6 +129,9 @@ void dhcp_network_changed(struct netif *netif); void dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr); #endif +/** check if DHCP supplied netif->ip_addr */ +u8_t dhcp_supplied_address(struct netif *netif); + /** to be called every minute */ void dhcp_coarse_tmr(void); /** to be called every half second */