Brad Fitzpatrick (brad) wrote,
Brad Fitzpatrick

getting unacked packet count, current seq number, etc....

Dear Lazyweb,

I'm interesting in obtaining, in userspace, the number of unacked sequence numbers (and ideally the last/last acked sequence numbers themselves) for a given (TCP) socket.

With Linux I can do this, partially at least (only the unacked count), using getsockopt TCP_INFO and getting back a struct tcp_info from /usr/include/linux/net.h.

Couple questions:

1) is there another way on Linux that might give me more info, short of libpcap'ing my own connection? Ideally I'd like the sequence numbers themselves, not just the unacked count.

2) is there a library to do this portable on different operating systems?

3) if not 2, how do I do this on $YOUR_OS so I can write a library.


P.S. In Perl, it looks like:
sub unacked {
    my ($sock) = @_;
    my $IPPROTO_TCP = 6;
    my $TCP_INFO    = 11;
    my $data =  getsockopt($sock, $IPPROTO_TCP, $TCP_INFO);
    die "no data" unless defined $data;
    # tcpi_unacked (u32) from struct tcp_info
    return unpack("L", substr($data, 24, 4));
Tags: lazyweb, tech, unix
  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.