uint8_t syslog_check_cache(void) { uip_ipaddr_t ipaddr; #ifdef IPV6_SUPPORT if(memcmp(syslog_conn->ripaddr, uip_hostaddr, 8)) /* Remote address is not on the local network, use router */ uip_ipaddr_copy(&ipaddr, uip_draddr); else /* Remote address is on the local network, send directly. */ uip_ipaddr_copy(&ipaddr, syslog_conn->ripaddr); if (uip_ipaddr_cmp(&ipaddr, &all_zeroes_addr)) return 1; /* Cowardly refusing to send IPv6 packet to :: */ if(uip_neighbor_lookup (ipaddr)) return 0; #else /* IPV4_SUPPORT */ if(!uip_ipaddr_maskcmp(syslog_conn->ripaddr, uip_hostaddr, uip_netmask)) /* Remote address is not on the local network, use router */ uip_ipaddr_copy(&ipaddr, uip_draddr); else /* Remote address is on the local network, send directly. */ uip_ipaddr_copy(&ipaddr, syslog_conn->ripaddr); #ifdef ETHERNET_SUPPORT /* uip_arp_lookup returns a pointer if the mac is in the arp cache */ if(uip_arp_lookup (ipaddr)) #endif return 0; #endif return 1; }
/*-----------------------------------------------------------------------------------*/ uint8_t uip_arp_out(void) { #ifdef MDNS_SD_SUPPORT uip_ipaddr_t mdns_address = {0x00e0, 0xfb00}; #endif /* Find the destination IP address in the ARP table and construct the Ethernet header. If the destination IP addres isn't on the local network, we use the default router's IP address instead. If not ARP table entry is found, we overwrite the original IP packet with an ARP request for the IP address. */ /* First check if destination is a local broadcast. */ if(((const uint8_t *)IPBUF->destipaddr)[0] >= 224 && ((const uint8_t *)IPBUF->destipaddr)[0] <= 239) { /* packet is addressed to multicast ip range, generate the associated mac address for it. */ IPBUF->ethhdr.dest.addr[0] = 0x01; IPBUF->ethhdr.dest.addr[1] = 0x00; IPBUF->ethhdr.dest.addr[2] = 0x5e; IPBUF->ethhdr.dest.addr[3] = ((const uint8_t *)IPBUF->destipaddr)[1] & 0x7f; IPBUF->ethhdr.dest.addr[4] = ((const uint8_t *)IPBUF->destipaddr)[2]; IPBUF->ethhdr.dest.addr[5] = ((const uint8_t *)IPBUF->destipaddr)[3]; } else if((IPBUF->destipaddr[0] == (uip_hostaddr[0] | ~uip_netmask[0]) && IPBUF->destipaddr[1] == (uip_hostaddr[1] | ~uip_netmask[1])) || (uip_ipaddr_cmp(IPBUF->destipaddr, broadcast_ipaddr))) { memcpy(IPBUF->ethhdr.dest.addr, broadcast_ethaddr.addr, 6); #ifdef MDNS_SD_SUPPORT /* If the ip is the mdns mulicast ip, we answer to the mac who asked */ } else if (uip_ipaddr_cmp(IPBUF->destipaddr, mdns_address)) { memcpy(IPBUF->ethhdr.dest.addr, &((struct uip_eth_hdr *) uip_buf)->dest, 6); #endif } else { /* Check if the destination address is on the local network. */ if(!uip_ipaddr_maskcmp(IPBUF->destipaddr, uip_hostaddr, uip_netmask)) { /* Destination address was not on the local network, so we need to use the default router's IP address instead of the destination address when determining the MAC address. */ uip_ipaddr_copy(ipaddr, uip_draddr); } else { /* Else, we use the destination IP address. */ uip_ipaddr_copy(ipaddr, IPBUF->destipaddr); } struct arp_entry *tabptr = uip_arp_lookup (ipaddr); if(!tabptr) { /* The destination address was not in our ARP table, so we overwrite the IP packet with an ARP request. */ memset(BUF->ethhdr.dest.addr, 0xff, 6); memset(BUF->dhwaddr.addr, 0x00, 6); memcpy(BUF->ethhdr.src.addr, uip_ethaddr.addr, 6); memcpy(BUF->shwaddr.addr, uip_ethaddr.addr, 6); uip_ipaddr_copy(BUF->dipaddr, ipaddr); uip_ipaddr_copy(BUF->sipaddr, uip_hostaddr); BUF->opcode = HTONS(ARP_REQUEST); /* ARP request. */ BUF->hwtype = HTONS(ARP_HWTYPE_ETH); BUF->protocol = HTONS(UIP_ETHTYPE_IP); BUF->hwlen = 6; BUF->protolen = 4; BUF->ethhdr.type = HTONS(UIP_ETHTYPE_ARP); /* FIXME uip_appdata = &uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN]; */ uip_len = sizeof(struct arp_hdr); return 1; } /* Build an ethernet header. */ memcpy(IPBUF->ethhdr.dest.addr, tabptr->ethaddr.addr, 6); } memcpy(IPBUF->ethhdr.src.addr, uip_ethaddr.addr, 6); IPBUF->ethhdr.type = HTONS(UIP_ETHTYPE_IP); uip_len += sizeof(struct uip_eth_hdr); return 0; }