mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-24 04:43:39 +00:00
Use macros defined in ip_addr.h (some of them new) to work with IP addresses (preparation for bug #27352 - Change ip_addr from struct to typedef (u32_t) - and better code).
This commit is contained in:
parent
258fe88232
commit
a23b446ddf
@ -80,6 +80,11 @@ HISTORY
|
||||
|
||||
++ Bugfixes:
|
||||
|
||||
2010-02-04: Simon Goldschmidt
|
||||
* nearly every file: Use macros defined in ip_addr.h (some of them new)
|
||||
to work with IP addresses (preparation for bug #27352 - Change ip_addr
|
||||
from struct to typedef (u32_t) - and better code).
|
||||
|
||||
2010-01-31: Simon Goldschmidt
|
||||
* netif.c: Don't call the link-callback from netif_set_up/down() since
|
||||
this invalidly retriggers DHCP.
|
||||
|
@ -128,7 +128,7 @@ lwip_gethostbyname(const char *name)
|
||||
u8_t idx;
|
||||
for ( idx=0; s_hostent.h_addr_list[idx]; idx++) {
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i] == %p\n", idx, s_hostent.h_addr_list[idx]));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ip_ntoa(s_hostent.h_addr_list[idx])));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("hostent.h_addr_list[%i]-> == %s\n", idx, ip_ntoa((struct ip_addr*)s_hostent.h_addr_list[idx])));
|
||||
}
|
||||
}
|
||||
#endif /* DNS_DEBUG */
|
||||
@ -298,7 +298,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
}
|
||||
} else {
|
||||
/* service location specified, use loopback address */
|
||||
addr.addr = htonl(IPADDR_LOOPBACK);
|
||||
ip_addr_set_loopback(&addr);
|
||||
}
|
||||
|
||||
total_size = sizeof(struct addrinfo) + sizeof(struct sockaddr_in);
|
||||
@ -317,7 +317,7 @@ lwip_getaddrinfo(const char *nodename, const char *servname,
|
||||
memset(ai, 0, total_size);
|
||||
sa = (struct sockaddr_in*)((u8_t*)ai + sizeof(struct addrinfo));
|
||||
/* set up sockaddr */
|
||||
sa->sin_addr.s_addr = addr.addr;
|
||||
inet_addr_from_ipaddr(&sa->sin_addr, &addr);
|
||||
sa->sin_family = AF_INET;
|
||||
sa->sin_len = sizeof(struct sockaddr_in);
|
||||
sa->sin_port = htons((u16_t)port_nr);
|
||||
|
@ -317,7 +317,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||
sin.sin_len = sizeof(sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
sin.sin_addr.s_addr = naddr.addr;
|
||||
inet_addr_from_ipaddr(&sin.sin_addr, &naddr);
|
||||
|
||||
if (*addrlen > sizeof(sin))
|
||||
*addrlen = sizeof(sin);
|
||||
@ -370,7 +370,7 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
((((const struct sockaddr_in *)name)->sin_family) == AF_INET)),
|
||||
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
|
||||
|
||||
local_addr.addr = ((const struct sockaddr_in *)name)->sin_addr.s_addr;
|
||||
inet_addr_to_ipaddr(&local_addr, &((const struct sockaddr_in *)name)->sin_addr);
|
||||
local_port = ((const struct sockaddr_in *)name)->sin_port;
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
|
||||
@ -430,7 +430,7 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
|
||||
struct ip_addr remote_addr;
|
||||
u16_t remote_port;
|
||||
|
||||
remote_addr.addr = ((const struct sockaddr_in *)name)->sin_addr.s_addr;
|
||||
inet_addr_to_ipaddr(&remote_addr, &((const struct sockaddr_in *)name)->sin_addr);
|
||||
remote_port = ((const struct sockaddr_in *)name)->sin_port;
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
|
||||
@ -593,7 +593,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
|
||||
sin.sin_len = sizeof(sin);
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
sin.sin_addr.s_addr = addr->addr;
|
||||
inet_addr_from_ipaddr(&sin.sin_addr, addr);
|
||||
|
||||
if (*fromlen > sizeof(sin)) {
|
||||
*fromlen = sizeof(sin);
|
||||
@ -730,7 +730,7 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
||||
p->payload = (void*)data;
|
||||
p->len = p->tot_len = short_size;
|
||||
|
||||
remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
|
||||
inet_addr_to_ipaddr(&remote_addr, &((const struct sockaddr_in *)to)->sin_addr);
|
||||
|
||||
LOCK_TCPIP_CORE();
|
||||
if (sock->conn->type==NETCONN_RAW) {
|
||||
@ -747,12 +747,12 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
||||
/* initialize a buffer */
|
||||
buf.p = buf.ptr = NULL;
|
||||
if (to) {
|
||||
remote_addr.addr = ((const struct sockaddr_in *)to)->sin_addr.s_addr;
|
||||
inet_addr_to_ipaddr(&remote_addr, &((const struct sockaddr_in *)to)->sin_addr);
|
||||
remote_port = ntohs(((const struct sockaddr_in *)to)->sin_port);
|
||||
buf.addr = &remote_addr;
|
||||
buf.port = remote_port;
|
||||
} else {
|
||||
remote_addr.addr = 0;
|
||||
ip_addr_set_zero(&remote_addr);
|
||||
remote_port = 0;
|
||||
buf.addr = NULL;
|
||||
buf.port = 0;
|
||||
@ -1194,7 +1194,7 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", sin.sin_port));
|
||||
|
||||
sin.sin_port = htons(sin.sin_port);
|
||||
sin.sin_addr.s_addr = naddr.addr;
|
||||
inet_addr_from_ipaddr(&sin.sin_addr, &naddr);
|
||||
|
||||
if (*namelen > sizeof(sin))
|
||||
*namelen = sizeof(sin);
|
||||
@ -1516,7 +1516,7 @@ lwip_getsockopt_internal(void *arg)
|
||||
s, *(int *)optval));
|
||||
break;
|
||||
case IP_MULTICAST_IF:
|
||||
((struct in_addr*) optval)->s_addr = sock->conn->pcb.udp->multicast_ip.addr;
|
||||
inet_addr_from_ipaddr((struct in_addr*)optval, &sock->conn->pcb.udp->multicast_ip);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_IF) = 0x%"X32_F"\n",
|
||||
s, *(u32_t *)optval));
|
||||
break;
|
||||
@ -1863,7 +1863,7 @@ lwip_setsockopt_internal(void *arg)
|
||||
sock->conn->pcb.udp->ttl = (u8_t)(*(u8_t*)optval);
|
||||
break;
|
||||
case IP_MULTICAST_IF:
|
||||
sock->conn->pcb.udp->multicast_ip.addr = ((struct in_addr*) optval)->s_addr;
|
||||
inet_addr_to_ipaddr(&sock->conn->pcb.udp->multicast_ip, (struct in_addr*)optval);
|
||||
break;
|
||||
case IP_ADD_MEMBERSHIP:
|
||||
case IP_DROP_MEMBERSHIP:
|
||||
|
@ -242,11 +242,13 @@ dhcp_handle_offer(struct netif *netif)
|
||||
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
|
||||
/* obtain the server address */
|
||||
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SERVER_ID)) {
|
||||
dhcp->server_ip_addr.addr = htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n", dhcp->server_ip_addr.addr));
|
||||
ip4_addr_set_u32(&dhcp->server_ip_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID)));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n",
|
||||
ip4_addr_get_u32(&dhcp->server_ip_addr)));
|
||||
/* remember offered address */
|
||||
ip_addr_set(&dhcp->offered_ip_addr, &dhcp->msg_in->yiaddr);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08"X32_F"\n", dhcp->offered_ip_addr.addr));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08"X32_F"\n",
|
||||
ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
|
||||
dhcp_select(netif);
|
||||
} else {
|
||||
@ -287,10 +289,10 @@ dhcp_select(struct netif *netif)
|
||||
|
||||
/* MUST request the offered IP address */
|
||||
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
|
||||
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));
|
||||
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
|
||||
dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
|
||||
dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr));
|
||||
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->server_ip_addr)));
|
||||
|
||||
dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/);
|
||||
dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
|
||||
@ -501,10 +503,10 @@ dhcp_handle_ack(struct netif *netif)
|
||||
u8_t n;
|
||||
|
||||
/* clear options we might not get from the ACK */
|
||||
dhcp->offered_sn_mask.addr = 0;
|
||||
dhcp->offered_gw_addr.addr = 0;
|
||||
ip_addr_set_zero(&dhcp->offered_sn_mask);
|
||||
ip_addr_set_zero(&dhcp->offered_gw_addr);
|
||||
#if LWIP_DHCP_BOOTP_FILE
|
||||
dhcp->offered_si_addr.addr = 0;
|
||||
ip_addr_set_zero(&dhcp->offered_si_addr);
|
||||
#endif /* LWIP_DHCP_BOOTP_FILE */
|
||||
|
||||
/* lease time given? */
|
||||
@ -542,7 +544,7 @@ dhcp_handle_ack(struct netif *netif)
|
||||
/* subnet mask given? */
|
||||
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)) {
|
||||
/* remember given subnet mask */
|
||||
dhcp->offered_sn_mask.addr = htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SUBNET_MASK));
|
||||
ip4_addr_set_u32(&dhcp->offered_sn_mask, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)));
|
||||
dhcp->subnet_mask_given = 1;
|
||||
} else {
|
||||
dhcp->subnet_mask_given = 0;
|
||||
@ -550,7 +552,7 @@ dhcp_handle_ack(struct netif *netif)
|
||||
|
||||
/* gateway router */
|
||||
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_ROUTER)) {
|
||||
dhcp->offered_gw_addr.addr = htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER));
|
||||
ip4_addr_set_u32(&dhcp->offered_gw_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER)));
|
||||
}
|
||||
|
||||
#if LWIP_DNS
|
||||
@ -558,7 +560,7 @@ dhcp_handle_ack(struct netif *netif)
|
||||
n = 0;
|
||||
while(dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n) && (n < DNS_MAX_SERVERS)) {
|
||||
struct ip_addr dns_addr;
|
||||
dns_addr.addr = htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n));
|
||||
ip4_addr_set_u32(&dns_addr, htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
|
||||
dns_setserver(n, &dns_addr);
|
||||
n++;
|
||||
}
|
||||
@ -760,7 +762,8 @@ void dhcp_arp_reply(struct netif *netif, struct ip_addr *addr)
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_arp_reply()\n"));
|
||||
/* is a DHCP client doing an ARP check? */
|
||||
if ((netif->dhcp != NULL) && (netif->dhcp->state == DHCP_CHECKING)) {
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08"X32_F"\n", addr->addr));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08"X32_F"\n",
|
||||
ip4_addr_get_u32(addr)));
|
||||
/* did a host respond with the address we
|
||||
were offered by the DHCP server? */
|
||||
if (ip_addr_cmp(addr, &netif->dhcp->offered_ip_addr)) {
|
||||
@ -796,7 +799,7 @@ dhcp_decline(struct netif *netif)
|
||||
dhcp_option_byte(dhcp, DHCP_DECLINE);
|
||||
|
||||
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
|
||||
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));
|
||||
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
|
||||
dhcp_option_trailer(dhcp);
|
||||
/* resize pbuf to reflect true size of options */
|
||||
@ -925,23 +928,23 @@ dhcp_bind(struct netif *netif)
|
||||
ip_addr_set(&sn_mask, &dhcp->offered_sn_mask);
|
||||
} else {
|
||||
/* subnet mask not given, choose a safe subnet mask given the network class */
|
||||
u8_t first_octet = (u8_t)ip4_addr1(&dhcp->offered_ip_addr);
|
||||
u8_t first_octet = (u8_t)ip4_addr1_16(&dhcp->offered_ip_addr);
|
||||
if (first_octet <= 127) {
|
||||
sn_mask.addr = htonl(0xff000000);
|
||||
ip4_addr_set_u32(&sn_mask, htonl(0xff000000));
|
||||
} else if (first_octet >= 192) {
|
||||
sn_mask.addr = htonl(0xffffff00);
|
||||
ip4_addr_set_u32(&sn_mask, htonl(0xffffff00));
|
||||
} else {
|
||||
sn_mask.addr = htonl(0xffff0000);
|
||||
ip4_addr_set_u32(&sn_mask, htonl(0xffff0000));
|
||||
}
|
||||
}
|
||||
|
||||
ip_addr_set(&gw_addr, &dhcp->offered_gw_addr);
|
||||
/* gateway address not given? */
|
||||
if (gw_addr.addr == 0) {
|
||||
if (ip_addr_isany(&gw_addr)) {
|
||||
/* copy network address */
|
||||
gw_addr.addr = (dhcp->offered_ip_addr.addr & sn_mask.addr);
|
||||
ip_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
|
||||
/* use first host address on network as gateway */
|
||||
gw_addr.addr |= htonl(0x00000001);
|
||||
ip4_addr_set_u32(&gw_addr, ip4_addr_get_u32(&gw_addr) | htonl(0x00000001));
|
||||
}
|
||||
|
||||
#if LWIP_DHCP_AUTOIP_COOP
|
||||
@ -951,11 +954,14 @@ dhcp_bind(struct netif *netif)
|
||||
}
|
||||
#endif /* LWIP_DHCP_AUTOIP_COOP */
|
||||
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n", dhcp->offered_ip_addr.addr));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F"\n",
|
||||
ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
netif_set_ipaddr(netif, &dhcp->offered_ip_addr);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): SN: 0x%08"X32_F"\n", sn_mask.addr));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): SN: 0x%08"X32_F"\n",
|
||||
ip4_addr_get_u32(&sn_mask)));
|
||||
netif_set_netmask(netif, &sn_mask);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n", gw_addr.addr));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): GW: 0x%08"X32_F"\n",
|
||||
ip4_addr_get_u32(&gw_addr)));
|
||||
netif_set_gw(netif, &gw_addr);
|
||||
/* bring the interface up */
|
||||
netif_set_up(netif);
|
||||
@ -1121,7 +1127,7 @@ dhcp_reboot(struct netif *netif)
|
||||
dhcp_option_short(dhcp, 576);
|
||||
|
||||
dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
|
||||
dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));
|
||||
dhcp_option_long(dhcp, ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
|
||||
|
||||
dhcp_option_trailer(dhcp);
|
||||
|
||||
@ -1158,12 +1164,12 @@ dhcp_release(struct netif *netif)
|
||||
/* idle DHCP client */
|
||||
dhcp_set_state(dhcp, DHCP_OFF);
|
||||
/* clean old DHCP offer */
|
||||
dhcp->server_ip_addr.addr = 0;
|
||||
dhcp->offered_ip_addr.addr = 0;
|
||||
dhcp->offered_sn_mask.addr = 0;
|
||||
dhcp->offered_gw_addr.addr = 0;
|
||||
ip_addr_set_zero(&dhcp->server_ip_addr);
|
||||
ip_addr_set_zero(&dhcp->offered_ip_addr);
|
||||
ip_addr_set_zero(&dhcp->offered_sn_mask);
|
||||
ip_addr_set_zero(&dhcp->offered_gw_addr);
|
||||
#if LWIP_DHCP_BOOTP_FILE
|
||||
dhcp->offered_si_addr.addr = 0;
|
||||
ip_addr_set_zero(&dhcp->offered_si_addr);
|
||||
#endif /* LWIP_DHCP_BOOTP_FILE */
|
||||
dhcp->offered_t0_lease = dhcp->offered_t1_renew = dhcp->offered_t2_rebind = 0;
|
||||
|
||||
@ -1495,8 +1501,7 @@ dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr,
|
||||
u8_t msg_type;
|
||||
u8_t i;
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_recv(pbuf = %p) from DHCP server %"U16_F".%"U16_F".%"U16_F".%"U16_F" port %"U16_F"\n", (void*)p,
|
||||
(u16_t)(ntohl(addr->addr) >> 24 & 0xff), (u16_t)(ntohl(addr->addr) >> 16 & 0xff),
|
||||
(u16_t)(ntohl(addr->addr) >> 8 & 0xff), (u16_t)(ntohl(addr->addr) & 0xff), port));
|
||||
ip4_addr1_16(addr), ip4_addr2_16(addr), ip4_addr3_16(addr), ip4_addr4_16(addr), port));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->len = %"U16_F"\n", p->len));
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->tot_len = %"U16_F"\n", p->tot_len));
|
||||
/* prevent warnings about unused arguments */
|
||||
@ -1640,13 +1645,13 @@ dhcp_create_request(struct netif *netif, struct dhcp *dhcp)
|
||||
/* we don't need the broadcast flag since we can receive unicast traffic
|
||||
before being fully configured! */
|
||||
dhcp->msg_out->flags = 0;
|
||||
dhcp->msg_out->ciaddr.addr = 0;
|
||||
ip_addr_set_zero(&dhcp->msg_out->ciaddr);
|
||||
if (dhcp->state==DHCP_BOUND || dhcp->state==DHCP_RENEWING || dhcp->state==DHCP_REBINDING) {
|
||||
dhcp->msg_out->ciaddr.addr = netif->ip_addr.addr;
|
||||
ip_addr_set(&dhcp->msg_out->ciaddr, &netif->ip_addr);
|
||||
}
|
||||
dhcp->msg_out->yiaddr.addr = 0;
|
||||
dhcp->msg_out->siaddr.addr = 0;
|
||||
dhcp->msg_out->giaddr.addr = 0;
|
||||
ip_addr_set_zero(&dhcp->msg_out->yiaddr);
|
||||
ip_addr_set_zero(&dhcp->msg_out->siaddr);
|
||||
ip_addr_set_zero(&dhcp->msg_out->giaddr);
|
||||
for (i = 0; i < DHCP_CHADDR_LEN; i++) {
|
||||
/* copy netif hardware address, pad with zeroes */
|
||||
dhcp->msg_out->chaddr[i] = (i < netif->hwaddr_len) ? netif->hwaddr[i] : 0/* pad byte*/;
|
||||
|
@ -84,7 +84,7 @@
|
||||
|
||||
/** DNS server IP address */
|
||||
#ifndef DNS_SERVER_ADDRESS
|
||||
#define DNS_SERVER_ADDRESS ipaddr_addr("208.67.222.222") /* resolver1.opendns.com */
|
||||
#define DNS_SERVER_ADDRESS(ipaddr) (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */
|
||||
#endif
|
||||
|
||||
/** DNS server port address */
|
||||
@ -199,7 +199,7 @@ struct local_hostlist_entry {
|
||||
/** static hostname */
|
||||
const char *name;
|
||||
/** static host address in network byteorder */
|
||||
u32_t addr;
|
||||
struct ip_addr addr;
|
||||
struct local_hostlist_entry *next;
|
||||
};
|
||||
|
||||
@ -256,7 +256,7 @@ dns_init()
|
||||
struct ip_addr dnsserver;
|
||||
|
||||
/* initialize default DNS server address */
|
||||
dnsserver.addr = DNS_SERVER_ADDRESS;
|
||||
DNS_SERVER_ADDRESS(&dnsserver);
|
||||
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_init: initializing\n"));
|
||||
|
||||
@ -293,7 +293,7 @@ void
|
||||
dns_setserver(u8_t numdns, struct ip_addr *dnsserver)
|
||||
{
|
||||
if ((numdns < DNS_MAX_SERVERS) && (dns_pcb != NULL) &&
|
||||
(dnsserver != NULL) && (dnsserver->addr !=0 )) {
|
||||
(dnsserver != NULL) && !ip_addr_isany(dnsserver)) {
|
||||
dns_servers[numdns] = (*dnsserver);
|
||||
}
|
||||
}
|
||||
@ -370,7 +370,7 @@ dns_lookup_local(const char *hostname)
|
||||
struct local_hostlist_entry *entry = local_hostlist_dynamic;
|
||||
while(entry != NULL) {
|
||||
if(strcmp(entry->name, hostname) == 0) {
|
||||
return entry->addr;
|
||||
return ip4_addr_get_u32(&entry->addr);
|
||||
}
|
||||
entry = entry->next;
|
||||
}
|
||||
@ -378,7 +378,7 @@ dns_lookup_local(const char *hostname)
|
||||
int i;
|
||||
for (i = 0; i < sizeof(local_hostlist_static) / sizeof(struct local_hostlist_entry); i++) {
|
||||
if(strcmp(local_hostlist_static[i].name, hostname) == 0) {
|
||||
return local_hostlist_static[i].addr;
|
||||
return ip4_addr_get_u32(&local_hostlist_static[i].addr);
|
||||
}
|
||||
}
|
||||
#endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
|
||||
@ -402,7 +402,7 @@ dns_local_removehost(const char *hostname, const struct ip_addr *addr)
|
||||
struct local_hostlist_entry *last_entry = NULL;
|
||||
while (entry != NULL) {
|
||||
if (((hostname == NULL) || !strcmp(entry->name, hostname)) &&
|
||||
((addr == NULL) || (entry->addr == addr->addr))) {
|
||||
((addr == NULL) || ip_addr_cmp(&entry->addr, addr))) {
|
||||
struct local_hostlist_entry *free_entry;
|
||||
if (last_entry != NULL) {
|
||||
last_entry->next = entry->next;
|
||||
@ -443,7 +443,7 @@ dns_local_addhost(const char *hostname, const struct ip_addr *addr)
|
||||
entry->name = (char*)entry + sizeof(struct local_hostlist_entry);
|
||||
MEMCPY((char*)entry->name, hostname, namelen);
|
||||
((char*)entry->name)[namelen] = 0;
|
||||
entry->addr = addr->addr;
|
||||
ip_addr_set(&entry->addr, addr);
|
||||
entry->next = local_hostlist_dynamic;
|
||||
local_hostlist_dynamic = entry;
|
||||
return ERR_OK;
|
||||
@ -489,7 +489,7 @@ dns_lookup(const char *name)
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_lookup: \"%s\": found = ", name));
|
||||
ip_addr_debug_print(DNS_DEBUG, &(dns_table[i].ipaddr));
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("\n"));
|
||||
return dns_table[i].ipaddr.addr;
|
||||
return ip4_addr_get_u32(&dns_table[i].ipaddr);
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,7 +588,7 @@ dns_send(u8_t numdns, const char* name, u8_t id)
|
||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_send: dns_servers[%"U16_F"] \"%s\": request\n",
|
||||
(u16_t)(numdns), name));
|
||||
LWIP_ASSERT("dns server out of array", numdns < DNS_MAX_SERVERS);
|
||||
LWIP_ASSERT("dns server has no IP address set", dns_servers[numdns].addr != 0);
|
||||
LWIP_ASSERT("dns server has no IP address set", !ip_addr_isany(&dns_servers[numdns]));
|
||||
|
||||
/* if here, we have either a new query or a retry on a previous query to process */
|
||||
p = pbuf_alloc(PBUF_TRANSPORT, SIZEOF_DNS_HDR + DNS_MAX_NAME_LENGTH +
|
||||
@ -674,7 +674,7 @@ dns_check_entry(u8_t i)
|
||||
case DNS_STATE_ASKING: {
|
||||
if (--pEntry->tmr == 0) {
|
||||
if (++pEntry->retries == DNS_MAX_RETRIES) {
|
||||
if ((pEntry->numdns+1<DNS_MAX_SERVERS) && (dns_servers[pEntry->numdns+1].addr!=0)) {
|
||||
if ((pEntry->numdns+1<DNS_MAX_SERVERS) && !ip_addr_isany(&dns_servers[pEntry->numdns+1])) {
|
||||
/* change of server */
|
||||
pEntry->numdns++;
|
||||
pEntry->tmr = 1;
|
||||
@ -961,6 +961,7 @@ err_t
|
||||
dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback found,
|
||||
void *callback_arg)
|
||||
{
|
||||
u32_t ipaddr;
|
||||
/* not initialized or no valid server yet, or invalid addr pointer
|
||||
* or invalid hostname or invalid hostname length */
|
||||
if ((dns_pcb == NULL) || (addr == NULL) ||
|
||||
@ -971,15 +972,19 @@ dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback
|
||||
|
||||
#if LWIP_HAVE_LOOPIF
|
||||
if (strcmp(hostname,"localhost")==0) {
|
||||
addr->addr = htonl(IPADDR_LOOPBACK);
|
||||
ip_addr_set_loopback(addr);
|
||||
return ERR_OK;
|
||||
}
|
||||
#endif /* LWIP_HAVE_LOOPIF */
|
||||
|
||||
/* host name already in octet notation? set ip addr and return ERR_OK
|
||||
* already have this address cached? */
|
||||
if (((addr->addr = ipaddr_addr(hostname)) != IPADDR_NONE) ||
|
||||
((addr->addr = dns_lookup(hostname)) != IPADDR_NONE)) {
|
||||
ipaddr = ipaddr_addr(hostname);
|
||||
if (ipaddr == IPADDR_NONE) {
|
||||
ipaddr = dns_lookup(hostname);
|
||||
}
|
||||
if (ipaddr != IPADDR_NONE) {
|
||||
ip4_addr_set_u32(addr, ipaddr);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -190,11 +190,12 @@ autoip_create_addr(struct netif *netif, struct ip_addr *ipaddr)
|
||||
}
|
||||
LWIP_ASSERT("AUTOIP address not in range", (addr >= AUTOIP_RANGE_START) &&
|
||||
(addr <= AUTOIP_RANGE_END));
|
||||
ipaddr->addr = htonl(addr);
|
||||
ip4_addr_set_u32(ipaddr, htonl(addr));
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_create_addr(): tried_llipaddr=%"U16_F", 0x%08"X32_F"\n",
|
||||
(u16_t)(netif->autoip->tried_llipaddr), (u32_t)(ipaddr->addr)));
|
||||
("autoip_create_addr(): tried_llipaddr=%"U16_F", %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
(u16_t)(netif->autoip->tried_llipaddr), ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr),
|
||||
ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -235,8 +236,10 @@ autoip_bind(struct netif *netif)
|
||||
struct ip_addr sn_mask, gw_addr;
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
|
||||
("autoip_bind(netif=%p) %c%c%"U16_F" 0x%08"X32_F"\n",
|
||||
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num, autoip->llipaddr.addr));
|
||||
("autoip_bind(netif=%p) %c%c%"U16_F" %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
(void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num,
|
||||
ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr),
|
||||
ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr)));
|
||||
|
||||
IP4_ADDR(&sn_mask, 255, 255, 0, 0);
|
||||
IP4_ADDR(&gw_addr, 0, 0, 0, 0);
|
||||
@ -269,9 +272,9 @@ autoip_start(struct netif *netif)
|
||||
/* Set IP-Address, Netmask and Gateway to 0 to make sure that
|
||||
* ARP Packets are formed correctly
|
||||
*/
|
||||
netif->ip_addr.addr = 0;
|
||||
netif->netmask.addr = 0;
|
||||
netif->gw.addr = 0;
|
||||
ip_addr_set_zero(&netif->ip_addr);
|
||||
ip_addr_set_zero(&netif->netmask);
|
||||
ip_addr_set_zero(&netif->gw);
|
||||
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("autoip_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0],
|
||||
|
@ -184,9 +184,9 @@ icmp_input(struct pbuf *p, struct netif *inp)
|
||||
/* We generate an answer by switching the dest and src ip addresses,
|
||||
* setting the icmp type to ECHO_RESPONSE and updating the checksum. */
|
||||
iecho = (struct icmp_echo_hdr *)p->payload;
|
||||
tmpaddr.addr = iphdr->src.addr;
|
||||
iphdr->src.addr = iphdr->dest.addr;
|
||||
iphdr->dest.addr = tmpaddr.addr;
|
||||
ip_addr_set(&tmpaddr, &iphdr->src);
|
||||
ip_addr_set(&iphdr->src, &iphdr->dest);
|
||||
ip_addr_set(&iphdr->dest, &tmpaddr);
|
||||
ICMPH_TYPE_SET(iecho, ICMP_ER);
|
||||
/* adjust the checksum */
|
||||
if (iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) {
|
||||
|
@ -385,7 +385,7 @@ igmp_input(struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
||||
switch (igmp->igmp_msgtype) {
|
||||
case IGMP_MEMB_QUERY: {
|
||||
/* IGMP_MEMB_QUERY to the "all systems" address ? */
|
||||
if ((ip_addr_cmp(dest, &allsystems)) && (igmp->igmp_group_address.addr == 0)) {
|
||||
if ((ip_addr_cmp(dest, &allsystems)) && ip_addr_isany(&igmp->igmp_group_address)) {
|
||||
/* THIS IS THE GENERAL QUERY */
|
||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: General IGMP_MEMB_QUERY on \"ALL SYSTEMS\" address (224.0.0.1) [igmp_maxresp=%i]\n", (int)(igmp->igmp_maxresp)));
|
||||
|
||||
@ -406,7 +406,7 @@ igmp_input(struct pbuf *p, struct netif *inp, struct ip_addr *dest)
|
||||
}
|
||||
} else {
|
||||
/* IGMP_MEMB_QUERY to a specific group ? */
|
||||
if (group->group_address.addr != 0) {
|
||||
if (!ip_addr_isany(&group->group_address) != 0) {
|
||||
LWIP_DEBUGF(IGMP_DEBUG, ("igmp_input: IGMP_MEMB_QUERY to a specific group "));
|
||||
ip_addr_debug_print(IGMP_DEBUG, &group->group_address);
|
||||
if (ip_addr_cmp (dest, &allsystems)) {
|
||||
|
@ -285,6 +285,7 @@ inet_chksum_pseudo(struct pbuf *p,
|
||||
u8_t proto, u16_t proto_len)
|
||||
{
|
||||
u32_t acc;
|
||||
u32_t addr;
|
||||
struct pbuf *q;
|
||||
u8_t swapped;
|
||||
|
||||
@ -309,10 +310,12 @@ inet_chksum_pseudo(struct pbuf *p,
|
||||
if (swapped) {
|
||||
acc = SWAP_BYTES_IN_WORD(acc);
|
||||
}
|
||||
acc += (src->addr & 0xffffUL);
|
||||
acc += ((src->addr >> 16) & 0xffffUL);
|
||||
acc += (dest->addr & 0xffffUL);
|
||||
acc += ((dest->addr >> 16) & 0xffffUL);
|
||||
addr = ip4_addr_get_u32(src);
|
||||
acc += (addr & 0xffffUL);
|
||||
acc += ((addr >> 16) & 0xffffUL);
|
||||
addr = ip4_addr_get_u32(dest);
|
||||
acc += (addr & 0xffffUL);
|
||||
acc += ((addr >> 16) & 0xffffUL);
|
||||
acc += (u32_t)htons((u16_t)proto);
|
||||
acc += (u32_t)htons(proto_len);
|
||||
|
||||
@ -344,6 +347,7 @@ inet_chksum_pseudo_partial(struct pbuf *p,
|
||||
u8_t proto, u16_t proto_len, u16_t chksum_len)
|
||||
{
|
||||
u32_t acc;
|
||||
u32_t addr;
|
||||
struct pbuf *q;
|
||||
u8_t swapped;
|
||||
u16_t chklen;
|
||||
@ -374,10 +378,12 @@ inet_chksum_pseudo_partial(struct pbuf *p,
|
||||
if (swapped) {
|
||||
acc = SWAP_BYTES_IN_WORD(acc);
|
||||
}
|
||||
acc += (src->addr & 0xffffUL);
|
||||
acc += ((src->addr >> 16) & 0xffffUL);
|
||||
acc += (dest->addr & 0xffffUL);
|
||||
acc += ((dest->addr >> 16) & 0xffffUL);
|
||||
addr = ip4_addr_get_u32(src);
|
||||
acc += (addr & 0xffffUL);
|
||||
acc += ((addr >> 16) & 0xffffUL);
|
||||
addr = ip4_addr_get_u32(dest);
|
||||
acc += (addr & 0xffffUL);
|
||||
acc += ((addr >> 16) & 0xffffUL);
|
||||
acc += (u32_t)htons((u16_t)proto);
|
||||
acc += (u32_t)htons(proto_len);
|
||||
|
||||
|
@ -93,7 +93,8 @@ ip_route(struct ip_addr *dest)
|
||||
}
|
||||
}
|
||||
if ((netif_default == NULL) || (!netif_is_up(netif_default))) {
|
||||
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to 0x%"X32_F"\n", dest->addr));
|
||||
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
|
||||
IP_STATS_INC(ip.rterr);
|
||||
snmp_inc_ipoutnoroutes();
|
||||
return NULL;
|
||||
@ -117,13 +118,15 @@ static struct netif *
|
||||
ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
||||
{
|
||||
struct netif *netif;
|
||||
struct ip_addr dest;
|
||||
|
||||
PERF_START;
|
||||
dest = iphdr->dest;
|
||||
/* Find network interface where to forward this IP packet to. */
|
||||
netif = ip_route((struct ip_addr *)&(iphdr->dest));
|
||||
netif = ip_route(&dest);
|
||||
if (netif == NULL) {
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%"X32_F" found\n",
|
||||
iphdr->dest.addr));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for %"U16_F".%"U16_F".%"U16_F".%"U16_F" found\n",
|
||||
ip4_addr1_16(&dest), ip4_addr2_16(&dest), ip4_addr3_16(&dest), ip4_addr4_16(&dest)));
|
||||
snmp_inc_ipoutnoroutes();
|
||||
return (struct netif *)NULL;
|
||||
}
|
||||
@ -156,8 +159,8 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
||||
IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100));
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%"X32_F"\n",
|
||||
iphdr->dest.addr));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(&dest), ip4_addr2_16(&dest), ip4_addr3_16(&dest), ip4_addr4_16(&dest)));
|
||||
|
||||
IP_STATS_INC(ip.fw);
|
||||
IP_STATS_INC(ip.xmit);
|
||||
@ -165,7 +168,7 @@ ip_forward(struct pbuf *p, struct ip_hdr *iphdr, struct netif *inp)
|
||||
|
||||
PERF_STOP("ip_forward");
|
||||
/* transmit pbuf on chosen interface */
|
||||
netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
|
||||
netif->output(netif, p, &dest);
|
||||
return netif;
|
||||
}
|
||||
#endif /* IP_FORWARD */
|
||||
@ -274,10 +277,10 @@ ip_input(struct pbuf *p, struct netif *inp)
|
||||
netif = inp;
|
||||
do {
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%"X32_F" netif->ip_addr 0x%"X32_F" (0x%"X32_F", 0x%"X32_F", 0x%"X32_F")\n",
|
||||
iphdr->dest.addr, netif->ip_addr.addr,
|
||||
iphdr->dest.addr & netif->netmask.addr,
|
||||
netif->ip_addr.addr & netif->netmask.addr,
|
||||
iphdr->dest.addr & ~(netif->netmask.addr)));
|
||||
ip4_addr_get_u32(&iphdr->dest), ip4_addr_get_u32(&netif->ip_addr),
|
||||
ip4_addr_get_u32(&iphdr->dest) & ip4_addr_get_u32(&netif->netmask),
|
||||
ip4_addr_get_u32(&netif->ip_addr) & ip4_addr_get_u32(&netif->netmask),
|
||||
ip4_addr_get_u32(&iphdr->dest) & ~ip4_addr_get_u32(&netif->netmask)));
|
||||
|
||||
/* interface is up and configured? */
|
||||
if ((netif_is_up(netif)) && (!ip_addr_isany(&(netif->ip_addr)))) {
|
||||
@ -325,7 +328,7 @@ ip_input(struct pbuf *p, struct netif *inp)
|
||||
/* broadcast or multicast packet source address? Compliant with RFC 1122: 3.2.1.3 */
|
||||
#if LWIP_DHCP
|
||||
/* DHCP servers need 0.0.0.0 to be allowed as source address (RFC 1.1.2.2: 3.2.1.3/a) */
|
||||
if (check_ip_src && (iphdr->src.addr != 0))
|
||||
if (check_ip_src && !ip_addr_isany(&iphdr->src))
|
||||
#endif /* LWIP_DHCP */
|
||||
{ if ((ip_addr_isbroadcast(&(iphdr->src), inp)) ||
|
||||
(ip_addr_ismulticast(&(iphdr->src)))) {
|
||||
@ -386,7 +389,7 @@ ip_input(struct pbuf *p, struct netif *inp)
|
||||
|
||||
#if LWIP_IGMP
|
||||
/* there is an extra "router alert" option in IGMP messages which we allow for but do not police */
|
||||
if((iphdr_hlen > IP_HLEN && (IPH_PROTO(iphdr) != IP_PROTO_IGMP)) {
|
||||
if((iphdr_hlen > IP_HLEN) && (IPH_PROTO(iphdr) != IP_PROTO_IGMP)) {
|
||||
#else
|
||||
if (iphdr_hlen > IP_HLEN) {
|
||||
#endif /* LWIP_IGMP */
|
||||
@ -625,7 +628,8 @@ ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||
struct netif *netif;
|
||||
|
||||
if ((netif = ip_route(dest)) == NULL) {
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%"X32_F"\n", dest->addr));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
|
||||
IP_STATS_INC(ip.rterr);
|
||||
return ERR_RTE;
|
||||
}
|
||||
@ -660,7 +664,8 @@ ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
|
||||
err_t err;
|
||||
|
||||
if ((netif = ip_route(dest)) == NULL) {
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%"X32_F"\n", dest->addr));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("ip_output: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
|
||||
IP_STATS_INC(ip.rterr);
|
||||
return ERR_RTE;
|
||||
}
|
||||
@ -706,16 +711,16 @@ ip_debug_print(struct pbuf *p)
|
||||
ntohs(IPH_CHKSUM(iphdr))));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n",
|
||||
ip4_addr1(&iphdr->src),
|
||||
ip4_addr2(&iphdr->src),
|
||||
ip4_addr3(&iphdr->src),
|
||||
ip4_addr4(&iphdr->src)));
|
||||
ip4_addr1_16(&iphdr->src),
|
||||
ip4_addr2_16(&iphdr->src),
|
||||
ip4_addr3_16(&iphdr->src),
|
||||
ip4_addr4_16(&iphdr->src)));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (dest)\n",
|
||||
ip4_addr1(&iphdr->dest),
|
||||
ip4_addr2(&iphdr->dest),
|
||||
ip4_addr3(&iphdr->dest),
|
||||
ip4_addr4(&iphdr->dest)));
|
||||
ip4_addr1_16(&iphdr->dest),
|
||||
ip4_addr2_16(&iphdr->dest),
|
||||
ip4_addr3_16(&iphdr->dest),
|
||||
ip4_addr4_16(&iphdr->dest)));
|
||||
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n"));
|
||||
}
|
||||
#endif /* IP_DEBUG */
|
||||
|
@ -40,12 +40,9 @@
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
#define IP_ADDR_ANY_VALUE 0x00000000UL
|
||||
#define IP_ADDR_BROADCAST_VALUE 0xffffffffUL
|
||||
|
||||
/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in ip_addr.h */
|
||||
const struct ip_addr ip_addr_any = { IP_ADDR_ANY_VALUE };
|
||||
const struct ip_addr ip_addr_broadcast = { IP_ADDR_BROADCAST_VALUE };
|
||||
/* used by IP_ADDR_ANY and IP_ADDR_BROADCAST in struct ip_addr.h */
|
||||
const struct ip_addr ip_addr_any = { IPADDR_ANY };
|
||||
const struct ip_addr ip_addr_broadcast = { IPADDR_BROADCAST };
|
||||
|
||||
/**
|
||||
* Determine if an address is a broadcast address on a network interface
|
||||
@ -58,10 +55,10 @@ u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
|
||||
{
|
||||
u32_t addr2test;
|
||||
|
||||
addr2test = addr->addr;
|
||||
addr2test = ip4_addr_get_u32(addr);
|
||||
/* all ones (broadcast) or all zeroes (old skool broadcast) */
|
||||
if ((~addr2test == IP_ADDR_ANY_VALUE) ||
|
||||
(addr2test == IP_ADDR_ANY_VALUE))
|
||||
if ((~addr2test == IPADDR_ANY) ||
|
||||
(addr2test == IPADDR_ANY))
|
||||
return 1;
|
||||
/* no broadcast support on this network interface? */
|
||||
else if ((netif->flags & NETIF_FLAG_BROADCAST) == 0)
|
||||
@ -69,13 +66,13 @@ u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
|
||||
* nor can we check against any broadcast addresses */
|
||||
return 0;
|
||||
/* address matches network interface address exactly? => no broadcast */
|
||||
else if (addr2test == netif->ip_addr.addr)
|
||||
else if (addr2test == ip4_addr_get_u32(&netif->ip_addr))
|
||||
return 0;
|
||||
/* on the same (sub) network... */
|
||||
else if (ip_addr_netcmp(addr, &(netif->ip_addr), &(netif->netmask))
|
||||
/* ...and host identifier bits are all ones? =>... */
|
||||
&& ((addr2test & ~netif->netmask.addr) ==
|
||||
(IP_ADDR_BROADCAST_VALUE & ~netif->netmask.addr)))
|
||||
&& ((addr2test & ~ip4_addr_get_u32(&netif->netmask)) ==
|
||||
(IPADDR_BROADCAST & ~ip4_addr_get_u32(&netif->netmask))))
|
||||
/* => network broadcast address */
|
||||
return 1;
|
||||
else
|
||||
@ -105,7 +102,7 @@ ipaddr_addr(const char *cp)
|
||||
struct ip_addr val;
|
||||
|
||||
if (ipaddr_aton(cp, &val)) {
|
||||
return (val.addr);
|
||||
return ip4_addr_get_u32(&val);
|
||||
}
|
||||
return (IPADDR_NONE);
|
||||
}
|
||||
@ -208,8 +205,9 @@ ipaddr_aton(const char *cp, struct ip_addr *addr)
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if (addr)
|
||||
addr->addr = htonl(val);
|
||||
if (addr) {
|
||||
ip4_addr_set_u32(addr, htonl(val));
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -225,7 +223,7 @@ char *
|
||||
ipaddr_ntoa(struct ip_addr *addr)
|
||||
{
|
||||
static char str[16];
|
||||
u32_t s_addr = addr->addr;
|
||||
u32_t s_addr;
|
||||
char inv[3];
|
||||
char *rp;
|
||||
u8_t *ap;
|
||||
@ -233,6 +231,8 @@ ipaddr_ntoa(struct ip_addr *addr)
|
||||
u8_t n;
|
||||
u8_t i;
|
||||
|
||||
s_addr = ip4_addr_get_u32(addr);
|
||||
|
||||
rp = str;
|
||||
ap = (u8_t *)&s_addr;
|
||||
for(n = 0; n < 4; n++) {
|
||||
|
@ -97,9 +97,9 @@ netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask,
|
||||
LWIP_ASSERT("No init function given", init != NULL);
|
||||
|
||||
/* reset new interface configuration state */
|
||||
netif->ip_addr.addr = 0;
|
||||
netif->netmask.addr = 0;
|
||||
netif->gw.addr = 0;
|
||||
ip_addr_set_zero(&netif->ip_addr);
|
||||
ip_addr_set_zero(&netif->netmask);
|
||||
ip_addr_set_zero(&netif->gw);
|
||||
netif->flags = 0;
|
||||
#if LWIP_DHCP
|
||||
/* netif not under DHCP control by default */
|
||||
@ -316,10 +316,10 @@ netif_set_ipaddr(struct netif *netif, struct ip_addr *ipaddr)
|
||||
|
||||
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IP address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
netif->name[0], netif->name[1],
|
||||
ip4_addr1(&netif->ip_addr),
|
||||
ip4_addr2(&netif->ip_addr),
|
||||
ip4_addr3(&netif->ip_addr),
|
||||
ip4_addr4(&netif->ip_addr)));
|
||||
ip4_addr1_16(&netif->ip_addr),
|
||||
ip4_addr2_16(&netif->ip_addr),
|
||||
ip4_addr3_16(&netif->ip_addr),
|
||||
ip4_addr4_16(&netif->ip_addr)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -336,10 +336,10 @@ netif_set_gw(struct netif *netif, struct ip_addr *gw)
|
||||
ip_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(&netif->gw),
|
||||
ip4_addr2(&netif->gw),
|
||||
ip4_addr3(&netif->gw),
|
||||
ip4_addr4(&netif->gw)));
|
||||
ip4_addr1_16(&netif->gw),
|
||||
ip4_addr2_16(&netif->gw),
|
||||
ip4_addr3_16(&netif->gw),
|
||||
ip4_addr4_16(&netif->gw)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -360,10 +360,10 @@ netif_set_netmask(struct netif *netif, struct ip_addr *netmask)
|
||||
snmp_insert_iprteidx_tree(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],
|
||||
ip4_addr1(&netif->netmask),
|
||||
ip4_addr2(&netif->netmask),
|
||||
ip4_addr3(&netif->netmask),
|
||||
ip4_addr4(&netif->netmask)));
|
||||
ip4_addr1_16(&netif->netmask),
|
||||
ip4_addr2_16(&netif->netmask),
|
||||
ip4_addr3_16(&netif->netmask),
|
||||
ip4_addr4_16(&netif->netmask)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -232,7 +232,8 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr)
|
||||
}
|
||||
|
||||
if ((netif = ip_route(ipaddr)) == NULL) {
|
||||
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to 0x%"X32_F"\n", ipaddr->addr));
|
||||
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
|
||||
/* free any temporary header pbuf allocated by pbuf_header() */
|
||||
if (q != p) {
|
||||
pbuf_free(q);
|
||||
@ -242,7 +243,7 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *ipaddr)
|
||||
|
||||
#if IP_SOF_BROADCAST
|
||||
/* broadcast filter? */
|
||||
if ( ((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(ipaddr, netif) ) {
|
||||
if (((pcb->so_options & SOF_BROADCAST) == 0) && ip_addr_isbroadcast(ipaddr, netif)) {
|
||||
LWIP_DEBUGF(RAW_DEBUG | LWIP_DBG_LEVEL_WARNING, ("raw_sendto: SOF_BROADCAST not enabled on pcb %p\n", (void *)pcb));
|
||||
/* free any temporary header pbuf allocated by pbuf_header() */
|
||||
if (q != p) {
|
||||
|
@ -1088,14 +1088,12 @@ void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip)
|
||||
{
|
||||
struct mib_list_rootnode *at_rn;
|
||||
struct mib_list_node *at_node;
|
||||
struct ip_addr hip;
|
||||
s32_t arpidx[5];
|
||||
u8_t level, tree;
|
||||
|
||||
LWIP_ASSERT("ni != NULL", ni != NULL);
|
||||
snmp_netiftoifindex(ni, &arpidx[0]);
|
||||
hip.addr = ntohl(ip->addr);
|
||||
snmp_iptooid(&hip, &arpidx[1]);
|
||||
snmp_iptooid(ip, &arpidx[1]);
|
||||
|
||||
for (tree = 0; tree < 2; tree++)
|
||||
{
|
||||
@ -1162,13 +1160,11 @@ void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip)
|
||||
{
|
||||
struct mib_list_rootnode *at_rn, *next, *del_rn[5];
|
||||
struct mib_list_node *at_n, *del_n[5];
|
||||
struct ip_addr hip;
|
||||
s32_t arpidx[5];
|
||||
u8_t fc, tree, level, del_cnt;
|
||||
|
||||
snmp_netiftoifindex(ni, &arpidx[0]);
|
||||
hip.addr = ntohl(ip->addr);
|
||||
snmp_iptooid(&hip, &arpidx[1]);
|
||||
snmp_iptooid(ip, &arpidx[1]);
|
||||
|
||||
for (tree = 0; tree < 2; tree++)
|
||||
{
|
||||
@ -1321,13 +1317,11 @@ void snmp_insert_ipaddridx_tree(struct netif *ni)
|
||||
{
|
||||
struct mib_list_rootnode *ipa_rn;
|
||||
struct mib_list_node *ipa_node;
|
||||
struct ip_addr ip;
|
||||
s32_t ipaddridx[4];
|
||||
u8_t level;
|
||||
|
||||
LWIP_ASSERT("ni != NULL", ni != NULL);
|
||||
ip.addr = ntohl(ni->ip_addr.addr);
|
||||
snmp_iptooid(&ip, &ipaddridx[0]);
|
||||
snmp_iptooid(&ni->ip_addr, &ipaddridx[0]);
|
||||
|
||||
level = 0;
|
||||
ipa_rn = &ipaddrtree_root;
|
||||
@ -1377,13 +1371,11 @@ void snmp_delete_ipaddridx_tree(struct netif *ni)
|
||||
{
|
||||
struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];
|
||||
struct mib_list_node *ipa_n, *del_n[4];
|
||||
struct ip_addr ip;
|
||||
s32_t ipaddridx[4];
|
||||
u8_t fc, level, del_cnt;
|
||||
|
||||
LWIP_ASSERT("ni != NULL", ni != NULL);
|
||||
ip.addr = ntohl(ni->ip_addr.addr);
|
||||
snmp_iptooid(&ip, &ipaddridx[0]);
|
||||
snmp_iptooid(&ni->ip_addr, &ipaddridx[0]);
|
||||
|
||||
/* mark nodes for deletion */
|
||||
level = 0;
|
||||
@ -1450,15 +1442,17 @@ void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
|
||||
if (dflt != 0)
|
||||
{
|
||||
/* the default route 0.0.0.0 */
|
||||
dst.addr = 0;
|
||||
ip_addr_set(&dst, &ip_addr_any);
|
||||
insert = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* route to the network address */
|
||||
dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
|
||||
ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
|
||||
/* exclude 0.0.0.0 network (reserved for default rte) */
|
||||
if (dst.addr != 0) insert = 1;
|
||||
if (!ip_addr_isany(&dst)) {
|
||||
insert = 1;
|
||||
}
|
||||
}
|
||||
if (insert)
|
||||
{
|
||||
@ -1525,15 +1519,17 @@ void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
|
||||
if (dflt != 0)
|
||||
{
|
||||
/* the default route 0.0.0.0 */
|
||||
dst.addr = 0;
|
||||
ip_addr_set(&dst, &ip_addr_any);
|
||||
del = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* route to the network address */
|
||||
dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
|
||||
ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
|
||||
/* exclude 0.0.0.0 network (reserved for default rte) */
|
||||
if (dst.addr != 0) del = 1;
|
||||
if (!ip_addr_isany(&dst)) {
|
||||
del = 1;
|
||||
}
|
||||
}
|
||||
if (del)
|
||||
{
|
||||
@ -1795,13 +1791,11 @@ void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
|
||||
{
|
||||
struct mib_list_rootnode *udp_rn;
|
||||
struct mib_list_node *udp_node;
|
||||
struct ip_addr ip;
|
||||
s32_t udpidx[5];
|
||||
u8_t level;
|
||||
|
||||
LWIP_ASSERT("pcb != NULL", pcb != NULL);
|
||||
ip.addr = ntohl(pcb->local_ip.addr);
|
||||
snmp_iptooid(&ip, &udpidx[0]);
|
||||
snmp_iptooid(&pcb->local_ip, &udpidx[0]);
|
||||
udpidx[4] = pcb->local_port;
|
||||
|
||||
udp_rn = &udp_root;
|
||||
@ -1847,29 +1841,28 @@ void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
|
||||
*/
|
||||
void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
|
||||
{
|
||||
struct udp_pcb *npcb;
|
||||
struct mib_list_rootnode *udp_rn, *next, *del_rn[5];
|
||||
struct mib_list_node *udp_n, *del_n[5];
|
||||
struct ip_addr ip;
|
||||
s32_t udpidx[5];
|
||||
u8_t bindings, fc, level, del_cnt;
|
||||
|
||||
LWIP_ASSERT("pcb != NULL", pcb != NULL);
|
||||
ip.addr = ntohl(pcb->local_ip.addr);
|
||||
snmp_iptooid(&ip, &udpidx[0]);
|
||||
snmp_iptooid(&pcb->local_ip, &udpidx[0]);
|
||||
udpidx[4] = pcb->local_port;
|
||||
|
||||
/* count PCBs for a given binding
|
||||
(e.g. when reusing ports or for temp output PCBs) */
|
||||
bindings = 0;
|
||||
pcb = udp_pcbs;
|
||||
while ((pcb != NULL))
|
||||
npcb = udp_pcbs;
|
||||
while ((npcb != NULL))
|
||||
{
|
||||
if ((pcb->local_ip.addr == ip.addr) &&
|
||||
(pcb->local_port == udpidx[4]))
|
||||
if (ip_addr_cmp(&npcb->local_ip, &pcb->local_ip) &&
|
||||
(npcb->local_port == udpidx[4]))
|
||||
{
|
||||
bindings++;
|
||||
}
|
||||
pcb = pcb->next;
|
||||
npcb = npcb->next;
|
||||
}
|
||||
if (bindings == 1)
|
||||
{
|
||||
@ -2622,7 +2615,7 @@ ifentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
#if !SNMP_SAFE_REQUESTS
|
||||
static u8_t
|
||||
ifentry_set_test (struct obj_def *od, u16_t len, void *value)
|
||||
ifentry_set_test(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
struct netif *netif;
|
||||
u8_t id, set_ok;
|
||||
@ -2630,7 +2623,7 @@ ifentry_set_test (struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
set_ok = 0;
|
||||
snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
|
||||
id = od->id_inst_ptr[0];
|
||||
id = (u8_t)od->id_inst_ptr[0];
|
||||
switch (id)
|
||||
{
|
||||
case 7: /* ifAdminStatus */
|
||||
@ -2645,14 +2638,14 @@ ifentry_set_test (struct obj_def *od, u16_t len, void *value)
|
||||
}
|
||||
|
||||
static void
|
||||
ifentry_set_value (struct obj_def *od, u16_t len, void *value)
|
||||
ifentry_set_value(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
struct netif *netif;
|
||||
u8_t id;
|
||||
LWIP_UNUSED_ARG(len);
|
||||
|
||||
snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
|
||||
id = od->id_inst_ptr[0];
|
||||
id = (u8_t)od->id_inst_ptr[0];
|
||||
switch (id)
|
||||
{
|
||||
case 7: /* ifAdminStatus */
|
||||
@ -2740,7 +2733,6 @@ atentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
|
||||
snmp_oidtoip(&od->id_inst_ptr[2], &ip);
|
||||
ip.addr = htonl(ip.addr);
|
||||
|
||||
#if LWIP_ARP /** @todo implement a netif_find_addr */
|
||||
if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
|
||||
@ -3084,7 +3076,6 @@ ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
LWIP_UNUSED_ARG(len);
|
||||
snmp_oidtoip(&od->id_inst_ptr[1], &ip);
|
||||
ip.addr = htonl(ip.addr);
|
||||
ifidx = 0;
|
||||
while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
|
||||
{
|
||||
@ -3122,7 +3113,7 @@ ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
/* lwIP oddity, there's no broadcast
|
||||
address in the netif we can rely on */
|
||||
*sint_ptr = ip_addr_broadcast.addr & 1;
|
||||
*sint_ptr = IPADDR_BROADCAST & 1;
|
||||
}
|
||||
break;
|
||||
case 5: /* ipAdEntReasmMaxSize */
|
||||
@ -3226,9 +3217,8 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
ident = od->id_inst_ptr;
|
||||
snmp_oidtoip(&ident[1], &dest);
|
||||
dest.addr = htonl(dest.addr);
|
||||
|
||||
if (dest.addr == 0)
|
||||
if (ip_addr_isany(&dest))
|
||||
{
|
||||
/* ip_route() uses default netif for default route */
|
||||
netif = netif_default;
|
||||
@ -3253,15 +3243,15 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
struct ip_addr *dst = (struct ip_addr*)value;
|
||||
|
||||
if (dest.addr == 0)
|
||||
if (ip_addr_isany(&dest))
|
||||
{
|
||||
/* default rte has 0.0.0.0 dest */
|
||||
dst->addr = 0;
|
||||
ip_addr_set_zero(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* netifs have netaddress dest */
|
||||
dst->addr = netif->ip_addr.addr & netif->netmask.addr;
|
||||
ip_addr_get_network(dst, &netif->ip_addr, &netif->netmask);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -3276,7 +3266,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
s32_t *sint_ptr = (s32_t*)value;
|
||||
|
||||
if (dest.addr == 0)
|
||||
if (ip_addr_isany(&dest))
|
||||
{
|
||||
/* default rte has metric 1 */
|
||||
*sint_ptr = 1;
|
||||
@ -3302,7 +3292,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
struct ip_addr *dst = (struct ip_addr*)value;
|
||||
|
||||
if (dest.addr == 0)
|
||||
if (ip_addr_isany(&dest))
|
||||
{
|
||||
/* default rte: gateway */
|
||||
*dst = netif->gw;
|
||||
@ -3318,7 +3308,7 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
s32_t *sint_ptr = (s32_t*)value;
|
||||
|
||||
if (dest.addr == 0)
|
||||
if (ip_addr_isany(&dest))
|
||||
{
|
||||
/* default rte is indirect */
|
||||
*sint_ptr = 4;
|
||||
@ -3349,10 +3339,10 @@ ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
{
|
||||
struct ip_addr *dst = (struct ip_addr*)value;
|
||||
|
||||
if (dest.addr == 0)
|
||||
if (ip_addr_isany(&dest))
|
||||
{
|
||||
/* default rte use 0.0.0.0 mask */
|
||||
dst->addr = 0;
|
||||
ip_addr_set_zero(dst);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3434,7 +3424,6 @@ ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
|
||||
snmp_oidtoip(&od->id_inst_ptr[2], &ip);
|
||||
ip.addr = htonl(ip.addr);
|
||||
|
||||
#if LWIP_ARP /** @todo implement a netif_find_addr */
|
||||
if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
|
||||
@ -3789,10 +3778,8 @@ tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
ident = od->id_inst_ptr;
|
||||
snmp_oidtoip(&ident[1], &lip);
|
||||
lip.addr = htonl(lip.addr);
|
||||
lport = ident[5];
|
||||
snmp_oidtoip(&ident[6], &rip);
|
||||
rip.addr = htonl(rip.addr);
|
||||
rport = ident[10];
|
||||
|
||||
/** @todo find matching PCB */
|
||||
@ -3899,13 +3886,12 @@ udpentry_get_value(struct obj_def *od, u16_t len, void *value)
|
||||
|
||||
LWIP_UNUSED_ARG(len);
|
||||
snmp_oidtoip(&od->id_inst_ptr[1], &ip);
|
||||
ip.addr = htonl(ip.addr);
|
||||
LWIP_ASSERT("invalid port", (od->id_inst_ptr[5] >= 0) && (od->id_inst_ptr[5] <= 0xffff));
|
||||
port = (u16_t)od->id_inst_ptr[5];
|
||||
|
||||
pcb = udp_pcbs;
|
||||
while ((pcb != NULL) &&
|
||||
!((pcb->local_ip.addr == ip.addr) &&
|
||||
!(ip_addr_cmp(&pcb->local_ip, &ip) &&
|
||||
(pcb->local_port == port)))
|
||||
{
|
||||
pcb = pcb->next;
|
||||
|
@ -135,16 +135,7 @@ snmp_netiftoifindex(struct netif *netif, s32_t *ifidx)
|
||||
void
|
||||
snmp_oidtoip(s32_t *ident, struct ip_addr *ip)
|
||||
{
|
||||
u32_t ipa;
|
||||
|
||||
ipa = ident[0];
|
||||
ipa <<= 8;
|
||||
ipa |= ident[1];
|
||||
ipa <<= 8;
|
||||
ipa |= ident[2];
|
||||
ipa <<= 8;
|
||||
ipa |= ident[3];
|
||||
ip->addr = ipa;
|
||||
IP4_ADDR(ip, ident[0], ident[1], ident[2], ident[3]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -155,13 +146,10 @@ snmp_oidtoip(s32_t *ident, struct ip_addr *ip)
|
||||
void
|
||||
snmp_iptooid(struct ip_addr *ip, s32_t *ident)
|
||||
{
|
||||
u32_t ipa;
|
||||
|
||||
ipa = ip->addr;
|
||||
ident[0] = (ipa >> 24) & 0xff;
|
||||
ident[1] = (ipa >> 16) & 0xff;
|
||||
ident[2] = (ipa >> 8) & 0xff;
|
||||
ident[3] = ipa & 0xff;
|
||||
ident[0] = ip4_addr1(ip);
|
||||
ident[1] = ip4_addr2(ip);
|
||||
ident[2] = ip4_addr3(ip);
|
||||
ident[3] = ip4_addr4(ip);
|
||||
}
|
||||
|
||||
struct mib_list_node *
|
||||
|
@ -96,7 +96,7 @@ snmp_trap_dst_ip_set(u8_t dst_idx, struct ip_addr *dst)
|
||||
{
|
||||
if (dst_idx < SNMP_TRAP_DESTINATIONS)
|
||||
{
|
||||
trap_dst[dst_idx].dip.addr = htonl(dst->addr);
|
||||
ip_addr_set_hton(&trap_dst[dst_idx].dip, dst);
|
||||
}
|
||||
}
|
||||
|
||||
@ -227,17 +227,18 @@ snmp_send_trap(s8_t generic_trap, struct snmp_obj_id *eoid, s32_t specific_trap)
|
||||
|
||||
for (i=0, td = &trap_dst[0]; i<SNMP_TRAP_DESTINATIONS; i++, td++)
|
||||
{
|
||||
if ((td->enable != 0) && (td->dip.addr != 0))
|
||||
if ((td->enable != 0) && !ip_addr_isany(&td->dip))
|
||||
{
|
||||
/* network order trap destination */
|
||||
trap_msg.dip.addr = td->dip.addr;
|
||||
ip_addr_set(&trap_msg.dip, &td->dip);
|
||||
/* lookup current source address for this dst */
|
||||
dst_if = ip_route(&td->dip);
|
||||
dst_ip.addr = ntohl(dst_if->ip_addr.addr);
|
||||
trap_msg.sip_raw[0] = (u8_t)(dst_ip.addr >> 24);
|
||||
trap_msg.sip_raw[1] = (u8_t)(dst_ip.addr >> 16);
|
||||
trap_msg.sip_raw[2] = (u8_t)(dst_ip.addr >> 8);
|
||||
trap_msg.sip_raw[3] = (u8_t)dst_ip.addr;
|
||||
ip_addr_set(&dst_ip, &dst_if->ip_addr);
|
||||
/* @todo: what about IPv6? */
|
||||
trap_msg.sip_raw[0] = ip4_addr1(&dst_ip);
|
||||
trap_msg.sip_raw[1] = ip4_addr2(&dst_ip);
|
||||
trap_msg.sip_raw[2] = ip4_addr3(&dst_ip);
|
||||
trap_msg.sip_raw[3] = ip4_addr4(&dst_ip);
|
||||
trap_msg.gen_trap = generic_trap;
|
||||
trap_msg.spc_trap = specific_trap;
|
||||
if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC)
|
||||
|
@ -687,8 +687,8 @@ tcp_slowtmr(void)
|
||||
#endif /* LWIP_TCP_KEEPALIVE */
|
||||
{
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to %"U16_F".%"U16_F".%"U16_F".%"U16_F".\n",
|
||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
|
||||
ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
|
||||
ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip)));
|
||||
|
||||
++pcb_remove;
|
||||
++pcb_reset;
|
||||
|
@ -934,8 +934,8 @@ tcp_keepalive(struct tcp_pcb *pcb)
|
||||
struct tcp_hdr *tcphdr;
|
||||
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: sending KEEPALIVE probe to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
|
||||
ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
|
||||
ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip)));
|
||||
|
||||
LWIP_DEBUGF(TCP_DEBUG, ("tcp_keepalive: tcp_ticks %"U32_F" pcb->tmr %"U32_F" pcb->keep_cnt_sent %"U16_F"\n",
|
||||
tcp_ticks, pcb->tmr, pcb->keep_cnt_sent));
|
||||
@ -993,8 +993,8 @@ tcp_zero_window_probe(struct tcp_pcb *pcb)
|
||||
LWIP_DEBUGF(TCP_DEBUG,
|
||||
("tcp_zero_window_probe: sending ZERO WINDOW probe to %"
|
||||
U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip)));
|
||||
ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
|
||||
ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip)));
|
||||
|
||||
LWIP_DEBUGF(TCP_DEBUG,
|
||||
("tcp_zero_window_probe: tcp_ticks %"U32_F
|
||||
|
@ -127,10 +127,10 @@ udp_input(struct pbuf *p, struct netif *inp)
|
||||
LWIP_DEBUGF(UDP_DEBUG,
|
||||
("udp (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") <-- "
|
||||
"(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
|
||||
ip4_addr1(&iphdr->dest), ip4_addr2(&iphdr->dest),
|
||||
ip4_addr3(&iphdr->dest), ip4_addr4(&iphdr->dest), ntohs(udphdr->dest),
|
||||
ip4_addr1(&iphdr->src), ip4_addr2(&iphdr->src),
|
||||
ip4_addr3(&iphdr->src), ip4_addr4(&iphdr->src), ntohs(udphdr->src)));
|
||||
ip4_addr1_16(&iphdr->dest), ip4_addr2_16(&iphdr->dest),
|
||||
ip4_addr3_16(&iphdr->dest), ip4_addr4_16(&iphdr->dest), ntohs(udphdr->dest),
|
||||
ip4_addr1_16(&iphdr->src), ip4_addr2_16(&iphdr->src),
|
||||
ip4_addr3_16(&iphdr->src), ip4_addr4_16(&iphdr->src), ntohs(udphdr->src)));
|
||||
|
||||
#if LWIP_DHCP
|
||||
pcb = NULL;
|
||||
@ -165,10 +165,10 @@ udp_input(struct pbuf *p, struct netif *inp)
|
||||
LWIP_DEBUGF(UDP_DEBUG,
|
||||
("pcb (%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F") --- "
|
||||
"(%"U16_F".%"U16_F".%"U16_F".%"U16_F", %"U16_F")\n",
|
||||
ip4_addr1(&pcb->local_ip), ip4_addr2(&pcb->local_ip),
|
||||
ip4_addr3(&pcb->local_ip), ip4_addr4(&pcb->local_ip), pcb->local_port,
|
||||
ip4_addr1(&pcb->remote_ip), ip4_addr2(&pcb->remote_ip),
|
||||
ip4_addr3(&pcb->remote_ip), ip4_addr4(&pcb->remote_ip), pcb->remote_port));
|
||||
ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
|
||||
ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip), pcb->local_port,
|
||||
ip4_addr1_16(&pcb->remote_ip), ip4_addr2_16(&pcb->remote_ip),
|
||||
ip4_addr3_16(&pcb->remote_ip), ip4_addr4_16(&pcb->remote_ip), pcb->remote_port));
|
||||
|
||||
/* compare PCB local addr+port to UDP destination addr+port */
|
||||
if ((pcb->local_port == dest) &&
|
||||
@ -372,7 +372,8 @@ udp_sendto(struct udp_pcb *pcb, struct pbuf *p,
|
||||
|
||||
/* no outgoing network interface could be found? */
|
||||
if (netif == NULL) {
|
||||
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to 0x%"X32_F"\n", dst_ip->addr));
|
||||
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("udp_send: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
|
||||
ip4_addr1_16(dst_ip), ip4_addr2_16(dst_ip), ip4_addr3_16(dst_ip), ip4_addr4_16(dst_ip)));
|
||||
UDP_STATS_INC(udp.rterr);
|
||||
return ERR_RTE;
|
||||
}
|
||||
@ -656,10 +657,9 @@ udp_bind(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
||||
}
|
||||
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("udp_bind: bound to %"U16_F".%"U16_F".%"U16_F".%"U16_F", port %"U16_F"\n",
|
||||
(u16_t)((ntohl(pcb->local_ip.addr) >> 24) & 0xff),
|
||||
(u16_t)((ntohl(pcb->local_ip.addr) >> 16) & 0xff),
|
||||
(u16_t)((ntohl(pcb->local_ip.addr) >> 8) & 0xff),
|
||||
(u16_t)(ntohl(pcb->local_ip.addr) & 0xff), pcb->local_port));
|
||||
ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
|
||||
ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
|
||||
pcb->local_port));
|
||||
return ERR_OK;
|
||||
}
|
||||
/**
|
||||
@ -715,10 +715,9 @@ udp_connect(struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
|
||||
#endif
|
||||
LWIP_DEBUGF(UDP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
|
||||
("udp_connect: connected to %"U16_F".%"U16_F".%"U16_F".%"U16_F",port %"U16_F"\n",
|
||||
(u16_t)((ntohl(pcb->remote_ip.addr) >> 24) & 0xff),
|
||||
(u16_t)((ntohl(pcb->remote_ip.addr) >> 16) & 0xff),
|
||||
(u16_t)((ntohl(pcb->remote_ip.addr) >> 8) & 0xff),
|
||||
(u16_t)(ntohl(pcb->remote_ip.addr) & 0xff), pcb->remote_port));
|
||||
ip4_addr1_16(&pcb->local_ip), ip4_addr2_16(&pcb->local_ip),
|
||||
ip4_addr3_16(&pcb->local_ip), ip4_addr4_16(&pcb->local_ip),
|
||||
pcb->local_port));
|
||||
|
||||
/* Insert UDP PCB into the list of active UDP PCBs. */
|
||||
for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
|
||||
|
@ -89,6 +89,9 @@ struct in_addr {
|
||||
|
||||
#define IN_LOOPBACKNET IP_LOOPBACKNET
|
||||
|
||||
#define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
|
||||
#define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
|
||||
|
||||
/* directly map this to the lwip internal functions */
|
||||
#define inet_addr(cp) ipaddr_addr(cp)
|
||||
#define inet_aton(cp, addr) ipaddr_aton(cp, (struct ip_addr*)addr)
|
||||
|
@ -44,7 +44,7 @@ extern "C" {
|
||||
#endif
|
||||
PACK_STRUCT_BEGIN
|
||||
struct ip_addr {
|
||||
PACK_STRUCT_FIELD(u32_t addr);
|
||||
PACK_STRUCT_FIELD(u32_t addre);
|
||||
} PACK_STRUCT_STRUCT;
|
||||
PACK_STRUCT_END
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
@ -67,6 +67,7 @@ PACK_STRUCT_END
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
/* Forward declaration to not include netif.h */
|
||||
struct netif;
|
||||
|
||||
extern const struct ip_addr ip_addr_any;
|
||||
@ -121,14 +122,32 @@ extern const struct ip_addr ip_addr_broadcast;
|
||||
|
||||
|
||||
#define IP4_ADDR(ipaddr, a,b,c,d) \
|
||||
(ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
|
||||
(ipaddr)->addre = htonl(((u32_t)((a) & 0xff) << 24) | \
|
||||
((u32_t)((b) & 0xff) << 16) | \
|
||||
((u32_t)((c) & 0xff) << 8) | \
|
||||
(u32_t)((d) & 0xff))
|
||||
|
||||
#define ip_addr_set(dest, src) (dest)->addr = \
|
||||
((src) == NULL? 0:\
|
||||
(src)->addr)
|
||||
/** Safely copy one IP address to another (src may be NULL) */
|
||||
#define ip_addr_set(dest, src) ((dest)->addre = \
|
||||
((src) == NULL ? 0:\
|
||||
(src)->addre))
|
||||
/** Set complete address to zero */
|
||||
#define ip_addr_set_zero(ipaddr) (ipaddr)->addre = IPADDR_ANY
|
||||
/** Set address to loopback address */
|
||||
#define ip_addr_set_loopback(ipaddr) ((ipaddr)->addre = IPADDR_LOOPBACK)
|
||||
/** Safely copy one IP address to another and change byte order
|
||||
* from host- to network-order. */
|
||||
#define ip_addr_set_hton(dest, src) ((dest)->addre = \
|
||||
((src) == NULL ? 0:\
|
||||
htonl((src)->addre)))
|
||||
/** IPv4 only: set the IP address given as an u32_t */
|
||||
#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addre = (src_u32))
|
||||
/** IPv4 only: get the IP address as an u32_t */
|
||||
#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addre)
|
||||
|
||||
/** Get the network address by combining host address with netmask */
|
||||
#define ip_addr_get_network(target, host, netmask) ((target)->addre = ((host)->addre) & ((netmask)->addre))
|
||||
|
||||
/**
|
||||
* Determine if two address are on the same network.
|
||||
*
|
||||
@ -137,45 +156,50 @@ extern const struct ip_addr ip_addr_broadcast;
|
||||
* @arg mask network identifier mask
|
||||
* @return !0 if the network identifiers of both address match
|
||||
*/
|
||||
#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
|
||||
(mask)->addr) == \
|
||||
((addr2)->addr & \
|
||||
(mask)->addr))
|
||||
#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
|
||||
#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addre & \
|
||||
(mask)->addre) == \
|
||||
((addr2)->addre & \
|
||||
(mask)->addre))
|
||||
#define ip_addr_cmp(addr1, addr2) ((addr1)->addre == (addr2)->addre)
|
||||
|
||||
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
|
||||
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addre == 0)
|
||||
|
||||
u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *);
|
||||
|
||||
#define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))
|
||||
#define ip_addr_ismulticast(addr1) (((addr1)->addre & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL))
|
||||
|
||||
#define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
|
||||
#define ip_addr_islinklocal(addr1) (((addr1)->addre & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
|
||||
|
||||
#define ip_addr_debug_print(debug, ipaddr) \
|
||||
LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
|
||||
ipaddr != NULL ? \
|
||||
(u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \
|
||||
(u16_t)(ntohl((ipaddr)->addre) >> 24) & 0xff : 0, \
|
||||
ipaddr != NULL ? \
|
||||
(u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \
|
||||
(u16_t)(ntohl((ipaddr)->addre) >> 16) & 0xff : 0, \
|
||||
ipaddr != NULL ? \
|
||||
(u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \
|
||||
(u16_t)(ntohl((ipaddr)->addre) >> 8) & 0xff : 0, \
|
||||
ipaddr != NULL ? \
|
||||
(u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
|
||||
(u16_t)ntohl((ipaddr)->addre) & 0xff : 0))
|
||||
|
||||
/* Get one byte from the 4-byte address */
|
||||
#define ip4_addr1(ipaddr) ((u8_t)(ntohl((ipaddr)->addre) >> 24) & 0xff)
|
||||
#define ip4_addr2(ipaddr) ((u8_t)(ntohl((ipaddr)->addre) >> 16) & 0xff)
|
||||
#define ip4_addr3(ipaddr) ((u8_t)(ntohl((ipaddr)->addre) >> 8) & 0xff)
|
||||
#define ip4_addr4(ipaddr) ((u8_t)(ntohl((ipaddr)->addre)) & 0xff)
|
||||
/* These are cast to u16_t, with the intent that they are often arguments
|
||||
* to printf using the U16_F format from cc.h. */
|
||||
#define ip4_addr1(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
|
||||
#define ip4_addr2(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
|
||||
#define ip4_addr3(ipaddr) ((u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
|
||||
#define ip4_addr4(ipaddr) ((u16_t)(ntohl((ipaddr)->addr)) & 0xff)
|
||||
#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
|
||||
#define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
|
||||
#define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
|
||||
#define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
|
||||
|
||||
/** For backwards compatibility */
|
||||
#define ip_ntoa(addr) ipaddr_ntoa(addr)
|
||||
#define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
|
||||
|
||||
u32_t ipaddr_addr(const char *cp);
|
||||
int ipaddr_aton(const char *cp, struct ip_addr *addr);
|
||||
int ipaddr_aton(const char *cp, struct ip_addr *addre);
|
||||
/** returns ptr to static buffer; not reentrant! */
|
||||
char *ipaddr_ntoa(struct ip_addr *addr);
|
||||
char *ipaddr_ntoa(struct ip_addr *addre);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
/* some rarely used options */
|
||||
|
@ -39,9 +39,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
struct udp_pcb;
|
||||
struct netif;
|
||||
struct ip_addr;
|
||||
|
||||
/**
|
||||
* @see RFC1213, "MIB-II, 6. Definitions"
|
||||
|
@ -475,9 +475,9 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry()\n"));
|
||||
LWIP_ASSERT("netif->hwaddr_len == ETHARP_HWADDR_LEN", netif->hwaddr_len == ETHARP_HWADDR_LEN);
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
|
||||
ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr),
|
||||
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
|
||||
ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
|
||||
ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr),
|
||||
ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2],
|
||||
ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5]));
|
||||
/* non-unicast address? */
|
||||
if (ip_addr_isany(ipaddr) ||
|
||||
ip_addr_isbroadcast(ipaddr, netif) ||
|
||||
@ -688,7 +688,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr));
|
||||
|
||||
/* this interface is not configured? */
|
||||
if (netif->ip_addr.addr == 0) {
|
||||
if (ip_addr_isany(&netif->ip_addr)) {
|
||||
for_us = 0;
|
||||
} else {
|
||||
/* ARP packet directed to us? */
|
||||
@ -724,8 +724,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
that would allocate a new pbuf. */
|
||||
hdr->opcode = htons(ARP_REPLY);
|
||||
|
||||
hdr->dipaddr = hdr->sipaddr;
|
||||
SMEMCPY(&hdr->sipaddr, &netif->ip_addr, sizeof(hdr->sipaddr));
|
||||
SMEMCPY(&hdr->dipaddr, &hdr->sipaddr, sizeof(struct ip_addr));
|
||||
SMEMCPY(&hdr->sipaddr, &netif->ip_addr, sizeof(struct ip_addr));
|
||||
|
||||
LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!",
|
||||
(netif->hwaddr_len == ETHARP_HWADDR_LEN));
|
||||
@ -754,7 +754,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
|
||||
/* return ARP reply */
|
||||
netif->linkoutput(netif, p);
|
||||
/* we are not configured? */
|
||||
} else if (netif->ip_addr.addr == 0) {
|
||||
} else if (ip_addr_isany(&netif->ip_addr)) {
|
||||
/* { for_us == 0 and netif->ip_addr.addr == 0 } */
|
||||
LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored.\n"));
|
||||
/* request was not directed to us */
|
||||
@ -840,7 +840,7 @@ etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr)
|
||||
/* outside local network? */
|
||||
if (!ip_addr_netcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) {
|
||||
/* interface has default gateway? */
|
||||
if (netif->gw.addr != 0) {
|
||||
if (!ip_addr_isany(&netif->gw)) {
|
||||
/* send to hardware address of default gateway IP address */
|
||||
ipaddr = &(netif->gw);
|
||||
/* no default gateway available */
|
||||
@ -1101,8 +1101,10 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
|
||||
#endif /* LWIP_AUTOIP */
|
||||
ethhdr->src.addr[k] = ethsrc_addr->addr[k];
|
||||
}
|
||||
hdr->sipaddr = *(struct ip_addr2 *)ipsrc_addr;
|
||||
hdr->dipaddr = *(struct ip_addr2 *)ipdst_addr;
|
||||
/* Copy struct ip_addr2 to aligned ip_addr, to support compilers without
|
||||
* structure packing. */
|
||||
SMEMCPY(&hdr->sipaddr, ipsrc_addr, sizeof(struct ip_addr));
|
||||
SMEMCPY(&hdr->dipaddr, ipdst_addr, sizeof(struct ip_addr));
|
||||
|
||||
hdr->hwtype = htons(HWTYPE_ETHERNET);
|
||||
hdr->proto = htons(ETHTYPE_IP);
|
||||
|
Loading…
x
Reference in New Issue
Block a user