MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / mk_net

Function mk_net

ip_addr.c:43–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41__thread char _ip_addr_A_buffs[IP_ADDR2STR_BUF_NO][IP_ADDR_MAX_STR_SIZE];
42
43struct 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;
75error:
76 return 0;
77}
78
79
80

Callers 2

mk_net_bitlenFunction · 0.85
parse_ip_netFunction · 0.85

Calls 1

print_ipFunction · 0.85

Tested by

no test coverage detected