[lkml]   [1997]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Subjectinteresting behavior.. this right ?

    Hi, I'm no expert at this, and I don't know what the correct behavior is,
    but this seems a little odd.

    If you call a bind before connect(), and you bind to an address that has
    no route to the host your trying to reach, the connect() will hang. I set
    up an alarm to try to get around this, but it only seems to work once,
    after that, the signal won't break it out of the connect call. (I even
    had to kill -9 it once..)

    Here's an example of what I'm talking about. It always hangs on the
    connect call.. shouldn't it return an error ?

    Like I say, I don't know the proper behavior but I just thought I'd check.
    :) If anyone knows how to work around this, I'd be very greatful.



    #include <stdio.h>
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>

    int main(void)
    struct sockaddr_in addr;
    struct sockaddr_in local_addr;
    int sock;

    sock = socket(AF_INET, SOCK_STREAM, 0);

    /* bind to localhost */
    local_addr.sin_family = AF_INET;
    local_addr.sin_port = htons(0);
    inet_aton("", &local_addr.sin_addr);

    if (bind(sock, (struct sockaddr *) &local_addr, sizeof(struct sockaddr_in)) < 0)

    /* connect to remote host (sunsite's IP) */
    addr.sin_family = AF_INET;
    addr.sin_port = htons(23);
    inet_aton("", &addr.sin_addr);


    if (connect(sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) < 0)


     \ /
      Last update: 2005-03-22 13:39    [W:0.018 / U:19.004 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site