Diff for /libelwix/src/net.c between versions 1.15 and 1.17.10.1

version 1.15, 2016/08/02 11:44:59 version 1.17.10.1, 2018/03/15 14:49:56
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004 - 2016Copyright 2004 - 2018
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 49  SUCH DAMAGE. Line 49  SUCH DAMAGE.
 #ifndef __linux__  #ifndef __linux__
 static char hexlist[] = "0123456789abcdef";  static char hexlist[] = "0123456789abcdef";
   
   #ifndef HAVE_LINK_ADDR
   
   /* States*/
   #define NAMING  0
   #define GOTONE  1
   #define GOTTWO  2
   #define RESET   3
   /* Inputs */
   #define DIGIT   (4*0)
   #define END     (4*1)
   #define DELIM   (4*2)
   #define LETTER  (4*3)
   
   void
   link_addr(const char *addr, struct sockaddr_dl *sdl)
   {
           char *cp = sdl->sdl_data;
           char *cplim = sdl->sdl_len + (char *)sdl;
           int byte = 0, state = NAMING, new;
   
           bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1);
           sdl->sdl_family = AF_LINK;
           do {
                   state &= ~LETTER;
                   if ((*addr >= '0') && (*addr <= '9')) {
                           new = *addr - '0';
                   } else if ((*addr >= 'a') && (*addr <= 'f')) {
                           new = *addr - 'a' + 10;
                   } else if ((*addr >= 'A') && (*addr <= 'F')) {
                           new = *addr - 'A' + 10;
                   } else if (*addr == 0) {
                           state |= END;
                   } else if (state == NAMING &&
                              (((*addr >= 'A') && (*addr <= 'Z')) ||
                              ((*addr >= 'a') && (*addr <= 'z'))))
                           state |= LETTER;
                   else
                           state |= DELIM;
                   addr++;
                   switch (state /* | INPUT */) {
                   case NAMING | DIGIT:
                   case NAMING | LETTER:
                           *cp++ = addr[-1];
                           continue;
                   case NAMING | DELIM:
                           state = RESET;
                           sdl->sdl_nlen = cp - sdl->sdl_data;
                           continue;
                   case GOTTWO | DIGIT:
                           *cp++ = byte;
                           /* FALLTHROUGH */
                   case RESET | DIGIT:
                           state = GOTONE;
                           byte = new;
                           continue;
                   case GOTONE | DIGIT:
                           state = GOTTWO;
                           byte = new + (byte << 4);
                           continue;
                   default: /* | DELIM */
                           state = RESET;
                           *cp++ = byte;
                           byte = 0;
                           continue;
                   case GOTONE | END:
                   case GOTTWO | END:
                           *cp++ = byte;
                           /* FALLTHROUGH */
                   case RESET | END:
                           break;
                   }
                   break;
           } while (cp < cplim);
           sdl->sdl_alen = cp - LLADDR(sdl);
           new = cp - (char *)sdl;
           if (new > sizeof(*sdl))
                   sdl->sdl_len = new;
           return;
   }
   #endif
   
   
 /*  /*
  * e_link_ntoa() - String ethernet address from link address   * e_link_ntoa() - String ethernet address from link address
  *   *
Line 340  e_addrlen(const sockaddr_t *addr) Line 422  e_addrlen(const sockaddr_t *addr)
 #endif  #endif
         }          }
   
        return MIN(sizeof(sockaddr_t), 0xff);        return E_SOCKADDR_MAX;
 }  }
   
 /*  /*
Line 481  e_getnet(const char *net) Line 563  e_getnet(const char *net)
 #endif  #endif
                         n->addr.sin.sin_family = host->h_addrtype;                          n->addr.sin.sin_family = host->h_addrtype;
                         memcpy(&n->addr.sin.sin_addr, host->h_addr, sizeof n->addr.sin.sin_addr);                          memcpy(&n->addr.sin.sin_addr, host->h_addr, sizeof n->addr.sin.sin_addr);
                        if (wrk)                        if (wrk && strtol(wrk, NULL, 10) != 32)
                                 n->mask.in.s_addr = E_CIDRMASK(strtol(wrk, NULL, 10));                                  n->mask.in.s_addr = E_CIDRMASK(strtol(wrk, NULL, 10));
                         else                          else
                                 n->mask.in.s_addr = 0xFFFFFFFF;                                  n->mask.in.s_addr = 0xFFFFFFFF;

Removed from v.1.15  
changed lines
  Added in v.1.17.10.1


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>