Detecting socket state? - TCP-IP

This is a discussion on Detecting socket state? - TCP-IP ; Hi, Given a socket descriptor, is there a way to detect what state (CLOSE_WAIT, LAST_ACK, TIME_WAIT...) the given socket is in without doing a write or read to the socket? Thanks for your response, Yug...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Detecting socket state?

  1. Detecting socket state?

    Hi,

    Given a socket descriptor, is there a way to detect what state
    (CLOSE_WAIT, LAST_ACK, TIME_WAIT...) the given socket is in without
    doing a write or read to the socket?

    Thanks for your response,
    Yug


  2. Re: Detecting socket state?

    In article <1157525476.740969.252720@b28g2000cwb.googlegroups. com>,
    yug@hotmail.com wrote:

    > Hi,
    >
    > Given a socket descriptor, is there a way to detect what state
    > (CLOSE_WAIT, LAST_ACK, TIME_WAIT...) the given socket is in without
    > doing a write or read to the socket?


    Not in the standard sockets API, AFAIK.

    --
    Barry Margolin, barmar@alum.mit.edu
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
    *** PLEASE don't copy me on replies, I'll read them in the group ***

  3. Re: Detecting socket state?

    In article ,
    Barry Margolin wrote:

    >> Given a socket descriptor, is there a way to detect what state
    >> (CLOSE_WAIT, LAST_ACK, TIME_WAIT...) the given socket is in without
    >> doing a write or read to the socket?

    >
    >Not in the standard sockets API, AFAIK.


    True, but in many UNIX-like flavors you can:

    - use the fstat, lsof, or similar command to convert the process ID
    and socket file descriptor to the address of the TCP pcb

    - use something like `netstat -Aan | grep pcb`


    Vernon Schryver vjs@rhyolite.com

  4. Re: Detecting socket state?

    Barry Margolin wrote:
    > In article <1157525476.740969.252720@b28g2000cwb.googlegroups. com>,
    > yug@hotmail.com wrote:
    >> Given a socket descriptor, is there a way to detect what state
    >> (CLOSE_WAIT, LAST_ACK, TIME_WAIT...) the given socket is in without
    >> doing a write or read to the socket?


    > Not in the standard sockets API, AFAIK.


    Indeed.

    Soooo, what problem is to be solved by knowing the socket state?
    Perhaps there is another solution.

    rick jones
    --
    denial, anger, bargaining, depression, acceptance, rebirth...
    where do you want to be today?
    these opinions are mine, all mine; HP might not want them anyway...
    feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...

  5. Re: Detecting socket state?

    yug@hotmail.com wrote:

    > Hi,
    >
    > Given a socket descriptor, is there a way to detect what state
    > (CLOSE_WAIT, LAST_ACK, TIME_WAIT...) the given socket is in without
    > doing a write or read to the socket?


    Given a socket descriptor that is still valid, it can't *be* in any of
    these states except for CLOSE_WAIT, which can be detected by reading EOF
    (use recvmsg() with the MSG_PEEK flag if you don't want to get any
    data). It can also be LISTENING, which you should already know from your
    application state, or ESTABLISHED which you should also already know
    from your application state, or SYN_SENT which corresponds to the
    interval between the initial connect() and the final successful
    connect()in non-blocking mode, which again you should already know from
    your application state.

+ Reply to Thread