~ubuntu-branches/ubuntu/hardy/nast/hardy

« back to all changes in this revision

Viewing changes to udp.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2004-02-17 22:14:21 UTC
  • Revision ID: james.westby@ubuntu.com-20040217221421-f1h39tzviblbp2lh
Tags: upstream-0.2.0
ImportĀ upstreamĀ versionĀ 0.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    nast
 
3
 
 
4
    Copyright (C) 2002  Snifth
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
19
 
 
20
*/
 
21
 
 
22
#include "include/nast.h"
 
23
 
 
24
/* handle a udp packet */
 
25
void handle_UDP (u_short d, u_short x, FILE *output, FILE *ldd)
 
26
{
 
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;
 
31
 
 
32
 
 
33
   size_ip = LIBNET_IPV4_H;
 
34
   size_udp = LIBNET_UDP_H;
 
35
   size_buf = 0;
 
36
 
 
37
   ip = (struct libnet_ipv4_hdr *) (packet+offset);
 
38
   udp = (struct libnet_udp_hdr *) (packet+size_ip+offset);
 
39
 
 
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);
 
49
 
 
50
   if(!graph)
 
51
        printf("\n");
 
52
 
 
53
   size_buf = ntohs(ip->ip_len) - size_ip - size_udp;
 
54
   ++line_s;
 
55
   row_s=0;
 
56
   /* there is a payload */
 
57
   if (size_buf)
 
58
     {
 
59
        buf = (char *) (packet + size_ip + size_udp + offset);
 
60
 
 
61
        if (d)
 
62
          {
 
63
             n_print("princ",line_s,row_s,lg,"\n---[ UDP Data ]------------------------------------------------------\n");
 
64
             data_sniffo (buf, size_buf, output);
 
65
          }
 
66
 
 
67
        if (x)
 
68
          {
 
69
             n_print("princ",line_s,row_s,lg,"\n---[ UDP Hex-Ascii Data ]--------------------------------------------");
 
70
             print_ascii_hex (buf, size_buf, output);
 
71
          }
 
72
 
 
73
        /* log data (payload only) */
 
74
        if (ldd)
 
75
          {
 
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");
 
80
 
 
81
             data_sniffo (buf, size_buf, ldd);
 
82
             fprintf(ldd, "\n");
 
83
 
 
84
          }
 
85
     }
 
86
   row_s=0;
 
87
 
 
88
}
 
89