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

« back to all changes in this revision

Viewing changes to src/ipv4_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 "ipv4_hdr.h"
 
24
 
 
25
void
 
26
ipv4_hdr(struct libnet_ipv4_hdr *iphdr, u_int16_t prv_opts)
 
27
{
 
28
    u_int8_t *s_addr, *d_addr;
 
29
 
 
30
#ifdef DEBUG
 
31
    fprintf(stdout, "DEBUG: ipv4_hdr()\n");
 
32
#endif
 
33
 
 
34
    s_addr = malloc(sizeof(u_int8_t *));
 
35
    d_addr = malloc(sizeof(u_int8_t *));
 
36
 
 
37
    s_addr = libnet_addr2name4(iphdr->ip_src.s_addr, 0);
 
38
    d_addr = libnet_addr2name4(iphdr->ip_dst.s_addr, 0);
 
39
 
 
40
    fprintf(stdout, "IP header:   Src Address: %s  Dst Address: %s\n", s_addr, d_addr); 
 
41
 
 
42
    fprintf(stdout, "\t     TTL: %d  ID: %d  TOS: 0x%X  Len: %d  ", 
 
43
        iphdr->ip_ttl, 
 
44
        ntohs(iphdr->ip_id), 
 
45
        iphdr->ip_tos, 
 
46
        ntohs(iphdr->ip_len));
 
47
 
 
48
    if(ntohs(iphdr->ip_off) & IP_DF)
 
49
        fprintf(stdout, "(DF)  ");
 
50
 
 
51
    fprintf(stdout, "\n");
 
52
 
 
53
    if(libnet_build_ipv4(
 
54
        ntohs(iphdr->ip_len) - prv_opts,
 
55
        iphdr->ip_tos,
 
56
        ntohs(iphdr->ip_id),
 
57
        ntohs(iphdr->ip_off),
 
58
        iphdr->ip_ttl,
 
59
        iphdr->ip_p,
 
60
        0,
 
61
        iphdr->ip_src.s_addr,
 
62
        iphdr->ip_dst.s_addr,
 
63
        NULL,
 
64
        0,
 
65
        pkt_d,
 
66
        0) == -1)
 
67
    {
 
68
        fatal_error("Unable to build IP header: %s", libnet_geterror(pkt_d));
 
69
    }
 
70
 
 
71
    return;
 
72
}