Example #1
0
os_int
nw_socketGetDefaultLoopbackAddress(
    os_int sockfd,
    os_sockaddr_storage *sockAddr)
{
    /* Statics for storing the result */
    static os_sockaddr_storage sockAddrFound;
    static os_int hadSuccessBefore = SK_FALSE;
    /* Normal variables for retrieving the result */
    os_int success;
    sk_interfaceInfo *interfaceList;
    os_uint nofInterfaces;
    char addressStr[INET6_ADDRSTRLEN];

    if (!hadSuccessBefore) {
         success = sk_interfaceInfoRetrieveAllLoopback(&interfaceList, &nofInterfaces,
                                              sockfd);
         if (success) {
             sockAddrFound =
                 *(os_sockaddr_storage *)sk_interfaceInfoGetPrimaryAddress(
                                          interfaceList[0]);
             hadSuccessBefore = SK_TRUE;

             /* Diagnostics */
             NW_TRACE_2(Configuration, 2, "Identified loopback enabled interface %s "
                 "having primary address %s",
                 sk_interfaceInfoGetName(interfaceList[0]),
                 os_sockaddrAddressToString((os_sockaddr*) &sockAddrFound,
                                            addressStr,
                                            sizeof(addressStr)));

             /* Free mem used */
             sk_interfaceInfoFreeAll(interfaceList, nofInterfaces);
         }
    }

    if (hadSuccessBefore) {
        *sockAddr = sockAddrFound;
    }

    return hadSuccessBefore;
}
Example #2
0
os_int
nw_socketGetDefaultLoopbackAddress(
    os_int sockfd,
    struct sockaddr_in *sockAddr)
{
    /* Statics for storing the result */
    static struct sockaddr_in sockAddrFound;
    static os_int hadSuccessBefore = SK_FALSE;
    /* Normal variables for retrieving the result */
    os_int success;
    sk_interfaceInfo *interfaceList;
    os_uint nofInterfaces;
    
    if (!hadSuccessBefore) {
         success = sk_interfaceInfoRetrieveAllLoopback(&interfaceList, &nofInterfaces, 
                                              sockfd);
         if (success) {
             sockAddrFound = 
                 *(struct sockaddr_in *)sk_interfaceInfoGetPrimaryAddress(
                                          interfaceList[0]);
             hadSuccessBefore = SK_TRUE;
             
             /* Diagnostics */
             NW_TRACE_2(Configuration, 2, "Identified loopback enabled interface %s "
                 "having primary address %s",
                 sk_interfaceInfoGetName(interfaceList[0]),
                 inet_ntoa(sockAddrFound.sin_addr));
                                       
             /* Free mem used */
             sk_interfaceInfoFreeAll(interfaceList, nofInterfaces);
         }
    }

    if (hadSuccessBefore) {
        *sockAddr = sockAddrFound;
    }
    
    return hadSuccessBefore;
}