]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/capture/cap_debug/ip.c
Merge branch 'stg-2.409-radius'
[stg.git] / projects / stargazer / plugins / capture / cap_debug / ip.c
1 /* $Id: ip.c,v 1.1 2005/12/12 18:14:22 nobunaga Exp $ 
2
3 Copyright (C) 2002 Marc Kirchner <kirchner@stud.fh-heilbronn.de>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 #include "libpal.h"
21
22 int
23 pkt_ip_header(struct packet *pkt,
24                 unsigned int iphdr_len,
25                 unsigned int version,
26                 unsigned char tos,
27                 unsigned short int total_len,
28                 unsigned short int id,
29                 unsigned short int frag_off,
30                 unsigned char ttl,
31                 unsigned char protocol,
32                 unsigned short int cksum,
33                 unsigned int saddr,
34                 unsigned int daddr)
35 {
36         struct ip *ip;
37
38         if (!pkt)
39                 return EPKTINVALPTR;
40         
41         ip = (struct ip *) pkt->pkt_ptr;
42
43         ip->ip_hl = iphdr_len;
44         ip->ip_v = version;
45         ip->ip_tos = tos;
46         ip->ip_len = htons(total_len);
47         ip->ip_id = htons(id);
48         ip->ip_off = htons(frag_off);
49         ip->ip_ttl = ttl;
50         ip->ip_p = protocol;
51         ip->ip_src.s_addr = saddr;
52         ip->ip_dst.s_addr = daddr;
53
54         return 0;
55 }