ipaux.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "all.h"
  2. #include "../ip/ip.h"
  3. int
  4. chartoea(uchar *ea, char *cp)
  5. {
  6. int i, h, c;
  7. h = 0;
  8. for(i=0; i<Easize*2; i++) {
  9. c = *cp++;
  10. if(c >= '0' && c <= '9')
  11. c = c - '0';
  12. else
  13. if(c >= 'a' && c <= 'f')
  14. c = c - 'a' + 10;
  15. else
  16. if(c >= 'A' && c <= 'F')
  17. c = c - 'A' + 10;
  18. else
  19. return 1;
  20. h = (h*16) + c;
  21. if(i & 1) {
  22. *ea++ = h;
  23. h = 0;
  24. }
  25. }
  26. if(*cp != 0)
  27. return 1;
  28. return 0;
  29. }
  30. int
  31. chartoip(uchar *pa, char *cp)
  32. {
  33. int i, c, h;
  34. for(i=0;;) {
  35. h = 0;
  36. for(;;) {
  37. c = *cp++;
  38. if(c < '0' || c > '9')
  39. break;
  40. h = (h*10) + (c-'0');
  41. }
  42. *pa++ = h;
  43. i++;
  44. if(i == Pasize) {
  45. if(c != 0)
  46. return 1;
  47. return 0;
  48. }
  49. if(c != '.')
  50. return 1;
  51. }
  52. }
  53. void
  54. getipa(Ifc *ifc, int a)
  55. {
  56. memmove(ifc->ipa, ipaddr[a].sysip, Pasize);
  57. memmove(ifc->netgate, ipaddr[a].defgwip, Pasize);
  58. ifc->ipaddr = nhgetl(ifc->ipa);
  59. ifc->mask = nhgetl(ipaddr[a].defmask);
  60. ifc->cmask = ipclassmask(ifc->ipa);
  61. }
  62. int
  63. isvalidip(uchar ip[Pasize])
  64. {
  65. if(ip[0] || ip[1] || ip[2] || ip[3])
  66. return 1;
  67. return 0;
  68. }