1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include "include/nast.h"
void handle_TCP (u_short d, u_short x, FILE *output, FILE *ldd)
{
struct libnet_ipv4_hdr *ip;
struct libnet_tcp_hdr *tcp;
struct servent *service;
u_char flags;
u_short size_ip, size_tcp, size_buf;
size_ip = LIBNET_IPV4_H;
size_buf = 0;
buf = NULL;
ip = (struct libnet_ipv4_hdr *) (packet+offset);
tcp = (struct libnet_tcp_hdr *) (packet+size_ip+offset);
size_tcp = (tcp->th_off) * 4;
n_print("princ",line_s,row_s,lg,"\n---[ TCP ]-----------------------------------------------------------\n");
service = getservbyport(htons(ntohs(tcp->th_sport)), "tcp");
n_print("princ",line_s=line_s+2,row_s,lg,"%s:%d(%s)",inet_ntoa(ip->ip_src),ntohs(tcp->th_sport),(service) ? service->s_name : "unknown");
service = getservbyport(htons(ntohs(tcp->th_dport)), "tcp");
n_print("princ",line_s,28,lg," -> ");
n_print("princ",line_s,33,lg,"%s:%d(%s)\n",inet_ntoa(ip->ip_dst),ntohs(tcp->th_dport),(service) ? service->s_name : "unknown");
n_print("princ",++line_s,row_s,lg,"TTL: %d \t", ip->ip_ttl);
n_print("princ",line_s,10,lg,"Window: %d\t", ntohs(tcp->th_win));
n_print("princ",line_s,25,lg,"Version: %d\t", ip->ip_v);
n_print("princ",line_s,39,lg,"Length: %d\n", ntohs(ip->ip_len));
n_print("princ",++line_s,row_s,lg,"FLAGS: ");
flags = tcp->th_flags;
row_s = 8;
if (flags & TH_FIN)
n_print("princ",line_s,++row_s,lg,"F");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & TH_SYN)
n_print("princ",line_s,++row_s,lg,"S");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & TH_RST)
n_print("princ",line_s,++row_s,lg,"R");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & TH_PUSH)
n_print("princ",line_s,++row_s,lg,"P");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & TH_ACK)
n_print("princ",line_s,++row_s,lg,"A");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & TH_URG)
n_print("princ",line_s,++row_s,lg,"U");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & 0x80)
n_print("princ",line_s,++row_s,lg,"U");
else
n_print("princ",line_s,++row_s,lg,"-");
if (flags & 0x40)
n_print("princ",line_s,++row_s,lg,"E");
n_print("princ",line_s,16,lg,"\tSEQ: %u - ACK: %u\n", ntohl(tcp->th_seq),ntohl(tcp->th_ack));
n_print("princ",++line_s,0,lg,"Packet Number: %d",npkt);
if(!graph)
printf("\n");
row_s=0;
++line_s;
size_buf = ntohs(ip->ip_len) - size_ip - size_tcp;
if (size_buf)
{
buf = (char *) (packet + offset + size_ip + size_tcp);
if (d)
{
n_print("princ",line_s,row_s,lg,"\n---[ TCP Data ]------------------------------------------------------\n");
data_sniffo (buf, size_buf, output);
}
if (x)
{
n_print("princ",line_s,row_s,lg,"\n---[ TCP Hex-Ascii Data ]--------------------------------------------");
print_ascii_hex (buf, size_buf, output);
}
if (ldd)
{
service = getservbyport(htons(ntohs(tcp->th_sport)), "tcp");
fprintf(ldd, "%s:%d(%s) -> ",inet_ntoa(ip->ip_src),ntohs(tcp->th_sport),(service) ? service->s_name : "unknown");
service = getservbyport(htons(ntohs(tcp->th_dport)), "tcp");
fprintf(ldd, "%s:%d(%s) TCP\n",inet_ntoa(ip->ip_dst),ntohs(tcp->th_dport),(service) ? service->s_name : "unknown");
data_sniffo (buf, size_buf, ldd);
fprintf(ldd, "\n");
}
}
row_s = 0;
}
|