--- boost/asio/detail/io_control.hpp.orig	2010-12-06 01:32:39.000000000 +0300
+++ boost/asio/detail/io_control.hpp	2010-12-06 01:37:34.000000000 +0300
@@ -44,7 +44,7 @@
   }
 
   // Get the name of the IO control command.
-  int name() const
+  ioctl_cmd_type name() const
   {
     return FIONBIO;
   }
@@ -94,7 +94,7 @@
   }
 
   // Get the name of the IO control command.
-  int name() const
+  ioctl_cmd_type name() const
   {
     return FIONREAD;
   }
--- boost/asio/detail/descriptor_ops.hpp.orig	2010-12-06 01:55:08.000000000 +0300
+++ boost/asio/detail/descriptor_ops.hpp	2010-12-06 01:55:39.000000000 +0300
@@ -79,7 +79,7 @@
     const buf* bufs, std::size_t count,
     boost::system::error_code& ec, std::size_t& bytes_transferred);
 
-BOOST_ASIO_DECL int ioctl(int d, state_type& state, long cmd,
+BOOST_ASIO_DECL int ioctl(int d, state_type& state, ioctl_cmd_type cmd,
     ioctl_arg_type* arg, boost::system::error_code& ec);
 
 BOOST_ASIO_DECL int fcntl(int d, long cmd, boost::system::error_code& ec);
--- boost/asio/detail/socket_ops.hpp.orig	2010-12-06 01:58:36.000000000 +0300
+++ boost/asio/detail/socket_ops.hpp	2010-12-06 01:59:42.000000000 +0300
@@ -222,7 +222,7 @@
     std::size_t* addrlen, boost::system::error_code& ec);
 
 BOOST_ASIO_DECL int ioctl(socket_type s, state_type& state,
-    int cmd, ioctl_arg_type* arg, boost::system::error_code& ec);
+    ioctl_cmd_type cmd, ioctl_arg_type* arg, boost::system::error_code& ec);
 
 BOOST_ASIO_DECL int select(int nfds, fd_set* readfds, fd_set* writefds,
     fd_set* exceptfds, timeval* timeout, boost::system::error_code& ec);
--- boost/asio/detail/impl/descriptor_ops.ipp.orig	2010-12-06 01:44:38.000000000 +0300
+++ boost/asio/detail/impl/descriptor_ops.ipp	2010-12-06 01:41:33.000000000 +0300
@@ -251,7 +251,7 @@
   }
 }
 
-int ioctl(int d, state_type& state, long cmd,
+int ioctl(int d, state_type& state, ioctl_cmd_type cmd,
     ioctl_arg_type* arg, boost::system::error_code& ec)
 {
   if (d == -1)
@@ -273,7 +273,7 @@
     // descriptor is put into the state that has been requested by the user. If
     // the ioctl syscall was successful then we need to update the flags to
     // match.
-    if (cmd == static_cast<long>(FIONBIO))
+    if (cmd == static_cast<ioctl_cmd_type>(FIONBIO))
     {
       if (*arg)
       {
--- boost/asio/detail/impl/socket_ops.ipp.orig	2010-12-06 01:46:05.000000000 +0300
+++ boost/asio/detail/impl/socket_ops.ipp	2010-12-06 01:49:39.000000000 +0300
@@ -1414,7 +1414,7 @@
   return result;
 }
 
-int ioctl(socket_type s, state_type& state, int cmd,
+int ioctl(socket_type s, state_type& state, ioctl_cmd_type cmd,
     ioctl_arg_type* arg, boost::system::error_code& ec)
 {
   if (s == invalid_socket)
@@ -1424,15 +1424,10 @@
   }
 
   clear_last_error();
-#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
-  int result = error_wrapper(::ioctlsocket(s, cmd, arg), ec);
-#elif defined(__MACH__) && defined(__APPLE__) \
-  || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
+
   int result = error_wrapper(::ioctl(s,
-        static_cast<unsigned int>(cmd), arg), ec);
-#else
-  int result = error_wrapper(::ioctl(s, cmd, arg), ec);
-#endif
+        static_cast<ioctl_cmd_type>(cmd), arg), ec);
+
   if (result >= 0)
   {
     ec = boost::system::error_code();
@@ -1442,7 +1437,7 @@
     // the correct state. This ensures that the underlying socket is put into
     // the state that has been requested by the user. If the ioctl syscall was
     // successful then we need to update the flags to match.
-    if (cmd == static_cast<int>(FIONBIO))
+    if (cmd == static_cast<ioctl_cmd_type>(FIONBIO))
     {
       if (*arg)
       {
--- boost/asio/detail/socket_types.hpp.orig	2010-12-06 01:35:39.000000000 +0300
+++ boost/asio/detail/socket_types.hpp	2010-12-06 01:36:05.000000000 +0300
@@ -147,6 +147,12 @@
 typedef sockaddr_storage sockaddr_storage_type;
 typedef sockaddr_un sockaddr_un_type;
 typedef addrinfo addrinfo_type;
+#if (defined(__MACH__) && defined(__APPLE__)) || defined(__DragonFly__) || \
+    defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+typedef unsigned long ioctl_cmd_type;
+#else
+typedef int ioctl_cmd_type;
+#endif
 typedef int ioctl_arg_type;
 typedef uint32_t u_long_type;
 typedef uint16_t u_short_type;
