Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

cabal_os_bsd.cpp

00001 /*
00002    CABAL PROTOCOL
00003    CAched BAlanced LAN
00004 
00005    OS specific cabal extensions (UNIX BSDlike/GNU sockets)
00006 
00007    $Id: cabal_os_bsd.cpp,v 1.2 2004/03/15 04:22:34 jonnymind Exp $
00008 ---------------------------------------------
00009    Begin      :
00010    Author     : Giancarlo Niccolai
00011 
00012    Last modified because:
00013 
00014 */
00015 
00016 #include <cabal_os.h>
00017 
00018 namespace Cabal
00019 {
00020 
00021 
00022 bool Net_BSD::getHostList(
00023    const std::string &name,
00024    std::string &real_name,
00025    char *real_ip,
00026    NetAddr *other_addrs, int na_count )
00027 {
00028    int iError;
00029    int i;
00030    struct hostent ret, *result;
00031    char buffer[512];
00032 
00033    if ( gethostbyname_r (
00034          name.c_str(),
00035          &ret,
00036          buffer, 512,
00037          &result,
00038          &iError) ==0)
00039    {
00040       char **ret_ips = ret.h_addr_list;
00041 
00042       i = 0;
00043       while ( *ret_ips && i < na_count )
00044       {
00045          memcpy( other_addrs+i, *ret_ips, sizeof( NetAddr ) );
00046          ret_ips++;
00047          i++;
00048       }
00049       
00050       inet_ntop( AF_INET, other_addrs + 0, real_ip, CABAL_MAX_IP_SIZE );
00051       
00052       if( i < na_count ) 
00053          other_addrs[i] = CABAL_INVALID_ADDR;
00054          
00055       real_name = ret.h_name;
00056       return true;
00057    }
00058 
00059    return false;
00060 }
00061 
00062 
00063 }
00064 
00065 /* End of cabal_os_bsd.cpp */

Generated on Sat Apr 10 17:41:48 2004 for Cabal by doxygen 1.3.5