gethostbyname core dumps - HP UX

This is a discussion on gethostbyname core dumps - HP UX ; The following function dumps with SIGSEGV in gethostbyname the second time it is called. It works the first time. static int resolv_hostname( const char *hname, struct sockaddr_in *sin ){ struct hostent *hostp = NULL; unsigned long addr; addr = inet_addr( ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: gethostbyname core dumps

  1. gethostbyname core dumps

    The following function dumps with SIGSEGV in gethostbyname the second
    time it is called.

    It works the first time.

    static
    int resolv_hostname( const char *hname, struct sockaddr_in *sin ){
    struct hostent *hostp = NULL;
    unsigned long addr;

    addr = inet_addr( hname );
    memcpy( &sin->sin_addr, &addr, sizeof( addr ));
    if (addr != (in_addr_t)-1)
    memcpy( &sin->sin_addr, &addr, sizeof( addr ));
    else {
    hostp = gethostbyname( hname );
    if( hostp == NULL )
    return -1;
    else
    memcpy( &sin->sin_addr, hostp->h_addr_list[0], hostp->h_length );
    }
    return 0;
    }

    The includes in the file containing this function are:

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    The program is dynamically linked with -lxnet and not multithreaded.

    The defines are -D_HPUX_SOURCE -D_POSIX_SOURCE and the compiler is -Aa.

    What am I missing?

    --
    Jim Pennino

    Remove .spam.sux to reply.

  2. Re: gethostbyname core dumps

    On 12月5日, 上午3时15分, j...@specsol.spam.sux.com wrote:
    > The following function dumps with SIGSEGV in gethostbyname the second
    > time it is called.
    >
    > It works the first time.
    >
    > static
    > int resolv_hostname( const char *hname, struct sockaddr_in *sin ){
    > struct hostent *hostp = NULL;
    > unsigned long addr;
    >
    > addr = inet_addr( hname );
    > memcpy( &sin->sin_addr, &addr, sizeof( addr ));
    > if (addr != (in_addr_t)-1)
    > memcpy( &sin->sin_addr, &addr, sizeof( addr ));
    > else {
    > hostp = gethostbyname( hname );
    > if( hostp == NULL )
    > return -1;
    > else
    > memcpy( &sin->sin_addr, hostp->h_addr_list[0], hostp->h_length );
    > }
    > return 0;
    >
    > }
    >
    > The includes in the file containing this function are:
    >
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    > #include
    >
    > The program is dynamically linked with -lxnet and not multithreaded.
    >
    > The defines are -D_HPUX_SOURCE -D_POSIX_SOURCE and the compiler is -Aa.
    >
    > What am I missing?
    >
    > --
    > Jim Pennino
    >
    > Remove .spam.sux to reply.



    Your code works fine on my HP-UX box. I don't think there is any
    problem in your system,
    but the below line of your code does have a little error:

    memcpy( &sin->sin_addr, hostp->h_addr_list[0], hostp->h_length );
    the hostp->h_length is the length of whole address list, not just the
    first one. So if there r
    more than one inet interface related the hname, you get panic. Try to
    change it to:

    memcpy( &sin->sin_addr, hostp->h_addr_list[0], sizeof(sin-
    >sin_addr) );


+ Reply to Thread