parseether.c 318 B

12345678910111213141516171819202122232425
  1. #include <u.h>
  2. #include <libc.h>
  3. int
  4. parseether(uchar *to, char *from)
  5. {
  6. char nip[4];
  7. char *p;
  8. int i;
  9. p = from;
  10. for(i = 0; i < 6; i++){
  11. if(*p == 0)
  12. return -1;
  13. nip[0] = *p++;
  14. if(*p == 0)
  15. return -1;
  16. nip[1] = *p++;
  17. nip[2] = 0;
  18. to[i] = strtoul(nip, 0, 16);
  19. if(*p == ':')
  20. p++;
  21. }
  22. return 0;
  23. }