Advertisement
Guest User

Untitled

a guest
Feb 26th, 2023
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. struct netif* find_netif_based_on_dest_ip(struct pbuf *p, u16_t type, struct netif* source_netif){
  2. ip4_addr_t dest;
  3. struct netif* netif;
  4. s16_t ip_hdr_offset = SIZEOF_ETH_HDR;
  5.  
  6. #if ETHARP_SUPPORT_VLAN
  7. struct eth_hdr* ethhdr = (struct eth_hdr *)p->payload;
  8. if ( ethhdr->type == PP_HTONS(ETHTYPE_VLAN)) {
  9. ip_hdr_offset += SIZEOF_VLAN_HDR;
  10. }
  11. #endif //ETHARP_SUPPORT_VLAN
  12. void* temp_pbuf = (u8_t *)p->payload + ip_hdr_offset;
  13. if(type == PP_HTONS(ETHTYPE_ARP)){
  14. struct etharp_hdr *ethhdr = (struct etharp_hdr *)temp_pbuf;
  15. IPADDR2_COPY(&dest, &ethhdr->dipaddr);
  16. }
  17. else if(type == PP_HTONS(ETHTYPE_IP)){
  18. struct ip_hdr *iphdr = (struct ip_hdr *)temp_pbuf;
  19. ip_addr_copy_from_ip4(dest, iphdr->dest);
  20. }
  21. else {
  22. return source_netif;
  23. }
  24.  
  25. for (netif = netif_list; netif != NULL; netif = netif->next) {
  26. if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
  27. u8_t for_us = (u8_t)ip4_addr_cmp(&dest, netif_ip4_addr(netif));
  28. if(for_us){
  29. break;
  30. }
  31. }
  32. }
  33. return netif == NULL ? source_netif : netif;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement