2012-08-05 18:50:00 +00:00
|
|
|
{- network functions
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-08-05 18:50:00 +00:00
|
|
|
-
|
2014-05-10 14:01:27 +00:00
|
|
|
- License: BSD-2-clause
|
2012-08-05 18:50:00 +00:00
|
|
|
-}
|
|
|
|
|
2015-05-10 20:38:49 +00:00
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
|
|
|
|
2012-08-05 18:50:00 +00:00
|
|
|
module Utility.Network where
|
|
|
|
|
|
|
|
import Utility.Process
|
|
|
|
import Utility.Exception
|
|
|
|
|
|
|
|
import Control.Applicative
|
2015-05-10 20:19:56 +00:00
|
|
|
import Prelude
|
2012-08-05 18:50:00 +00:00
|
|
|
|
|
|
|
{- Haskell lacks uname(2) bindings, except in the
|
|
|
|
- Bindings.Uname addon. Rather than depend on that,
|
|
|
|
- use uname -n when available. -}
|
|
|
|
getHostname :: IO (Maybe String)
|
|
|
|
getHostname = catchMaybeIO uname_node
|
2012-12-13 04:24:19 +00:00
|
|
|
where
|
|
|
|
uname_node = takeWhile (/= '\n') <$> readProcess "uname" ["-n"]
|