00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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
00083
00084
00085
00086
00087
00088
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
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
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
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