| iMatix home page
| << | < | > | >>
SFL Logo SFL
Version 2.11

 

get_host_file

#include "sflsock.h"
char *
get_host_file (void)

Synopsis

returns the full path name of the host lookup file, if provided by the OS, and found. If not found, returns "hosts". The returned string is held in a static area of memory that may be overwritten by each call.

Source Code - (sflsock.c)

{
#if (defined (WIN32))
    static OSVERSIONINFO
        version_info;
    static char
        name [LINE_MAX + 1];

    strclr (name);
    GetWindowsDirectory (name, LINE_MAX);
    version_info.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
    if (GetVersionEx (&version_info))
        /*  On Windows NT the hosts file is well-hidden; on Win95 it's
         *  more visible                                                     */
        if (version_info.dwPlatformId == VER_PLATFORM_WIN32_NT)
            strcat (name, "\\system32\\drivers\\etc\\hosts");
        else
            strcat (name, "\\hosts");
    return (name);

#elif (defined (__UNIX__))
    return ("/etc/hosts");

#elif (defined (__VMS__))
    return ("/etc/hosts");              /*  Not correct -- needs more work   */

#elif (defined (__OS2__))
    /*  Under OS/2 the hosts information is stored in the "hosts" file which
     *  is in the directory pointed at by the %ETC% environment variable.
     *  If that environment variable is not set, then TCP/IP support is not
     *  properly installed.  In that instance we return "/mptn/etc/hosts"
     *  (the likely value on OS/2 Warp 3 Connect and OS/2 Warp 4) and hope
     *  for the best.
     */

    /*  A static array is used only because the other versions use a static
     *  array.  If the resulting file name will not fit in the space allowed
     *  then "/mtpn/etc/hosts" is used as before.
     */
    static char
        name [LINE_MAX + 1];
    char
        *etcenv = NULL;

    etcenv = getenv ("ETC");
    if (etcenv != NULL && strlen (etcenv) < (LINE_MAX - 6))
      { /*  We've already checked it will all fit.                           */
        strcpy (name, etcenv);
        strcat (name, "/hosts");
        return (name);
      }
    else
        return ("/mptn/etc/hosts");

#else
    return ("hosts");
#endif
}

| << | < | > | >> iMatix Copyright © 1996-2000 iMatix Corporation