ipattr.c 998 B

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