Принимается пакет, ставятся указатели. В tcp неправильные порты показывает. Вот код.
char packet[8096];
struct ether_header *eth;
struct ip *ip;
struct tcphdr *tcp;
/* получения порции данных */
while ( 1 )
{
memset ( &packet, 0, sizeof packet );
read ( sock, packet, sizeof packet );
eth = ( struct ether_header *) &packet[0];
ip = ( struct ip *) (packet + sizeof ( struct ether_header ) );
tcp = ( struct tcphdr *) (packet + sizeof ( struct ether_header ) +
sizeof ( struct ip *) );
if ( ip->ip_p == IPPROTO_TCP )
printf ("%s:%d %s:%d\n", inet_ntoa ( ip->ip_src), ntohs (tcp->source),
inet_ntoa ( ip->ip_dst), ntohs ( tcp->dest ) );
if ( tcp->dest == ntohs (23) ) {
printf ("!!!!!!!!\n");
}
}