BSD-3-Clause licensed
Maintained by Kazu Yamamoto, Evan Borden
This version can be pinned in stack with:network-,4268

network Build Status Build status

To build this package directly from git, you must run autoreconf -i. And then use cabal configure; cabal build or stack build.

Support Policy


The network package support 3 major versions of GHC only. This means that the current stable version and two previous stable versions are supported.


We use MSYS to build this package on Windows. To use the network package on Cygwin, use stack.


.hs files

If you need C macros created by “configure” or CALLCONV/SAFE_ON_WIN, put

#include "HsNetDef.h"

“HsNet.h” does now work well since Mac’s cpp sucks.

.hsc files

If you need #peek, #poke and others, create a .hsc file with

#include "HsNet.h"

HsNet.h includes HsNefDef.h and necessary C structures. Unfortunately, hsc2hs does not convert C macros. So, if you use CALLCONV/SAFE_ON_WIN, the following is also necessary:

##include "HsNetDef.h"



  • [x] Making SockAddrCan deprecated



  • [x] Making Network deprecated
  • [x] Making Network.BSD deprecated
  • [x] Making MkSocket deprecated
  • [x] Making many APIs deprecated


  • [x] Stop exporting the PortNum Constructor in PortNumber


  • [x] Removing Network
  • [x] Removing Network.BSD
  • [x] Removing SockAddrCan
  • [x] Changing the internal structure of Socket.
  • [x] Make address extensible.
  • [x] Remove EOF errors



  • Fix for GHCJS. #431


  • A new API: gracefulClose. #417
  • touchSocket, unsafeFdSocket: Allow direct access to a socket’s file descriptor while providing tools to prevent it from being garbage collected. This also deprecated fdSocket in favor of unsafeFdSocket and withFdSocket. #423
  • socketToFd: Duplicates a socket as a file desriptor and closes the source socket. #424


  • getAddrInfo: raise exception if no AddrInfo returned. #410
  • Avoid catching SomeException. #411


  • Making GC of socket safer. #399
  • Deprecating fdSocket. Use withFdSocket instead to ensure that sockets are GCed in proper time. #399


  • Fix blocking if_nametoindex errors on Windows #391


  • Added getSocketType :: Socket -> IO SocketType. #372
  • Correcting manual and brushing up test cases #375
  • Fixed longstanded bug in getContents on mac #375
  • Fixing regression: set correct sockaddr length for abstract addresses for Linux. #374


  • Fixed a bug in connect where exceptions were not thrown #368


  • Breaking change: the Network and Network.BSD are removed. Network.BSD is provided a new package: network-bsd.
  • Breaking change: the signatures are changed:
old fdSocket :: Socket -> CInt
new fdSocket :: Socket -> IO CInt

old mkSocket :: CInt -> Family -> SocketType -> ProtocolNumber -> SocketStatus -> IO Socket
new mkSocket :: CInt -> IO Socket
  • Breaking change: the deprecated APIs are removed: send, sendTo, recv, recvFrom, recvLen, htonl, ntohl, inet_addr, int_ntoa, bindSocket, sClose, SocketStatus, isConnected, isBound, isListening, isReadable, isWritable, sIsConnected, sIsBound, sIsListening, sIsReadable, sIsWritable, aNY_PORT, iNADDR_ANY, iN6ADDR_ANY, sOMAXCONN, sOL_SOCKET, sCM_RIGHTS, packSocketType, getPeerCred.
  • Breaking change: SockAddrCan is removed from SockAddr.
  • Socket addresses are extendable with Network.Socket.Address.
  • “socket” is now asynchronous-exception-safe. #336
  • “recvFrom” returns (0, addr) instead of throwing an error on EOF. #360
  • All APIs are available on any platforms.
  • Build system is simplified.
  • Bug fixes.


  • Eensuring that accept returns a correct sockaddr for unix domain. #400
  • Avoid out of bounds writes in pokeSockAddr. #400


  • Breaking change: PortNumber originally contained Word16 in network byte order and used “deriving Ord”. This results in strange behavior on the Ord instance. Now PortNumber holds Word16 in host byte order. #347
  • Breaking change: stopping the export of the PortNum constructor in PortNumber.
  • Use bytestring == 0.10.* only.
  • Use base >= 4.7 && < 5.


  • Removing withMVar to avoid the deadlock between “accept” and “close” #330
  • “close” does not throw exceptions. A new API: “close’” throws exceptions when necessary. #337
  • Fixing the hang of lazy sendAll. #340
  • Installing NetDef.h (#334) #334


  • A new API: socketPortSafe. #319
  • Fixing a drain bug of sendAll. #320
  • Porting the new CALLCONV convention from master. #313
  • Withdrawing the deprecations of packFamily and unpackFamily. #324


  • Obsoleting the Network module.
  • Obsoleting the Network.BSD module.
  • Obsoleting APIs: MkSocket, htonl, ntohl, getPeerCred, getPeerEid, send, sendTo, recv, recvFrom, recvLen, inet_addr, inet_ntoa, isConnected, isBound, isListening, isReadable, isWritable, aNY_PORT, iNADDR_ANY, iN6ADDR_ANY, sOMAXCONN, sOL_SOCKET, sCM_RIGHTS, packFamily, unpackFamily, packSocketType
  • Breaking change: do not closeFd within sendFd. #271
  • Exporting ifNameToIndex and ifIndexToName from Network.Socket.
  • New APIs: setCloseOnExecIfNeeded, getCloseOnExec and getNonBlock
  • New APIs: isUnixDomainSocketAvailable and getPeerCredential
  • socketPair, sendFd and recvFd are exported even on Windows.


  • Reverting “Do not closeFd within sendFd” #271


  • Don’t touch IPv6Only when running on OpenBSD #227
  • Do not closeFd within sendFd #271
  • Updating examples and docs.


  • Adds a function to show the defaultHints without reading their undefined fields #291
  • Improve exception error messages for getAddrInfo and getNameInfo #289


  • Zero memory of sockaddr_un if abstract socket #220

  • Improving error messages #232

  • Allow non-blocking file descriptors via setNonBlockIfNeeded #242

  • Update config.{guess,sub} to latest version #244

  • Rename my_inet_ntoa to avoid symbol conflicts #228

  • Test infrastructure improvements #219 #217 #218

  • House keeping and cleanup #238 #237


  • Reverse breaking exception change in Network.Socket.ByteString.recv #215


  • New maintainers: Evan Borden (@eborden) and Kazu Yamamoto (@kazu-yamamoto). The maintainer for a long period, Johan Tibell (@tibbe) stepped down. Thank you, Johan, for your hard work for a long time.

  • New APIs: ntohl, htonl,hostAddressToTuple{,6} and tupleToHostAddress{,6}. #210

  • Added a Read instance for PortNumber. #145

  • We only set the IPV6_V6ONLY flag to 0 for stream and datagram socket types, as opposed to all of them. This makes it possible to use ICMPv6. #180 #181

  • Work around GHC bug #12020. Socket errors no longer cause segfaults or hangs on Windows. #192

  • Various documentation improvements and the deprecated pragmas. #186 #201 #205 #206 #211

  • Various internal improvements. #193 #200


  • Regenerate configure and

  • Better detection of CAN sockets.


  • Add support for TCP_USER_TIMEOUT.

  • Don’t conditionally export the SockAddr constructors.

  • Add isSupportSockAddr to allow checking for supported address types at runtime.