embedded IPsec source code documentation


util.h

Go to the documentation of this file.
00001 /*
00002  * embedded IPsec
00003  * Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without modification,
00007  * are permitted provided that the following conditions are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions and the following disclaimer in the documentation
00013  *    and/or other materials provided with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00018  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00020  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00022  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00025  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00026  * OF SUCH DAMAGE.
00027  *
00028  */
00029 
00043 #ifndef __UTIL_H__
00044 #define __UTIL_H__
00045 
00046 #include "ipsec\types.h"
00047 
00052 struct ipsec_ip_addr {
00053   __u32 addr ;
00054 };
00055 
00056 struct ipsec_in_addr {
00057   __u32 s_addr;
00058 };
00059 
00060 #define IPSEC_IP_ADDR_NONE    ((__u32) 0xffffffff)  /* 255.255.255.255 */
00061 #define IPSEC_IP_ADDR_LOCALHOST    ((__u32) 0x7f000001)  /* 127.0.0.1 */
00062 #define IPSEC_IP4_ADDR(ipaddr, a,b,c,d) ipaddr = ipsec_htonl(((__u32)(a & 0xff) << 24) | ((__u32)(b & 0xff) << 16) | \
00063                                                          ((__u32)(c & 0xff) << 8) | (__u32)(d & 0xff))
00064 
00065 #define IPSEC_IP4_ADDR_2(a,b,c,d) ((__u32)(d & 0xff) << 24) | ((__u32)(c & 0xff) << 16) | ((__u32)(b & 0xff) << 8) | (__u32)(a & 0xff)                                                                                                           
00066 #define IPSEC_IP4_ADDR_NET(a,b,c,d) ((__u32)(d & 0xff) << 24) | ((__u32)(c & 0xff) << 16) | ((__u32)(b & 0xff) << 8) | (__u32)(a & 0xff)
00067 
00068 #define IPSEC_HTONL(n) (((__u32)n & 0xff) << 24) | (((__u32)n & 0xff00) << 8) | (((__u32)n & 0xff0000) >> 8) | (((__u32)n & 0xff000000) >> 24)
00069 
00070 #define IPSEC_HTONS(n) (((__u16)n & 0xff) << 8) | (((__u16)n & 0xff00) >> 8)
00071 
00072 
00073 __u32 ipsec_inet_addr(const char *cp) ;
00074 int ipsec_inet_aton(const char *cp, struct ipsec_in_addr *addr) ;
00075 __u8 *ipsec_inet_ntoa(__u32 addr) ;
00076 
00077 #define ipsec_ip_addr_maskcmp(addr1, addr2, mask) ((addr1 & mask) == (addr2 & mask ))
00078 #define ipsec_ip_addr_cmp(addr1, addr2) (addr1 == addr2)
00079 
00080 
00081 
00082 void ipsec_print_ip(ipsec_ip_header *header);
00083 void ipsec_dump_buffer(char *, unsigned char *, int, int);
00084 
00085 ipsec_audit ipsec_check_replay_window(__u32 seq, __u32 lastSeq, __u32 bitField);
00086 ipsec_audit ipsec_update_replay_window(__u32 seq, __u32 *lastSeq, __u32 *bitField);
00087 
00088 
00089 __u16 ipsec_htons(__u16 n);
00090 __u16 ipsec_ntohs(__u16 n);
00091 __u32 ipsec_htonl(__u32 n);
00092 __u32 ipsec_ntohl(__u32 n);
00093 
00094 __u16 ipsec_ip_chksum(void *dataptr, __u16 len);
00095 
00096 #endif
00097 
00098 
00099 

Copyright 2003 by Christian Scheurer and Niklaus Schild