diff options
| author | Anton <anton@picapica> | 2017-12-02 20:32:19 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2017-12-02 20:32:19 +0400 |
| commit | 233a812bb060ef68aa606a55d478efaf62b44c9b (patch) | |
| tree | ed94b43cf3436c05da6c6d775e48d5b5ee564e89 | |
| parent | 0f726c30f5f11990d325bc5e55015c42c80cd9d2 (diff) | |
| download | pica-pica-233a812bb060ef68aa606a55d478efaf62b44c9b.tar.gz pica-pica-233a812bb060ef68aa606a55d478efaf62b44c9b.zip | |
moved PICA_is_reserved_addr_ipv4() to new file PICA_netconf.c
| -rw-r--r-- | Makefile.am | 3 | ||||
| -rw-r--r-- | PICA_netconf.c | 28 | ||||
| -rw-r--r-- | PICA_netconf.h | 21 | ||||
| -rw-r--r-- | PICA_node.c | 1 | ||||
| -rw-r--r-- | PICA_nodeaddrlist.c | 27 | ||||
| -rw-r--r-- | PICA_nodeaddrlist.h | 1 |
6 files changed, 53 insertions, 28 deletions
diff --git a/Makefile.am b/Makefile.am index bb19dac..ec75613 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,8 @@ pica_node_SOURCES = PICA_node.c PICA_msgproc.c PICA_nodeaddrlist.c \ PICA_node.h PICA_msgproc.h PICA_nodeaddrlist.h \ PICA_nodewait.h PICA_nodeconfig.h PICA_log.h \ iniparser/src/dictionary.h iniparser/src/iniparser.h \ - PICA_common.h PICA_proto.h PICA_id.h PICA_id.c + PICA_common.h PICA_proto.h PICA_id.h PICA_id.c \ + PICA_netconf.c PICA_netconf.h dist_man_MANS = pica-node.8 pica-node.conf.5 diff --git a/PICA_netconf.c b/PICA_netconf.c new file mode 100644 index 0000000..9657e39 --- /dev/null +++ b/PICA_netconf.c @@ -0,0 +1,28 @@ +#include "PICA_netconf.h" + +#define PREFIX4 htonl(0xf0000000U) +#define PREFIX8 htonl(0xff000000U) +#define PREFIX12 htonl(0xfff00000U) +#define PREFIX16 htonl(0xffff0000U) +#define PREFIX24 htonl(0xffffff00U) + +#define MAKEIP(a, b, c, d) (htonl( (a&0xFF) << 24 | (b&0xFF) << 16 | (c&0xFF) << 8 | (d&0xFF) )) + + +int PICA_is_reserved_addr_ipv4(in_addr_t addr) +{ + if ((addr & PREFIX8) == 0 //0.0.0.0/8 + || (addr & PREFIX8) == MAKEIP(10, 0, 0, 0) //10.0.0.0/8 + || (addr & PREFIX8) == MAKEIP(127, 0, 0, 0)//127.0.0.0/8 + || (addr & PREFIX16) == MAKEIP(169, 254, 0, 0) //169.254.0.0/16 + || (addr & PREFIX12) == MAKEIP(172, 16, 0, 0) //172.16.0.0/12 + || (addr & PREFIX16) == MAKEIP(192, 168, 0, 0) //192.168.0.0/16 + || (addr & PREFIX4) == MAKEIP(224, 0, 0, 0) //224.0.0.0/4 + || (addr & PREFIX4) == MAKEIP(240, 0, 0, 0) //240.0.0.0/4 + || addr == INADDR_BROADCAST + ) + return 1; + + return 0; +} + diff --git a/PICA_netconf.h b/PICA_netconf.h new file mode 100644 index 0000000..bab5738 --- /dev/null +++ b/PICA_netconf.h @@ -0,0 +1,21 @@ +#ifndef PICA_NETCONF_H +#define PICA_NETCONF_H + +#ifndef WIN32 + +#include <netinet/in.h> + +#else + +#define _WIN32_WINNT 0x501 +#include <winsock2.h> +#include <ws2tcpip.h> + +typedef u_long in_addr_t; +typedef u_short in_port_t; +#endif + +int PICA_is_reserved_addr_ipv4(in_addr_t); + +#endif + diff --git a/PICA_node.c b/PICA_node.c index fdd1759..48a97b9 100644 --- a/PICA_node.c +++ b/PICA_node.c @@ -11,6 +11,7 @@ #include "PICA_proto.h" #include "PICA_msgproc.h" #include "PICA_nodeaddrlist.h" +#include "PICA_netconf.h" #include "PICA_common.h" #include "PICA_nodeconfig.h" #include "PICA_log.h" diff --git a/PICA_nodeaddrlist.c b/PICA_nodeaddrlist.c index 52e4f29..d16eb33 100644 --- a/PICA_nodeaddrlist.c +++ b/PICA_nodeaddrlist.c @@ -6,37 +6,12 @@ #include "PICA_log.h" -#define PREFIX4 htonl(0xf0000000U) -#define PREFIX8 htonl(0xff000000U) -#define PREFIX12 htonl(0xfff00000U) -#define PREFIX16 htonl(0xffff0000U) -#define PREFIX24 htonl(0xffffff00U) - -#define MAKEIP(a, b, c, d) (htonl( (a&0xFF) << 24 | (b&0xFF) << 16 | (c&0xFF) << 8 | (d&0xFF) )) - struct cb_param { struct PICA_nodeaddr **n_addr; int *N; }; -int PICA_is_reserved_addr_ipv4(in_addr_t addr) -{ - if ((addr & PREFIX8) == 0 //0.0.0.0/8 - || (addr & PREFIX8) == MAKEIP(10, 0, 0, 0) //10.0.0.0/8 - || (addr & PREFIX8) == MAKEIP(127, 0, 0, 0)//127.0.0.0/8 - || (addr & PREFIX16) == MAKEIP(169, 254, 0, 0) //169.254.0.0/16 - || (addr & PREFIX12) == MAKEIP(172, 16, 0, 0) //172.16.0.0/12 - || (addr & PREFIX16) == MAKEIP(192, 168, 0, 0) //192.168.0.0/16 - || (addr & PREFIX4) == MAKEIP(224, 0, 0, 0) //224.0.0.0/4 - || (addr & PREFIX4) == MAKEIP(240, 0, 0, 0) //240.0.0.0/4 - || addr == INADDR_BROADCAST - ) - return 1; - - return 0; -} - static int nodeaddr_load_sqlite_cb(void *p, int argc, char **argv, char **ColName) { struct cb_param *cp = (struct cb_param*)p; @@ -236,4 +211,4 @@ void PICA_nodeaddr_list_free(struct PICA_nodeaddr *list_head) free(pp); pp = pn; } -}
\ No newline at end of file +} diff --git a/PICA_nodeaddrlist.h b/PICA_nodeaddrlist.h index b90de8f..f19a579 100644 --- a/PICA_nodeaddrlist.h +++ b/PICA_nodeaddrlist.h @@ -49,7 +49,6 @@ struct PICA_nodeaddr struct PICA_nodeaddr *next; }; -int PICA_is_reserved_addr_ipv4(in_addr_t); int PICA_nodeaddr_list_load(const char* dbfilename, struct PICA_nodeaddr **list_head); int PICA_nodeaddr_save(const char* dbfilename, struct PICA_nodeaddr *naddr); |
