Subject: | Patch for compiling under Windows |
This is a patch to allow the module to be compiled and used under win32 OSes. Mainly, I removed the dependency on IO::Interface (for Win32 only) and copied the inet_ntoa code from Socket.xs to Multicast.xs. After ifndefing the include of <netinet/in.h> for WIN32 the module compiled and the tests excluding test 4 succeeded.
I was able to send and receive multicasts.
Tested for perl, v5.8.4 built for MSWin32-x86-multi-thread (self compiled with vc6.0).
Will test for perl 5.8.0 shortly.
Is this ok to apply for future versions?
Happy coding,
Thomas
Index: Makefile.PL
===================================================================
--- IO-Socket-Multicast-1.00/Makefile.PL 2001-08-25 21:57:44.000000000 +0200
+++ IO-Socket-Multicast-1.00.patched/Makefile.PL 2005-07-05 20:13:32.445008600 +0200
@@ -4,13 +4,13 @@
use Config;
my @libs = ();
-push @libs,'-lresolv' unless $Config{d_inetaton};
+push @libs,'-lresolv' unless $Config{d_inetaton} or $^O eq 'MSWin32';
WriteMakefile(
NAME => 'IO::Socket::Multicast',
VERSION_FROM => 'Multicast.pm', # finds $VERSION
PREREQ_PM => {
- 'IO::Interface' => 0.94,
+ $^O eq 'MSWin32' ? () : ('IO::Interface' => 0.94),
},
LIBS => \@libs, # e.g., '-lm'
DEFINE => '', # e.g., '-DHAVE_SOMETHING'
Index: Multicast.xs
===================================================================
--- IO-Socket-Multicast-1.00/Multicast.xs 2001-08-25 21:57:44.000000000 +0200
+++ IO-Socket-Multicast-1.00.patched/Multicast.xs 2005-07-05 20:15:34.469936600 +0200
@@ -5,7 +5,9 @@
#include <stdio.h>
#include <errno.h>
+#ifndef WIN32
#include <netinet/in.h>
+#endif
#include <sys/socket.h>
#ifdef PerlIO
@@ -23,6 +25,103 @@
return -1;
}
+#ifdef WIN32
+static int
+my_inet_aton(register const char *cp, struct in_addr *addr)
+{
+ dTHX;
+ register U32 val;
+ register int base;
+ register char c;
+ int nparts;
+ const char *s;
+ unsigned int parts[4];
+ register unsigned int *pp = parts;
+
+ if (!cp || !*cp)
+ return 0;
+ for (;;) {
+ /*
+ * Collect number up to ``.''.
+ * Values are specified as for C:
+ * 0x=hex, 0=octal, other=decimal.
+ */
+ val = 0; base = 10;
+ if (*cp == '0') {
+ if (*++cp == 'x' || *cp == 'X')
+ base = 16, cp++;
+ else
+ base = 8;
+ }
+ while ((c = *cp) != '\0') {
+ if (isDIGIT(c)) {
+ val = (val * base) + (c - '0');
+ cp++;
+ continue;
+ }
+ if (base == 16 && (s=strchr(PL_hexdigit,c))) {
+ val = (val << 4) +
+ ((s - PL_hexdigit) & 15);
+ cp++;
+ continue;
+ }
+ break;
+ }
+ if (*cp == '.') {
+ /*
+ * Internet format:
+ * a.b.c.d
+ * a.b.c (with c treated as 16-bits)
+ * a.b (with b treated as 24 bits)
+ */
+ if (pp >= parts + 3 || val > 0xff)
+ return 0;
+ *pp++ = val, cp++;
+ } else
+ break;
+ }
+ /*
+ * Check for trailing characters.
+ */
+ if (*cp && !isSPACE(*cp))
+ return 0;
+ /*
+ * Concoct the address according to
+ * the number of parts specified.
+ */
+ nparts = pp - parts + 1; /* force to an int for switch() */
+ switch (nparts) {
+
+ case 1: /* a -- 32 bits */
+ break;
+
+ case 2: /* a.b -- 8.24 bits */
+ if (val > 0xffffff)
+ return 0;
+ val |= parts[0] << 24;
+ break;
+
+ case 3: /* a.b.c -- 8.8.16 bits */
+ if (val > 0xffff)
+ return 0;
+ val |= (parts[0] << 24) | (parts[1] << 16);
+ break;
+
+ case 4: /* a.b.c.d -- 8.8.8.8 bits */
+ if (val > 0xff)
+ return 0;
+ val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+ break;
+ }
+ addr->s_addr = htonl(val);
+ return 1;
+}
+
+#undef inet_aton
+#define inet_aton my_inet_aton
+
+#endif
+
MODULE = IO::Socket::Multicast PACKAGE = IO::Socket
void