ipattr.c 586 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <u.h>
  2. #include <ctype.h>
  3. /*
  4. * return ndb attribute type of an ip name
  5. */
  6. char*
  7. ipattr(char *name)
  8. {
  9. char *p, c;
  10. int dot = 0;
  11. int alpha = 0;
  12. int colon = 0;
  13. int hex = 0;
  14. for(p = name; *p; p++){
  15. c = *p;
  16. if(isdigit(c))
  17. continue;
  18. if(isxdigit(c))
  19. hex = 1;
  20. else if(isalpha(c) || c == '-')
  21. alpha = 1;
  22. else if(c == '.')
  23. dot = 1;
  24. else if(c == ':')
  25. colon = 1;
  26. else
  27. return "sys";
  28. }
  29. if(alpha){
  30. if(dot)
  31. return "dom";
  32. else
  33. return "sys";
  34. }
  35. if(colon)
  36. return "ip"; /* ip v6 */
  37. if(dot && !hex)
  38. return "ip";
  39. else
  40. return "sys";
  41. }