utils.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * Various kernel-resident INET utility functions; mainly
  7. * for format conversion and debugging output.
  8. *
  9. * Version: $Id: utils.c,v 1.8 2000/10/03 07:29:01 anton Exp $
  10. *
  11. * Author: Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12. *
  13. * Fixes:
  14. * Alan Cox : verify_area check.
  15. * Alan Cox : removed old debugging.
  16. * Andi Kleen : add net_ratelimit()
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/types.h>
  25. #include <asm/byteorder.h>
  26. /*
  27. * Convert an ASCII string to binary IP.
  28. */
  29. __u32 in_aton(const char *str)
  30. {
  31. unsigned long l;
  32. unsigned int val;
  33. int i;
  34. l = 0;
  35. for (i = 0; i < 4; i++)
  36. {
  37. l <<= 8;
  38. if (*str != '\0')
  39. {
  40. val = 0;
  41. while (*str != '\0' && *str != '.')
  42. {
  43. val *= 10;
  44. val += *str - '0';
  45. str++;
  46. }
  47. l |= val;
  48. if (*str != '\0')
  49. str++;
  50. }
  51. }
  52. return(htonl(l));
  53. }
  54. EXPORT_SYMBOL(in_aton);