2012-08-05 14:50:00 -04:00
|
|
|
{- network functions
|
|
|
|
-
|
2015-01-21 12:50:09 -04:00
|
|
|
- Copyright 2012 Joey Hess <id@joeyh.name>
|
2012-08-05 14:50:00 -04:00
|
|
|
-
|
2014-05-10 11:01:27 -03:00
|
|
|
- License: BSD-2-clause
|
2012-08-05 14:50:00 -04:00
|
|
|
-}
|
|
|
|
|
2015-05-10 16:38:49 -04:00
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
|
|
|
|
2019-11-21 15:38:06 -04:00
|
|
|
module Utility.Network (getHostname) where
|
2012-08-05 14:50:00 -04:00
|
|
|
|
|
|
|
import Utility.Process
|
|
|
|
import Utility.Exception
|
|
|
|
|
|
|
|
import Control.Applicative
|
2015-05-10 16:19:56 -04:00
|
|
|
import Prelude
|
2012-08-05 14:50:00 -04: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 00:24:19 -04:00
|
|
|
where
|
|
|
|
uname_node = takeWhile (/= '\n') <$> readProcess "uname" ["-n"]
|