| 41 | __thread char _ip_addr_A_buffs[IP_ADDR2STR_BUF_NO][IP_ADDR_MAX_STR_SIZE]; |
| 42 | |
| 43 | struct net* mk_net(const struct ip_addr* ip, struct ip_addr* mask) |
| 44 | { |
| 45 | struct net* n; |
| 46 | int warning; |
| 47 | unsigned int r; |
| 48 | |
| 49 | warning=0; |
| 50 | if ((ip->af != mask->af) || (ip->len != mask->len)){ |
| 51 | LM_CRIT("trying to use a different mask family" |
| 52 | " (eg. ipv4/ipv6mask or ipv6/ipv4mask)\n"); |
| 53 | goto error; |
| 54 | } |
| 55 | n=(struct net*)pkg_malloc(sizeof(struct net)); |
| 56 | if (n==0){ |
| 57 | LM_CRIT("memory allocation failure\n"); |
| 58 | goto error; |
| 59 | } |
| 60 | n->ip=*ip; |
| 61 | n->mask=*mask; |
| 62 | for (r=0; r<n->ip.len/4; r++) { /*ipv4 & ipv6 addresses are multiple of 4*/ |
| 63 | n->ip.u.addr32[r] &= n->mask.u.addr32[r]; |
| 64 | if (n->ip.u.addr32[r]!=ip->u.addr32[r]) warning=1; |
| 65 | }; |
| 66 | if (warning){ |
| 67 | LM_WARN("invalid network address/netmask " |
| 68 | "combination fixed...\n"); |
| 69 | print_ip("original network address:", ip, "/"); |
| 70 | print_ip("", mask, "\n"); |
| 71 | print_ip("fixed network address:", &(n->ip), "/"); |
| 72 | print_ip("", &(n->mask), "\n"); |
| 73 | }; |
| 74 | return n; |
| 75 | error: |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | |
| 80 |
no test coverage detected