Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct netif* find_netif_based_on_dest_ip(struct pbuf *p, u16_t type, struct netif* source_netif){
- ip4_addr_t dest;
- struct netif* netif;
- s16_t ip_hdr_offset = SIZEOF_ETH_HDR;
- #if ETHARP_SUPPORT_VLAN
- struct eth_hdr* ethhdr = (struct eth_hdr *)p->payload;
- if ( ethhdr->type == PP_HTONS(ETHTYPE_VLAN)) {
- ip_hdr_offset += SIZEOF_VLAN_HDR;
- }
- #endif //ETHARP_SUPPORT_VLAN
- void* temp_pbuf = (u8_t *)p->payload + ip_hdr_offset;
- if(type == PP_HTONS(ETHTYPE_ARP)){
- struct etharp_hdr *ethhdr = (struct etharp_hdr *)temp_pbuf;
- IPADDR2_COPY(&dest, ðhdr->dipaddr);
- }
- else if(type == PP_HTONS(ETHTYPE_IP)){
- struct ip_hdr *iphdr = (struct ip_hdr *)temp_pbuf;
- ip_addr_copy_from_ip4(dest, iphdr->dest);
- }
- else {
- return source_netif;
- }
- for (netif = netif_list; netif != NULL; netif = netif->next) {
- if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
- u8_t for_us = (u8_t)ip4_addr_cmp(&dest, netif_ip4_addr(netif));
- if(for_us){
- break;
- }
- }
- }
- return netif == NULL ? source_netif : netif;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement