You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

misc.c 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**************************************************************************
  2. MISC Support Routines
  3. **************************************************************************/
  4. FILE_LICENCE ( GPL2_OR_LATER );
  5. #include <stdlib.h>
  6. #include <ctype.h>
  7. #include <byteswap.h>
  8. #include <ipxe/in.h>
  9. #include <ipxe/timer.h>
  10. /**************************************************************************
  11. INET_ATON - Convert an ascii x.x.x.x to binary form
  12. **************************************************************************/
  13. int inet_aton ( const char *cp, struct in_addr *inp ) {
  14. const char *p = cp;
  15. const char *digits_start;
  16. unsigned long ip = 0;
  17. unsigned long val;
  18. int j;
  19. for(j = 0; j <= 3; j++) {
  20. digits_start = p;
  21. val = strtoul(p, ( char ** ) &p, 10);
  22. if ((p == digits_start) || (val > 255)) return 0;
  23. if ( ( j < 3 ) && ( *(p++) != '.' ) ) return 0;
  24. ip = (ip << 8) | val;
  25. }
  26. if ( *p == '\0' ) {
  27. inp->s_addr = htonl(ip);
  28. return 1;
  29. }
  30. return 0;
  31. }
  32. unsigned long strtoul ( const char *p, char **endp, int base ) {
  33. unsigned long ret = 0;
  34. unsigned int charval;
  35. base = strtoul_base ( &p, base );
  36. while ( 1 ) {
  37. charval = strtoul_charval ( *p );
  38. if ( charval >= ( unsigned int ) base )
  39. break;
  40. ret = ( ( ret * base ) + charval );
  41. p++;
  42. }
  43. if ( endp )
  44. *endp = ( char * ) p;
  45. return ( ret );
  46. }
  47. /*
  48. * Local variables:
  49. * c-basic-offset: 8
  50. * End:
  51. */