Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

ipobj.h

Go to the documentation of this file.
00001 /*
00002 
00003         ipobj.h
00004 
00005         IP address encapsulation interface
00006 
00007         This module provides encapsulation of single IP ADDRESSes as objects,
00008         and collections of IP ADDRESSes as objects
00009 
00010         Interaction with this library should be done in HOST byte order.
00011 
00012 */
00013 #ifndef IPOBJ_SNORT
00014 #define IPOBJ_SNORT
00015 
00016 #include <stdlib.h>
00017 #include <stdio.h>
00018 #include <string.h>
00019 
00020 #include "sflsq.h"
00021 
00022 #ifdef WIN32
00023 #define snprintf _snprintf
00024 #endif
00025 
00026 
00027 enum {
00028   NOFAMILY,
00029   IPV4_FAMILY,
00030   IPV6_FAMILY,
00031 };
00032 
00033 enum {
00034   IPV4_LEN=4,
00035   IPV6_LEN=16,
00036 };
00037 
00038 typedef struct {
00039 
00040   int family;
00041   unsigned char ip[1];
00042 
00043 }IPADDRESS ;
00044 
00045 
00046 typedef struct {
00047 
00048   int family;
00049   unsigned char ip[IPV4_LEN];
00050 
00051 }IPADDRESS4 ;
00052 
00053 typedef struct {
00054 
00055   int family;
00056   unsigned char ip[IPV6_LEN];
00057 
00058 }IPADDRESS6 ;
00059 
00060 typedef struct {
00061    unsigned mask;
00062    unsigned ip;
00063    int      notflag;
00064 }CIDRBLOCK;
00065 
00066 
00067 typedef struct {
00068    unsigned short mask[8];
00069    unsigned short ip[8];
00070    int            notflag;
00071 }CIDRBLOCK6;
00072 
00073 typedef struct {
00074 
00075   int       family;
00076   SF_LIST   cidr_list;
00077 
00078 }IPSET;
00079 
00080 /*
00081 
00082         IP ADDRESS OBJECT
00083         
00084         This interface is meant to hide the differences between ipv4
00085         and ipv6.  The assumption is that when we get a raw address we
00086         can stuff it into a generic IPADDRESS.  When we need to test
00087         an IPADDRESS against a raw address we know the family opf the
00088         raw address.  It's either ipv4 or ipv6.
00089 
00090 */
00091 int ip_familysize( int family );
00092 
00093 int ip4_sprintx( char * s, int slen, void * ip4 );
00094 int ip6_sprintx( char * s, int slen, void * ip6 );
00095 
00096 
00097 IPADDRESS * ip_new   ( int family );
00098 void        ip_free  ( IPADDRESS * p );
00099 int         ip_family( IPADDRESS * p );
00100 int         ip_size  ( IPADDRESS * p );
00101 int         ip_set   ( IPADDRESS * ia, void * ip, int family );
00102 int         ip_get   ( IPADDRESS * ia, void * ip, int family );
00103 int         ip_equal ( IPADDRESS * ia, void * ip, int family );
00104 int         ip_eq    ( IPADDRESS * ia, IPADDRESS * ib );
00105 int         ip_sprint( char * s, int slen, IPADDRESS * p );
00106 int         ip_fprint( FILE * fp, IPADDRESS * p );
00107 
00108 
00109 
00110 /*
00111 
00112   IP ADDRESS SET OBJECTS
00113 
00114    
00115    Snort Accepts:
00116 
00117         IP-Address              192.168.1.1
00118         IP-Address/MaskBits     192.168.1.0/24
00119         IP-Address/Mask         192.168.1.0/255.255.255.0
00120 
00121    
00122    These can all be handled via the CIDR block notation : IP/MaskBits
00123 
00124    We use collections (lists) of cidr blocks to represent address blocks
00125    and indivdual addresses.    
00126 
00127    For a single IPAddress the implied Mask is 32 bits,or
00128    255.255.255.255, or 0xffffffff, or -1.
00129 */
00130 IPSET * ipset_new     ( int family );
00131 IPSET * ipset_copy    ( IPSET * ipset );
00132 int     ipset_family  ( IPSET * ipset );
00133 void    ipset_free    ( IPSET * ipset );
00134 int     ipset_add     ( IPSET * ipset, void *ip, void *mask, int notflag,int family );
00135 int     ipset_contains( IPSET * ipset, void * ip, int family );
00136 int     ipset_print   ( IPSET * ipset );
00137 
00138 
00139 /* helper functions -- all the sets work in host order   
00140 */
00141 int      ip4_parse(char * ipstr, int network_order, int * not_flag,
00142                    unsigned * host, unsigned * mask);
00143 
00144 int      ip4_setparse(IPSET * ipset, char *ipstr);
00145 
00146 #endif

Generated on Sun May 14 14:51:18 2006 by  doxygen 1.4.2