From e00e4a6c134305e251d39c4575995ca91989766d Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Wed, 23 Sep 2015 13:19:56 +0200 Subject: [PATCH] make netif_ip4_* get accessors return const pointers --- src/core/netif.c | 6 +++--- src/core/raw.c | 2 +- src/core/snmp/mib_structs.c | 2 +- src/core/snmp/msg_out.c | 2 +- src/core/tcp.c | 2 +- src/core/tcp_out.c | 2 +- src/include/lwip/ip_addr.h | 4 ++-- src/include/lwip/netif.h | 6 +++--- src/include/lwip/snmp_structs.h | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core/netif.c b/src/core/netif.c index fff58937..e13f182d 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -435,7 +435,7 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) mib2_remove_ip4(netif); mib2_remove_route_ip4(0, netif); /* set new IP address to netif */ - ip4_addr_set(netif_ip4_addr(netif), ipaddr); + ip4_addr_set(&netif->ip_addr, ipaddr); mib2_add_ip4(netif); mib2_add_route_ip4(0, netif); @@ -463,7 +463,7 @@ netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr) void netif_set_gw(struct netif *netif, const ip4_addr_t *gw) { - ip4_addr_set(netif_ip4_gw(netif), gw); + ip4_addr_set(&netif->gw, gw); LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", netif->name[0], netif->name[1], ip4_addr1_16(netif_ip4_gw(netif)), @@ -486,7 +486,7 @@ netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask) { mib2_remove_route_ip4(0, netif); /* set new netmask to netif */ - ip4_addr_set(netif_ip4_netmask(netif), netmask); + ip4_addr_set(&netif->netmask, netmask); mib2_add_route_ip4(0, netif); LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", netif->name[0], netif->name[1], diff --git a/src/core/raw.c b/src/core/raw.c index c8d079a2..0f30969d 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -237,7 +237,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr) { err_t err; struct netif *netif; - ip_addr_t *src_ip; + const ip_addr_t *src_ip; struct pbuf *q; /* q will be sent down the stack */ s16_t header_size; const ip_addr_t *dst_ip = ipaddr; diff --git a/src/core/snmp/mib_structs.c b/src/core/snmp/mib_structs.c index e137b7bf..e31764db 100644 --- a/src/core/snmp/mib_structs.c +++ b/src/core/snmp/mib_structs.c @@ -145,7 +145,7 @@ snmp_oidtoip(s32_t *ident, ip4_addr_t *ip) * @param ident points to s32_t ident[4] output */ void -snmp_iptooid(ip4_addr_t *ip, s32_t *ident) +snmp_iptooid(const ip4_addr_t *ip, s32_t *ident) { ident[0] = ip4_addr1(ip); ident[1] = ip4_addr2(ip); diff --git a/src/core/snmp/msg_out.c b/src/core/snmp/msg_out.c index 134690bb..7c534dfe 100644 --- a/src/core/snmp/msg_out.c +++ b/src/core/snmp/msg_out.c @@ -231,7 +231,7 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific #if LWIP_IPV4 && LWIP_IPV6 ip_addr_t dst_ip_storage; #endif /* LWIP_IPV4 && LWIP_IPV6 */ - ip_addr_t* dst_ip; + const ip_addr_t* dst_ip; struct pbuf *p; u16_t i,tot_len; err_t err = ERR_OK; diff --git a/src/core/tcp.c b/src/core/tcp.c index 52332521..160e038d 100644 --- a/src/core/tcp.c +++ b/src/core/tcp.c @@ -777,7 +777,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, if (ip_addr_isany(&pcb->local_ip)) { /* no local IP address set, yet. */ struct netif *netif; - ip_addr_t *local_ip; + const ip_addr_t *local_ip; ip_route_get_local_ip(PCB_ISIPV6(pcb), &pcb->local_ip, &pcb->remote_ip, netif, local_ip, &local_ip_tmp); if ((netif == NULL) || (local_ip == NULL)) { /* Don't even try to send a SYN packet if we have no route diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index c9ab8ea4..c072d360 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -1197,7 +1197,7 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb) /* If we don't have a local IP address, we get one from netif */ if (ip_addr_isany(&pcb->local_ip)) { - ip_addr_t *local_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, + const ip_addr_t *local_ip = ip_netif_get_local_ip(PCB_ISIPV6(pcb), netif, &pcb->remote_ip, &pcb->local_ip); if (local_ip == NULL) { return ERR_RTE; diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index d86926b3..eab3171e 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -95,8 +95,8 @@ static const ip4_addr_t* ip_2_ip4_c(const ip_addr_t *ipaddr) IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0) #define ip_addr_copy(dest, src) do{if(IP_IS_V6_VAL(src)){ \ - ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }else{ \ - ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); }}while(0) + ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6_c(&(src))); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }else{ \ + ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4_c(&(src))); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); }}while(0) #define ip_addr_copy_from_ip6(dest, src) do{ \ ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0) #define ip_addr_copy_from_ip4(dest, src) do{ \ diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 7bd4caef..9200b6c0 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -349,9 +349,9 @@ void netif_set_default(struct netif *netif); void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr); void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask); void netif_set_gw(struct netif *netif, const ip4_addr_t *gw); -#define netif_ip4_addr(netif) (&((netif)->ip_addr)) -#define netif_ip4_netmask(netif) (&((netif)->netmask)) -#define netif_ip4_gw(netif) (&((netif)->gw)) +#define netif_ip4_addr(netif) ((const ip4_addr_t*)&((netif)->ip_addr)) +#define netif_ip4_netmask(netif) ((const ip4_addr_t*)&((netif)->netmask)) +#define netif_ip4_gw(netif) ((const ip4_addr_t*)&((netif)->gw)) #endif /* LWIP_IPV4 */ void netif_set_up(struct netif *netif); diff --git a/src/include/lwip/snmp_structs.h b/src/include/lwip/snmp_structs.h index 4ed28668..1a1201c4 100644 --- a/src/include/lwip/snmp_structs.h +++ b/src/include/lwip/snmp_structs.h @@ -241,7 +241,7 @@ u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value); void noleafs_set_value(struct obj_def *od, u16_t len, void *value); void snmp_oidtoip(s32_t *ident, ip4_addr_t *ip); -void snmp_iptooid(ip4_addr_t *ip, s32_t *ident); +void snmp_iptooid(const ip4_addr_t *ip, s32_t *ident); void snmp_ifindextonetif(s32_t ifindex, struct netif **netif); void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);