4
Copyright (C) 2002 Snifth
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include "include/nast.h"
24
/* handle a udp packet */
25
void handle_UDP (u_short d, u_short x, FILE *output, FILE *ldd)
27
struct libnet_ipv4_hdr *ip;
28
struct libnet_udp_hdr *udp;
29
struct servent *service;
30
u_short size_buf, size_ip, size_udp;
33
size_ip = LIBNET_IPV4_H;
34
size_udp = LIBNET_UDP_H;
37
ip = (struct libnet_ipv4_hdr *) (packet+offset);
38
udp = (struct libnet_udp_hdr *) (packet+size_ip+offset);
40
service = getservbyport (htons(ntohs(udp->uh_sport)), "udp");
41
n_print("princ",line_s,row_s,lg,"\n---[ UDP ]-----------------------------------------------------------\n");
42
n_print("princ",line_s=line_s+2,row_s,lg,"%s:%d(%s)", inet_ntoa (ip->ip_src), ntohs(udp->uh_sport), (service) ? service->s_name : "unknown");
43
service = getservbyport(htons(ntohs(udp->uh_dport)), "udp");
44
n_print("princ",line_s,28,lg," -> ");
45
n_print("princ",line_s,33,lg,"%s:%d(%s)\n", inet_ntoa(ip->ip_dst), ntohs(udp->uh_dport), (service) ? service->s_name : "unknown");
46
n_print("princ",++line_s,row_s,lg,"Version: %d\t Total Lenght: %d\t", ip->ip_v, ntohs(ip->ip_len));
47
n_print("princ",line_s,39,lg, "TTL: %d\n", ip->ip_ttl);
48
n_print("princ",++line_s,0,lg,"Packet Number: %d",npkt);
53
size_buf = ntohs(ip->ip_len) - size_ip - size_udp;
56
/* there is a payload */
59
buf = (char *) (packet + size_ip + size_udp + offset);
63
n_print("princ",line_s,row_s,lg,"\n---[ UDP Data ]------------------------------------------------------\n");
64
data_sniffo (buf, size_buf, output);
69
n_print("princ",line_s,row_s,lg,"\n---[ UDP Hex-Ascii Data ]--------------------------------------------");
70
print_ascii_hex (buf, size_buf, output);
73
/* log data (payload only) */
76
service = getservbyport (htons(ntohs(udp->uh_sport)), "udp");
77
fprintf(ldd, "%s:%d(%s) -> ", inet_ntoa (ip->ip_src), ntohs(udp->uh_sport), (service) ? service->s_name : "unknown");
78
service = getservbyport(htons(ntohs(udp->uh_dport)), "udp");
79
fprintf(ldd, "%s:%d(%s) UDP\n", inet_ntoa(ip->ip_dst), ntohs(udp->uh_dport), (service) ? service->s_name : "unknown");
81
data_sniffo (buf, size_buf, ldd);