/** * Create a generic IP address object from the current expanded * assignment. */ static void create_ip_address(struct ipset_iterator *iterator) { struct cork_ip *addr = &iterator->addr; struct ipset_expanded_assignment *exp = iterator->assignment_iterator; /* Initialize the address to all 0 bits. */ memset(addr, 0, sizeof(struct cork_ip)); /* Check variable 0 to see if this is an IPv4 or IPv6 address. */ addr->version = IPSET_BIT_GET(exp->values.buf, 0)? 4: 6; /* Copy bits from the expanded assignment. The number of bits to * copy is given as the current netmask. We'll have calculated that * already based on the non-expanded assignment. */ unsigned int i; for (i = 0; i < iterator->cidr_prefix; i++) { IPSET_BIT_SET(&addr->ip, i, IPSET_BIT_GET(exp->values.buf, i+1)); } #if IPSET_DEBUG char buf[CORK_IP_STRING_LENGTH]; cork_ip_to_raw_string(addr, buf); DEBUG("Current IP address is %s/%u", buf, iterator->cidr_prefix); #endif }
static void create_ip_address(ipset_iterator_t *iterator) { ipset_ip_t *addr = &iterator->addr; ipset_expanded_assignment_t *exp = iterator->assignment_iterator; /* * Check variable 0 to see if this is an IPv4 or IPv6 address. */ addr->is_ipv4 = IPSET_BIT_GET(exp->values->data, 0); /* * Initialize the address to all 0 bits. */ memset(addr->addr, 0, sizeof(guint32) * 4); /* * Copy bits from the expanded assignment. The number of bits to * copy is given as the current netmask. We'll have calculated * that already based on the non-expanded assignment. */ guint i; for (i = 0; i < iterator->netmask; i++) { IPSET_BIT_SET(addr->addr, i, IPSET_BIT_GET(exp->values->data, i+1)); } g_d_debug("Current IP address is %s/%u", ipset_ip_to_string(addr), iterator->netmask); }