Synesis Software STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ...

pantheios/util/system/hostname.h

Go to the documentation of this file.
00001 /* /////////////////////////////////////////////////////////////////////////
00002  * File:        pantheios/util/system/hostname.h
00003  *
00004  * Purpose:     Functions for eliciting host name
00005  *
00006  * Created:     14th April 2008
00007  * Updated:     10th August 2009
00008  *
00009  * Home:        http://www.pantheios.org/
00010  *
00011  * Copyright (c) 2008-2009, Matthew Wilson and Synesis Software
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are
00016  * met:
00017  *
00018  * - Redistributions of source code must retain the above copyright notice,
00019  *   this list of conditions and the following disclaimer.
00020  * - Redistributions in binary form must reproduce the above copyright
00021  *   notice, this list of conditions and the following disclaimer in the
00022  *   documentation and/or other materials provided with the distribution.
00023  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
00024  *   names of any contributors may be used to endorse or promote products
00025  *   derived from this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
00028  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00029  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00031  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00036  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038  *
00039  * ////////////////////////////////////////////////////////////////////// */
00040 
00041 
00047 #ifndef PANTHEIOS_INCL_PANTHEIOS_SYSTEM_H_HOSTNAME
00048 #define PANTHEIOS_INCL_PANTHEIOS_SYSTEM_H_HOSTNAME
00049 
00050 /* /////////////////////////////////////////////////////////////////////////
00051  * Version information
00052  */
00053 
00054 #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
00055 # define PANTHEIOS_VER_PANTHEIOS_SYSTEM_H_HOSTNAME_MAJOR    1
00056 # define PANTHEIOS_VER_PANTHEIOS_SYSTEM_H_HOSTNAME_MINOR    2
00057 # define PANTHEIOS_VER_PANTHEIOS_SYSTEM_H_HOSTNAME_REVISION 1
00058 # define PANTHEIOS_VER_PANTHEIOS_SYSTEM_H_HOSTNAME_EDIT     12
00059 #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
00060 
00061 /* /////////////////////////////////////////////////////////////////////////
00062  * Includes
00063  */
00064 
00065 #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
00066 # include <pantheios/pantheios.h>
00067 #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
00068 #ifndef PANTHEIOS_INCL_PANTHEIOS_QUALITY_H_CONTRACT
00069 # include <pantheios/quality/contract.h>
00070 #endif /* !PANTHEIOS_INCL_PANTHEIOS_QUALITY_H_CONTRACT */
00071 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00072 # include <stlsoft/stlsoft.h>
00073 #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */
00074 #ifdef __cplusplus
00075 # if defined(STLSOFT_COMPILER_IS_MSVC) && \
00076      _MSC_VER < 1300
00077 #  include <pantheios/util/memory/auto_buffer_selector.hpp>
00078 # endif /* VC6 */
00079 # ifndef STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER
00080 #  include <stlsoft/memory/auto_buffer.hpp>
00081 # endif /* !STLSOFT_INCL_STLSOFT_MEMORY_HPP_AUTO_BUFFER */
00082 #endif /* __cplusplus */
00083 
00084 /* /////////////////////////////////////////////////////////////////////////
00085  * Namespace
00086  */
00087 
00088 #if !defined(PANTHEIOS_NO_NAMESPACE)
00089 namespace pantheios
00090 {
00091 #endif /* !PANTHEIOS_NO_NAMESPACE */
00092 
00093 /* /////////////////////////////////////////////////////////////////////////
00094  * API
00095  */
00096 
00122 PANTHEIOS_CALL(size_t) pantheios_getHostName(pan_char_t* buffer, size_t cchBuffer);
00123 
00124 #if !defined(PANTHEIOS_NO_NAMESPACE)
00125 
00129 inline size_t getHostName(pan_char_t* buffer, size_t cchBuffer)
00130 {
00131     return pantheios_getHostName(buffer, cchBuffer);
00132 }
00133 #endif /* !PANTHEIOS_NO_NAMESPACE */
00134 
00135 #ifdef __cplusplus
00136 
00146 #if defined(STLSOFT_COMPILER_IS_MSVC) && \
00147     _MSC_VER < 1300
00148 template <typename B>
00149 inline size_t getHostName(B& buffer)
00150 #else /* ? compiler */
00151 template <size_t N, typename A>
00152 #  ifdef STLSOFT_AUTO_BUFFER_NEW_FORM
00153 inline size_t getHostName(stlsoft::auto_buffer<pan_char_t, N, A>& buffer)
00154 #  else /* ? STLSOFT_AUTO_BUFFER_NEW_FORM */
00155 inline size_t getHostName(stlsoft::auto_buffer<pan_char_t, A, N>& buffer)
00156 #  endif /* STLSOFT_AUTO_BUFFER_NEW_FORM */
00157 #endif /* compiler */
00158 {
00159     PANTHEIOS_CONTRACT_ENFORCE_PRECONDITION_PARAMS_API(0 != buffer.size(), "buffer must not be empty");
00160 
00161     for(;;)
00162     {
00163         size_t cch = pantheios_getHostName(&buffer[0], buffer.size());
00164 
00165         if(buffer.size() == cch)
00166         {
00167             if(!buffer.resize(2 * buffer.size()))
00168             {
00169                 return 0;
00170             }
00171         }
00172         else
00173         {
00174             buffer.resize(cch);
00175 
00176             break;
00177         }
00178     }
00179 
00180     return buffer.size();
00181 }
00182 
00183 #endif /* __cplusplus */
00184 
00185 /* /////////////////////////////////////////////////////////////////////////
00186  * Namespace
00187  */
00188 
00189 #if !defined(PANTHEIOS_NO_NAMESPACE)
00190 } /* namespace pantheios */
00191 #endif /* !PANTHEIOS_NO_NAMESPACE */
00192 
00193 /* ////////////////////////////////////////////////////////////////////// */
00194 
00195 #endif /* !PANTHEIOS_INCL_PANTHEIOS_SYSTEM_H_HOSTNAME */
00196 
00197 /* ///////////////////////////// end of file //////////////////////////// */

pantheios Library documentation © Matthew Wilson & Synesis Software, 2006-2011 SourceForge.net Logo