openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rsyslog/8.1903.0-r0/rsyslog-8.1903.0/runtime/net.c
static int* create_udp_socket(uchar* hostname, uchar* pszPort,
                              const int bIsServer, const int rcvbuf,
                              const int sndbuf, const int ipfreebind,
                              char* device)
{
    struct addrinfo hints, *res, *r;
    int error, maxs, *s, *socks;
    rsRetVal localRet;

    assert(!((pszPort == NULL) &&
             (hostname == NULL))); /* one of them must be non-NULL */
    memset(&hints, 0, sizeof(hints));
    if (bIsServer)
        hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
    else
        hints.ai_flags = AI_NUMERICSERV;
    hints.ai_family = glbl.GetDefPFFamily();
    hints.ai_socktype = SOCK_DGRAM;
#if defined(_AIX)
    /* AIXPORT : SOCK_DGRAM has the protocol IPPROTO_UDP
     *           getaddrinfo needs this hint on AIX
     */
    hints.ai_protocol = IPPROTO_UDP;
#endif
    error = getaddrinfo((char*)hostname, (char*)pszPort, &hints, &res);
    if (error)
    {
        LogError(0, NO_ERRCODE, "%s", gai_strerror(error));
        LogError(0, NO_ERRCODE,
                 "UDP message reception disabled due to error logged in last "
                 "message.\n");
        return NULL;
    }

    /* Count max number of sockets we may open */
    for (maxs = 0, r = res; r != NULL; r = r->ai_next, maxs++)
        /* EMPTY */;
    socks = malloc((maxs + 1) * sizeof(int));
    if (socks == NULL)
    {
        LogError(0, RS_RET_OUT_OF_MEMORY,
                 "couldn't allocate memory for UDP "
                 "sockets, suspending UDP message reception");
        freeaddrinfo(res);
        return NULL;
    }

    *socks = 0; /* num of sockets counter at start of array */
    s = socks + 1;
    for (r = res; r != NULL; r = r->ai_next)
    {
        localRet = create_single_udp_socket(s, r, hostname, bIsServer, rcvbuf,
                                            sndbuf, ipfreebind, device);
        if (localRet == RS_RET_OK)
        {
            (*socks)++;
            s++;
        }
    }

    if (res != NULL)
        freeaddrinfo(res);

    if (Debug && *socks != maxs)
        dbgprintf(
            "We could initialize %d UDP listen sockets out of %d we received "
            "- this may or may not be an error indication.\n",
            *socks, maxs);

    if (*socks == 0)
    {
        LogError(0, NO_ERRCODE,
                 "No UDP socket could successfully be initialized, "
                 "some functionality may be disabled.\n");
        /* we do NOT need to close any sockets, because there were none... */
        free(socks);
        return (NULL);
    }

    return (socks);
}
/* creates the UDP listen sockets
 * hostname and/or pszPort may be NULL, but not both!
 * bIsServer indicates if a server socket should be created
 * 1 - server, 0 - client
 * Note: server sockets are created in non-blocking mode, client ones
 * are blocking.
 * param rcvbuf indicates desired rcvbuf size; 0 means OS default,
 * similar for sndbuf.
 */
creates the UDP listen sockets
hostname and/or pszPort may be NULL, but not both.
bIsServer indicates if a server socket should be created
1 - server, 0 - client
Note: server sockets are created in non-blocking mode, client ones
are blocking.
param rcvbuf indicates desired rcvbuf size; 0 means OS default,
similar for sndbuf.
creates the UDP listen sockets hostname and / or pszPort may be NULL but not both . bIsServer indicates if a server socket should be created 1 - server 0 - client Note : server sockets are created in non - blocking mode client ones are blocking . param rcvbuf indicates desired rcvbuf size ; 0 means OS default similar for sndbuf .
static int* create_udp_socket(uchar* hostname, uchar* pszPort,
                              const int bIsServer, const int rcvbuf,
                              const int sndbuf, const int ipfreebind,
                              char* device)
{
    struct addrinfo hints, *res, *r;
    int error, maxs, *s, *socks;
    rsRetVal localRet;
    assert(!((pszPort == NULL) &&
             (hostname == NULL))); 
    memset(&hints, 0, sizeof(hints));
    if (bIsServer)
        hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
    else
        hints.ai_flags = AI_NUMERICSERV;
    hints.ai_family = glbl.GetDefPFFamily();
    hints.ai_socktype = SOCK_DGRAM;
#if defined(_AIX)
    hints.ai_protocol = IPPROTO_UDP;
#endif
    error = getaddrinfo((char*)hostname, (char*)pszPort, &hints, &res);
    if (error)
    {
        LogError(0, NO_ERRCODE, "%s", gai_strerror(error));
        LogError(0, NO_ERRCODE,
                 "UDP message reception disabled due to error logged in last "
                 "message.\n");
        return NULL;
    }
    for (maxs = 0, r = res; r != NULL; r = r->ai_next, maxs++)
        ;
    socks = malloc((maxs + 1) * sizeof(int));
    if (socks == NULL)
    {
        LogError(0, RS_RET_OUT_OF_MEMORY,
                 "couldn't allocate memory for UDP "
                 "sockets, suspending UDP message reception");
        freeaddrinfo(res);
        return NULL;
    }
    *socks = 0; 
    s = socks + 1;
    for (r = res; r != NULL; r = r->ai_next)
    {
        localRet = create_single_udp_socket(s, r, hostname, bIsServer, rcvbuf,
                                            sndbuf, ipfreebind, device);
        if (localRet == RS_RET_OK)
        {
            (*socks)++;
            s++;
        }
    }
    if (res != NULL)
        freeaddrinfo(res);
    if (Debug && *socks != maxs)
        dbgprintf(
            "We could initialize %d UDP listen sockets out of %d we received "
            "- this may or may not be an error indication.\n",
            *socks, maxs);
    if (*socks == 0)
    {
        LogError(0, NO_ERRCODE,
                 "No UDP socket could successfully be initialized, "
                 "some functionality may be disabled.\n");
        free(socks);
        return (NULL);
    }
    return (socks);
}
static int * create_udp_socket ( uchar * hostname , uchar * pszPort , const int bIsServer , const int rcvbuf , const int sndbuf , const int ipfreebind , char * device ) { struct addrinfo hints , * res , * r ; int error , maxs , * s , * socks ; rsRetVal localRet ; assert ( ! ( ( pszPort == NULL ) && ( hostname == NULL ) ) ) ; memset ( & hints , 0 , sizeof ( hints ) ) ; if ( bIsServer ) hints . ai_flags = AI_PASSIVE | AI_NUMERICSERV ; else hints . ai_flags = AI_NUMERICSERV ; hints . ai_family = glbl . GetDefPFFamily ( ) ; hints . ai_socktype = SOCK_DGRAM ; #if defined ( _AIX ) hints . ai_protocol = IPPROTO_UDP ; #endif error = getaddrinfo ( ( char * ) hostname , ( char * ) pszPort , & hints , & res ) ; if ( error ) { LogError ( 0 , NO_ERRCODE , " " , gai_strerror ( error ) ) ; LogError ( 0 , NO_ERRCODE , " " " \n " ) ; return NULL ; } for ( maxs = 0 , r = res ; r != NULL ; r = r -> ai_next , maxs ++ ) ; socks = malloc ( ( maxs + 1 ) * sizeof ( int ) ) ; if ( socks == NULL ) { LogError ( 0 , RS_RET_OUT_OF_MEMORY , " " " " ) ; freeaddrinfo ( res ) ; return NULL ; } * socks = 0 ; s = socks + 1 ; for ( r = res ; r != NULL ; r = r -> ai_next ) { localRet = create_single_udp_socket ( s , r , hostname , bIsServer , rcvbuf , sndbuf , ipfreebind , device ) ; if ( localRet == RS_RET_OK ) { ( * socks ) ++ ; s ++ ; } } if ( res != NULL ) freeaddrinfo ( res ) ; if ( Debug && * socks != maxs ) dbgprintf ( " " " \n " , * socks , maxs ) ; if ( * socks == 0 ) { LogError ( 0 , NO_ERRCODE , " " " \n " ) ; free ( socks ) ; return ( NULL ) ; } return ( socks ) ; }
creates the UDP listen sockets
 hostname and/or pszPort may be NULL, but not both!
creates the UDP listen sockets hostname and / or pszPort may be NULL but not both!
/* one of them must be non-NULL */ /* AIXPORT : SOCK_DGRAM has the protocol IPPROTO_UDP
     *           getaddrinfo needs this hint on AIX
     */ /* Count max number of sockets we may open */ /* EMPTY */ /* num of sockets counter at start of array */ /* we do NOT need to close any sockets, because there were none... */