Newer
Older
NetAddr-IP / Lite / Util / xs_include / inet_aton.c
  1. /* inet_aton.c
  2. *
  3. * Copyright 2006, Michael Robinton <michael@bizsystems.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. #ifndef LOCAL_HAVE_inet_aton
  21. #include <sys/types.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include <arpa/inet.h>
  25. int
  26. my_inet_aton(const char *cp, struct in_addr *inp)
  27. {
  28. # ifdef LOCAL_HAVE_inet_pton
  29. return inet_pton(AF_INET,cp,inp);
  30. # else
  31. # ifdef LOCAL_HAVE_inet_addr
  32. inp->s_addr = inet_addr(cp);
  33. if (inp->s_addr == -1) {
  34. if (strncmp("255.255.255.255",cp,15) == 0)
  35. return 1;
  36. else
  37. return 0;
  38. }
  39. return 1;
  40. # else
  41. # error inet_aton, inet_pton, inet_addr not defined on this platform
  42. # endif
  43. # endif
  44. }
  45. #define inet_aton my_inet_aton
  46. #endif