Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

utils.h

Go to the documentation of this file.
00001 /*
00002  *  utils.h  -  some useful functions (data conversion, ...)
00003  *  
00004  *  EAP-IKEv2
00005  *
00006  *  This library implements ideas of draft-tschofenig-eap-ikev2-10.txt
00007  *  Internet-Draft. Version of the document that this library corresponds
00008  *  to you can find at
00009  *  http://tools.ietf.org/wg/eap/draft-tschofenig-eap-ikev2-10.txt.
00010  *
00011  *  This file is part of libeap-ikev2.
00012  *
00013  *  libeap-ikev2 is free software; you can redistribute it and/or modify
00014  *  it under the terms of the GNU General Public License as published by
00015  *  the Free Software Foundation; either version 2 of the License, or
00016  *  (at your option) any later version.
00017  *
00018  *  libeap-ikev2 is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *  GNU General Public License for more details.
00022  *
00023  *  You should have received a copy of the GNU General Public License
00024  *  along with libeap-ikev2; if not, write to the Free Software
00025  *
00026  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  *  Copyright (C) 2005-2006 Krzysztof Rzecki <krzysztof.rzecki@ccns.pl>      
00029  *  Copyright (C) 2005-2006 Rafal Mijal <rafal.mijal@ccns.pl>                
00030  *  Copyright (C) 2005-2006 Piotr Marnik <piotr.marnik@ccns.pl>              
00031  *  Copyright (C) 2005-2006 Pawel Matejski <pawel.matejski@ccns.pl>          
00032  *  Copyright (C) 2003      Udo Schilcher <udo.schilcher@edu.uni-klu.ac.at>
00033  *  Copyright (C) 2003      Thomas Hambrusch <thambrus@edu.uni-klu.ac.at>          
00034  *
00035  */
00036 
00037 #ifndef __utils_h
00038 #define __utils_h
00039 
00040 #ifdef __cplusplus
00041 extern "C" {
00042 #endif
00043 
00044 #include"common.h"
00045 
00046    
00047 #  define STRINGIFY(x) # x
00048 #  define TOSTRING(x) STRINGIFY(x)
00049  // goodies
00050 // hton? for uint64_t
00051 #define hton64(x) ((uint64_t)((htonl(((uint32_t)((x)>>32)&0xFFFFFFFF))))|((uint64_t)(htonl((uint32_t)((x)&0xFFFFFFFF)))<<32))
00052 #define ntoh64(x) ((uint64_t)((ntohl(((uint32_t)((x)>>32)&0xFFFFFFFF))))|((uint64_t)(ntohl((uint32_t)((x)&0xFFFFFFFF)))<<32))
00053 
00054 // Seperate TypeHF in struct IKEv2Attribute
00055 #define Attribute_GetType(x) ((x)>>1)
00056 #define Attribute_GetHF(x) ((x)&1)
00057 #define Attribute_GetTypeHF(x,y) (((x)<<1)|((y)&1))
00058 
00059 // hex numbers utils
00060 #define hextobin(x) ((x)>'9'?((x)>'Z'?(((x)-0x27)&0x0F):(((x)-0x07)&0x0F)):((x)&0x0F))
00061 #define ishex(x) ((((x)>='0')&&((x)<='9'))||(((x)>='A')&&((x)<='Z'))||(((x)>='a')&&((x)<='z')))
00062 
00063 // function prototypes
00064 
00065 unsigned hex2bytes(char *s, uint8_t **dest);
00066 const char* bin2str(const uint8_t *data,uint32_t len);
00067 void hexalize(uint8_t **data,unsigned *len);
00068 BIGNUM *HexToBignum( const uint8_t *hex, uint32_t len );
00069 uint8_t *Clone( const uint8_t *data, uint32_t len );
00070 void PrintBuffer( unsigned char *buf, unsigned long len );
00071 void PrintBignum(const BIGNUM *a);
00072 uint32_t StringToIP( char *str_ip );
00073 char *IPToString( uint32_t ip );
00074 
00075 #ifdef __cplusplus
00076 }
00077 #endif
00078 
00079 #endif

Project hosted by: SourceForge.net Logo