Ignore:
Timestamp:
Nov 18, 2016, 2:58:30 PM (7 years ago)
Author:
coas-nagasima
Message:

uIPを更新
プロジェクトファイルを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uKadecot/trunk/uip/net/ipv4/uip-fw.c

    r158 r262  
    8686    proto;
    8787  uint16_t ipchksum;
    88   uint16_t srcipaddr[2],
    89     destipaddr[2];
     88  uip_ipaddr_t srcipaddr, destipaddr;
    9089 
    9190  /* TCP header. */
     
    112111    proto;
    113112  uint16_t ipchksum;
    114   uint16_t srcipaddr[2],
    115     destipaddr[2];
     113  uip_ipaddr_t srcipaddr, destipaddr;
    116114  /* ICMP (echo) header. */
    117115  uint8_t type, icode;
     
    144142  uint16_t timer;
    145143 
    146   uint16_t srcipaddr[2];
    147   uint16_t destipaddr[2];
     144  uip_ipaddr_t srcipaddr;
     145  uip_ipaddr_t destipaddr;
    148146  uint16_t ipid;
    149147  uint8_t proto;
     
    217215/*------------------------------------------------------------------------------*/
    218216static unsigned char
    219 ipaddr_maskcmp(uint16_t *ipaddr, uint16_t *netipaddr, uint16_t *netmask)
    220 {
    221   return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) &&
    222     (ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]);
     217ipaddr_maskcmp(uip_ipaddr_t *ipaddr,
     218               uip_ipaddr_t *netipaddr,
     219               uip_ipaddr_t *netmask)
     220{
     221  return (ipaddr->u16[0] & netmask->u16[0]) == (netipaddr->u16[0] & netmask->u16[0]) &&
     222    (ipaddr->u16[1] & netmask->u16[1]) == (netipaddr->u16[1] & netmask->u16[1]);
    223223}
    224224/*------------------------------------------------------------------------------*/
     
    254254  /* Set the IP destination address to be the source address of the
    255255     original packet. */
    256   tmp16= BUF->destipaddr[0];
    257   BUF->destipaddr[0] = BUF->srcipaddr[0];
    258   BUF->srcipaddr[0] = tmp16;
    259   tmp16 = BUF->destipaddr[1];
    260   BUF->destipaddr[1] = BUF->srcipaddr[1];
    261   BUF->srcipaddr[1] = tmp16;
     256  uip_ipaddr_copy(&BUF->destipaddr, &BUF->srcipaddr);
    262257
    263258  /* Set our IP address as the source address. */
    264   BUF->srcipaddr[0] = uip_hostaddr[0];
    265   BUF->srcipaddr[1] = uip_hostaddr[1];
     259  uip_ipaddr_copy(&BUF->srcipaddr, &uip_hostaddr);
    266260
    267261  /* The size of the ICMP time exceeded packet is 36 + the size of the
     
    269263  uip_len = 56;
    270264  ICMPBUF->len[0] = 0;
    271   ICMPBUF->len[1] = uip_len;
     265  ICMPBUF->len[1] = (uint8_t)uip_len;
    272266
    273267  /* Fill in the other fields in the IP header. */
     
    313307  fw->timer = FW_TIME;
    314308  fw->ipid = BUF->ipid;
    315   fw->srcipaddr[0] = BUF->srcipaddr[0];
    316   fw->srcipaddr[1] = BUF->srcipaddr[1];
    317   fw->destipaddr[0] = BUF->destipaddr[0];
    318   fw->destipaddr[1] = BUF->destipaddr[1];
     309  uip_ipaddr_copy(&fw->srcipaddr, &BUF->srcipaddr);
     310  uip_ipaddr_copy(&fw->destipaddr, &BUF->destipaddr);
    319311  fw->proto = BUF->proto;
    320312#if notdef
     
    340332  /* Walk through every network interface to check for a match. */
    341333  for(netif = netifs; netif != NULL; netif = netif->next) {
    342     if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
    343                       netif->netmask)) {
     334    if(ipaddr_maskcmp(&BUF->destipaddr, &netif->ipaddr,
     335                      &netif->netmask)) {
    344336      /* If there was a match, we break the loop. */
    345337      return netif;
     
    371363{
    372364  struct uip_fw_netif *netif;
     365#if UIP_BROADCAST
     366  const struct uip_udpip_hdr *udp = (void *)BUF;
     367#endif /* UIP_BROADCAST */
    373368
    374369  if(uip_len == 0) {
     
    380375#if UIP_BROADCAST
    381376  /* Link local broadcasts go out on all interfaces. */
    382   if(/*BUF->proto == UIP_PROTO_UDP &&*/
    383      BUF->destipaddr[0] == 0xffff &&
    384      BUF->destipaddr[1] == 0xffff) {
     377  if(uip_ipaddr_cmp(&udp->destipaddr, &uip_broadcast_addr)) {
    385378    if(defaultnetif != NULL) {
    386379      defaultnetif->output();
     
    422415  /* First check if the packet is destined for ourselves and return 0
    423416     to indicate that the packet should be processed locally. */
    424   if(BUF->destipaddr[0] == uip_hostaddr[0] &&
    425      BUF->destipaddr[1] == uip_hostaddr[1]) {
     417  if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_hostaddr)) {
    426418    return UIP_FW_LOCAL;
    427419  }
     
    430422     not yet configured, we should intercept all ICMP echo packets. */
    431423#if UIP_PINGADDRCONF
    432   if((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
     424  if(uip_ipaddr_cmp(&uip_hostaddr, &uip_all_zeroes_addr) &&
    433425     BUF->proto == UIP_PROTO_ICMP &&
    434426     ICMPBUF->type == ICMP_ECHO) {
     
    447439#endif
    448440       fw->ipid == BUF->ipid &&
    449        fw->srcipaddr[0] == BUF->srcipaddr[0] &&
    450        fw->srcipaddr[1] == BUF->srcipaddr[1] &&
    451        fw->destipaddr[0] == BUF->destipaddr[0] &&
    452        fw->destipaddr[1] == BUF->destipaddr[1] &&
     441       uip_ipaddr_cmp(&fw->srcipaddr, &BUF->srcipaddr) &&
     442       uip_ipaddr_cmp(&fw->destipaddr, &BUF->destipaddr) &&
    453443#if notdef
    454444       fw->payload[0] == BUF->srcport &&
     
    464454     in the uip_buf buffer and forward that packet back to the sender
    465455     of the packet. */
     456
    466457  if(BUF->ttl <= 1) {
    467458    /* No time exceeded for broadcasts and multicasts! */
    468     if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
     459    if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
    469460      return UIP_FW_LOCAL;
    470461    }
     
    476467 
    477468  /* Update the IP checksum. */
    478   if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {
    479     BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;
     469  if(BUF->ipchksum >= UIP_HTONS(0xffff - 0x0100)) {
     470    BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100) + 1;
    480471  } else {
    481     BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);
     472    BUF->ipchksum = BUF->ipchksum + UIP_HTONS(0x0100);
    482473  }
    483474
     
    488479
    489480#if UIP_BROADCAST
    490   if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
     481  if(uip_ipaddr_cmp(&BUF->destipaddr, &uip_broadcast_addr)) {
    491482    return UIP_FW_LOCAL;
    492483  }
Note: See TracChangeset for help on using the changeset viewer.