ether.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <stdlib.h>
  2. #include <netinet/ether.h>
  3. #include <stdio.h>
  4. struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a)
  5. {
  6. struct ether_addr a;
  7. char *y;
  8. for (int ii = 0; ii < 6; ii++) {
  9. unsigned long int n;
  10. if (ii != 0) {
  11. if (x[0] != ':') return 0; /* bad format */
  12. else x++;
  13. }
  14. n = strtoul (x, &y, 16);
  15. x = y;
  16. if (n > 0xFF) return 0; /* bad byte */
  17. a.ether_addr_octet[ii] = n;
  18. }
  19. if (x[0] != 0) return 0; /* bad format */
  20. *p_a = a;
  21. return p_a;
  22. }
  23. struct ether_addr *ether_aton (const char *x)
  24. {
  25. static struct ether_addr a;
  26. return ether_aton_r (x, &a);
  27. }
  28. char *ether_ntoa_r (const struct ether_addr *p_a, char *x) {
  29. char *y;
  30. y = x;
  31. for (int ii = 0; ii < 6; ii++) {
  32. x += sprintf (x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]);
  33. }
  34. return y;
  35. }
  36. char *ether_ntoa (const struct ether_addr *p_a) {
  37. static char x[18];
  38. return ether_ntoa_r (p_a, x);
  39. }
  40. int ether_line(const char *l, struct ether_addr *e, char *hostname)
  41. {
  42. return -1;
  43. }
  44. int ether_ntohost(char *hostname, const struct ether_addr *e)
  45. {
  46. return -1;
  47. }
  48. int ether_hostton(const char *hostname, struct ether_addr *e)
  49. {
  50. return -1;
  51. }