]> jfr.im git - irc/ircd-hybrid/libopm.git/commitdiff
Some systems don't have inet_aton(), Solaris being a great example. Here's
authorandy <redacted>
Thu, 12 Sep 2002 06:12:12 +0000 (06:12 +0000)
committerandy <redacted>
Thu, 12 Sep 2002 06:12:12 +0000 (06:12 +0000)
our own implementation which is only included if inet_aton() is not
available.

src/compat.c [new file with mode: 0644]
src/compat.h [new file with mode: 0644]
src/proxy.c

diff --git a/src/compat.c b/src/compat.c
new file mode 100644 (file)
index 0000000..35f2ef2
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+Copyright (C) 2002  Andy Smith
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to
+
+        The Free Software Foundation, Inc.
+       59 Temple Place - Suite 330
+       Boston, MA  02111-1307, USA
+*/
+
+#include "setup.h"
+
+#include <stdio.h>
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#endif
+
+#ifndef HAVE_INET_ATON
+# include <netinet/in.h>
+#endif
+
+#include "compat.h"
+#include "opm.h"
+
+RCSID("$Id$");
+
+#ifndef HAVE_INET_ATON
+/*
+ * An implementation of inet_aton for those systems that don't have it
+ * (Solaris, ...)
+ */
+int inet_aton(const char *cp, struct in_addr *inp)
+{
+       unsigned int a1, a2, a3, a4;
+       unsigned long ret;
+
+       if (strcmp(cp, "255.255.255.255") == 0) {
+               inp->s_addr = (unsigned) -1;
+               return 0;
+       }
+
+       if (sscanf(cp, "%u.%u.%u.%u", &a1, &a2, &a3, &a4) != 4 ||
+           a1 > 255 || a2 > 255 || a3 > 255 || a4 > 255) {
+               return 0;
+       }
+
+       ret = (a1 << 24) | (a2 << 16) | (a3 << 8) | a4;
+
+       inp->s_addr = htonl(ret);
+       
+       if (inp->s_addr == (unsigned) -1) {
+               return 0;
+       }
+       return 1;
+}
+#endif
diff --git a/src/compat.h b/src/compat.h
new file mode 100644 (file)
index 0000000..c747514
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#ifndef INADDR_NONE
+#define INADDR_NONE 0xffffffff
+#endif
+
+#ifndef HAVE_INET_ATON
+extern int inet_aton(const char *cp, struct in_addr *inp);
+#endif
+
+#endif
index a7f9f70a78eb83e0a7f117bf1dcd2564e26a5798..c788bd937432d2f6f372356370567a8913991627 100644 (file)
@@ -31,6 +31,7 @@
 #include "opm_error.h"
 #include "libopm.h"
 #include "inet.h"
+#include "compat.h"
 
 RCSID("$Id$");