Diff for /libelwix/src/net.c between versions 1.16 and 1.17

version 1.16, 2016/08/02 12:03:56 version 1.17, 2017/01/09 12:53:18
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 - 2017
         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 48  SUCH DAMAGE. Line 48  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

Removed from v.1.16  
changed lines
  Added in v.1.17


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