akaros/user/iplib/parseether.c
<<
>>
Prefs
   1/*
   2 * This file is part of the UCB release of Plan 9. It is subject to the license
   3 * terms in the LICENSE file found in the top-level directory of this
   4 * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
   5 * part of the UCB release of Plan 9, including this file, may be copied,
   6 * modified, propagated, or distributed except according to the terms contained
   7 * in the LICENSE file.
   8 */
   9#include <stdlib.h>
  10
  11#include <iplib/iplib.h>
  12#include <parlib/parlib.h>
  13#include <signal.h>
  14#include <stdio.h>
  15#include <unistd.h>
  16
  17int parseether(uint8_t *to, char *from)
  18{
  19        char nip[4];
  20        char *p;
  21        int i;
  22
  23        p = from;
  24        for (i = 0; i < 6; i++) {
  25                if (*p == 0)
  26                        return -1;
  27                nip[0] = *p++;
  28                if (*p == 0)
  29                        return -1;
  30                nip[1] = *p++;
  31                nip[2] = 0;
  32                to[i] = strtoul(nip, 0, 16);
  33                if (*p == ':')
  34                        p++;
  35        }
  36        return 0;
  37}
  38