00001 /* 00002 ** subnet.h for lseos in lseos-srv/net/inet/linet 00003 ** 00004 ** Copyright(c)2004 Vianney Rancurel 00005 ** Login <vianney@epita.fr> 00006 ** 00007 ** Started on Sun Oct 17 22:59:22 1999 Vianney Rancurel 00008 ** Last update Tue Dec 7 17:44:32 2004 Vianney Rancurel 00009 */ 00010 #ifndef INET_SUBNET_H 00011 #define INET_SUBNET_H 00012 00013 typedef struct s_subnet 00014 { 00015 struct in_addr addr; 00016 struct in_addr mask; 00017 } t_subnet; 00018 00019 typedef int (*t_subnet_walk_proc)(struct in_addr *addr, 00020 void *data); 00021 00022 #define SUBNET_PREFIX 0 00023 #define SUBNET_NETMASK 1 00024 #define SUBNET_HISTORICAL 2 00025 00026 #define SUBNET_CABLE(Subnet) ((Subnet)->addr.s_addr &\ 00027 (Subnet)->mask.s_addr) 00028 #define SUBNET_BCAST(Subnet) ((Subnet)->addr.s_addr |\ 00029 (~(Subnet)->mask.s_addr)) 00030 00031 #define SUBNET_ERR_TOO_BIG 1 00032 #define SUBNET_ERR_SYNTAX_IN_ADDR 2 00033 #define SUBNET_ERR_SYNTAX_IN_MASK 3 00034 #define SUBNET_ERR_NOT_CIDR 4 00035 00036 /* PROTO lib_subnet.c */ 00037 /* lib_subnet.c */ 00038 char *subnet_err_msg(int errcode); 00039 int subnet_in_class_default_nshift(struct in_addr *addr); 00040 int subnet_prefix_from_netmask(struct in_addr *netmask); 00041 int subnet_from_str(char *str, int check_cidr, t_subnet *subnet); 00042 int subnet_is_member(t_subnet *subnet, struct in_addr *inaddr); 00043 int subnet_walk(t_subnet *subnet, t_subnet_walk_proc proc, void *data); 00044 void subnet_print(t_printf_fn printf_fn, t_subnet *subnet); 00045 char *subnet_ntoa(t_subnet *subnet); 00046 #endif