~ubuntu-branches/ubuntu/precise/4g8/precise

« back to all changes in this revision

Viewing changes to src/udp_hdr.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2007-03-26 16:19:06 UTC
  • Revision ID: james.westby@ubuntu.com-20070326161906-00xhpx7yaef36u63
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * author: Darren Bounds <dbounds@intrusense.com>
 
3
 * copyright: Copyright (C) 2002 by Darren Bounds
 
4
 * license: This software is under GPL version 2 of license
 
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
 * 4g8 official page at http://.net
 
21
 */
 
22
 
 
23
#include "udp_hdr.h"
 
24
 
 
25
void
 
26
udp_hdr(u_int8_t *packet, u_int16_t diff)
 
27
{
 
28
    struct libnet_udp_hdr *udphdr;
 
29
 
 
30
#ifdef DEBUG
 
31
    fprintf(stdout, "DEBUG: udp_hdr()\n");
 
32
#endif
 
33
 
 
34
    udphdr = (struct libnet_udp_hdr *)(packet + IPV4_H + hdr_len);
 
35
 
 
36
    fprintf(stdout, "UDP header:  Src Port: %d  Dst Port: %d  Len: %d  ",
 
37
        htons(udphdr->uh_sport),
 
38
        htons(udphdr->uh_dport),
 
39
        ntohs(udphdr->uh_ulen)); 
 
40
    
 
41
    fprintf(stdout, "\n");
 
42
 
 
43
    payload_len = ntohs(udphdr->uh_ulen) - 8;
 
44
 
 
45
    if(libnet_build_udp(
 
46
        htons(udphdr->uh_sport),
 
47
        htons(udphdr->uh_dport),
 
48
        ntohs(udphdr->uh_ulen),
 
49
        udphdr->uh_sum,
 
50
        (payload_len == 0) ? NULL : packet + hdr_len + IPV4_H + 8,
 
51
        payload_len, 
 
52
        pkt_d,
 
53
        0) == -1)
 
54
    {
 
55
        fatal_error("Unable to build UDP header: %s", libnet_geterror(pkt_d));
 
56
    }
 
57
 
 
58
    return;
 
59
}
 
60