hostname-1.0/0000755000000000000000000000000011370642124011356 5ustar0000000000000000hostname-1.0/hostname.cabal0000644000000000000000000000145511370642124014165 0ustar0000000000000000Name: hostname Version: 1.0 Cabal-Version: >= 1.2 Category: Network Synopsis: A very simple package providing a cross-platform means of determining the hostname License: BSD3 License-File: LICENSE Author: Max Bolingbroke Maintainer: Max Bolingbroke Build-Type: Simple Library Exposed-Modules: Network.HostName Build-Depends: base >= 3 && < 5 Extensions: CPP, ForeignFunctionInterface if os(windows) Build-Depends: Win32 >= 2.0 Cpp-Options: -DWINDOWS Extra-Libraries: "kernel32" hostname-1.0/LICENSE0000644000000000000000000000276611370642124012376 0ustar0000000000000000Copyright (c) 2008, Maximilian Bolingbroke All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Maximilian Bolingbroke nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.hostname-1.0/Setup.lhs0000644000000000000000000000011511370642124013163 0ustar0000000000000000#! /usr/bin/env runhaskell > import Distribution.Simple > main = defaultMainhostname-1.0/Network/0000755000000000000000000000000011370642124013007 5ustar0000000000000000hostname-1.0/Network/HostName.hs0000644000000000000000000000262511370642124015066 0ustar0000000000000000module Network.HostName ( HostName, getHostName ) where import Foreign.C.Error import Foreign.C.String import Foreign.C.Types import Foreign.Marshal.Array #ifdef WINDOWS import Foreign.Marshal.Utils import Foreign.Ptr import Foreign.Storable import System.Win32.Types foreign import stdcall unsafe "windows.h GetComputerNameExW" getComputerNameEx :: COMPUTER_NAME_FORMAT -> LPTSTR -> LPDWORD -> IO BOOL type COMPUTER_NAME_FORMAT = CInt computerNamePhysicalDnsHostname :: COMPUTER_NAME_FORMAT computerNamePhysicalDnsHostname = 5 getHostName :: IO HostName getHostName = with 0 $ \p_charcount -> do -- On the first run, determine the character count and ignore any error we get _ <- getComputerNameEx computerNamePhysicalDnsHostname nullPtr p_charcount charcount <- peek p_charcount -- The second time around, use the correct character count to retrieve the data withTString (replicate (fromIntegral charcount) ' ') $ \name -> do failIfFalse_ "GetComputerNameExW" $ getComputerNameEx computerNamePhysicalDnsHostname name p_charcount peekTString name #else foreign import ccall unsafe "gethostname" gethostname :: CString -> CSize -> IO CInt getHostName :: IO HostName getHostName = allocaArray0 size $ \cstr -> do throwErrnoIfMinus1_ "getHostName" $ gethostname cstr (fromIntegral size) peekCString cstr where size = 256 #endif type HostName = String