Convert numeric IP to Network.Socket.HostAddress

I need to convert a numeric IP (such as 1.2.3.4) to a HostAddress for consumption by SockAddrInet. The only function I can find to do this is inet_addr, which is impure (can do DNS lookups). Is there a pure conversion?

Can you use the SockAddrUnix constructor of SockAddr?
See
http://hackage.haskell.org/package/network-2.2.1.3/docs/Network-Socket.html#...
Tim Perry
(916) 505-3634
On Sun, Feb 2, 2014 at 1:01 PM, harry
I need to convert a numeric IP (such as 1.2.3.4) to a HostAddress for consumption by SockAddrInet. The only function I can find to do this is inet_addr, which is impure (can do DNS lookups). Is there a pure conversion?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Tim Perry
Can you use the SockAddrUnix constructor of SockAddr?
See http://hackage.haskell.org/package/network-2.2.1.3/docs/Network-Socket.html#... What's the input format? All it says is String.

On Thu, Feb 6, 2014 at 5:04 AM, harry
Tim Perry
writes: Can you use the SockAddrUnix constructor of SockAddr?
See http://hackage.haskell.org/package/network-2.2.1.3/docs/Network-Socket.html#...
What's the input format? All it says is String.
You don't want SockAddrUnix. It's for AF_UNIX / AF_LOCAL sockets, which live in the filesystem, and the parameter is the pathname of the socket. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Tim Perry
Can you use the SockAddrUnix constructor of SockAddr?
See http://hackage.haskell.org/package/network-2.2.1.3/docs/Network-Socket.html#... What do I give as the parameter? I can't work out the format (which is just String).

You can use the functionality in Data.IP[1] (from iproutes) to accomplish
this. You'd first use `read` (or a safer version thereof, like
Safe.readMay) to convert a String to an IPv4, and then toHostAddress to
convert that to a HostAddress.
[1] http://hackage.haskell.org/package/iproute-1.2.11/docs/Data-IP.html
On Sun, Feb 2, 2014 at 11:01 PM, harry
I need to convert a numeric IP (such as 1.2.3.4) to a HostAddress for consumption by SockAddrInet. The only function I can find to do this is inet_addr, which is impure (can do DNS lookups). Is there a pure conversion?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (4)
-
Brandon Allbery
-
harry
-
Michael Snoyman
-
Tim Perry