Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
check_ipcheck.c File Reference
#include "gwlib/gwlib.h"

Go to the source code of this file.

Functions

int main (void)
 

Function Documentation

int main ( void  )

Definition at line 67 of file check_ipcheck.c.

References GW_INFO, gwlib_init(), gwlib_shutdown(), is_allowed_ip(), log_set_output_level(), octstr_get_cstr, octstr_imm(), and panic.

68 {
69  Octstr *ip;
70  Octstr *allowed;
71  Octstr *denied;
72  int result;
73  int i;
74  static struct {
75  char *allowed;
76  char *denied;
77  char *ip;
78  int should_be_allowed;
79  } tab[] = {
80  { "127.0.0.1", "", "127.0.0.1", 1 },
81  { "127.0.0.1", "", "127.0.0.2", 1 },
82  { "127.0.0.1", "*.*.*.*", "127.0.0.1", 1 },
83  { "127.0.0.1", "*.*.*.*", "1.2.3.4", 0 },
84  { "127.0.0.1", "127.0.0.*", "1.2.3.4", 1 },
85  { "127.0.0.1", "127.0.0.*", "127.0.0.2", 0 },
86  };
87 
88  gwlib_init();
90 
91  for (i = 0; (size_t) i < sizeof(tab) / sizeof(tab[0]); ++i) {
92  allowed = octstr_imm(tab[i].allowed);
93  denied = octstr_imm(tab[i].denied);
94  ip = octstr_imm(tab[i].ip);
95  result = is_allowed_ip(allowed, denied, ip);
96  if (!!result != !!tab[i].should_be_allowed) {
97  panic(0, "is_allowed_ip did not work for "
98  "allowed=<%s> denied=<%s> ip=<%s>, "
99  "returned %d should be %d",
100  octstr_get_cstr(allowed),
101  octstr_get_cstr(denied),
102  octstr_get_cstr(ip),
103  result,
104  tab[i].should_be_allowed);
105  }
106  }
107 
108  gwlib_shutdown();
109  return 0;
110 }
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
int is_allowed_ip(Octstr *allow_ip, Octstr *deny_ip, Octstr *ip)
Definition: utils.c:815
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
void log_set_output_level(enum output_level level)
Definition: log.c:217
Definition: octstr.c:118
Definition: log.h:69
#define panic
Definition: log.h:87
void gwlib_shutdown(void)
Definition: gwlib.c:94
void gwlib_init(void)
Definition: gwlib.c:78
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.