FWIW, on CentOS 4.7, the ctypes version works fine, but the struct
version fails, because len(tcp_info) is only 100 bytes while
struct.calcsize('B...L') is 104.

However, if the format is changed to '7B23L', i.e. one 'L' shorter,
the struct version works and returns to same result as the ctypes
version.

/Jean


On Dec 19, 4:45 pm, plz <u...@compgroups.net/> wrote:
> hi
> many thanks for helping me
> i also tried to manipulate it last night
> here is my code...
>
> import socket
> import struct
>
> sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> tcp_info = sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO, 
> struct.calcsize('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL'))
> print struct.unpack('BBBBBBBLLLLLLLLLLLLLLLLLLLLLLLL', tcp_info)
>
> the result of struct.unpack of tcp_info is following
> in /usr/include/linux/tcp.h
> used Linux Redhat and Python 2.7
>
> anyway your code is very useful
> Thxs again ;)

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to