Incorrect number of bytes returned by getsockopt(socket.SOL_SOCKET, socket.TCP_INFO, buflen)

Roy Smith roy at panix.com
Thu Dec 3 13:42:18 EST 2009


In article 
<5c2800de-a6d2-4863-b423-87ef80d95e6b at k17g2000yqh.googlegroups.com>,
 Ashwin Rao <ashwin.shirvanthe at gmail.com> wrote:

> I computed the size of the tcp_info using the
> following program, which returned 104.
> ---
> #include <stdio.h>
> #include <netinet/tcp.h>
> 
> int main()
> {
>   printf("%d", sizeof(struct tcp_info));
> }

In general, the right way to do stuff like this in Python is to use the 
struct module.  In particular, struct.calcsize() will tell you how long the 
string has to be.  Try that and see if you come up with the same value.



More information about the Python-list mailing list