Newer
Older
NetAddr-IP / Lite / Util / xs_include / inet_aton.c
@Michael Robinton Michael Robinton on 21 Oct 2014 1 KB Import of MIKER/NetAddr-IP-4.015 from CPAN.
  1. /* inet_aton.c
  2. *
  3. * Copyright 2006 - 2008, 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 HAVE_INET_ATON
  21.  
  22. int
  23. my_inet_aton(const char *cp, struct in_addr *inp)
  24. {
  25. # ifdef HAVE_INET_PTON
  26. return inet_pton(AF_INET,cp,inp);
  27. # else
  28. # ifdef HAVE_INET_ADDR
  29. inp->s_addr = inet_addr(cp);
  30. if (inp->s_addr == -1) {
  31. if (strncmp("255.255.255.255",cp,15) == 0)
  32. return 1;
  33. else
  34. return 0;
  35. }
  36. return 1;
  37. # else
  38. # error inet_aton, inet_pton, inet_addr not defined on this platform
  39. # endif
  40. # endif
  41. }
  42. #define inet_aton my_inet_aton
  43. #endif