/* set the ip mask and ip address */ void parse_ip_address(char *address, uint32_t *addr, uint32_t *msk) { char *p; /* first the mask */ if ((p = strrchr(address, '/')) != NULL) { *p = '\0'; if (ip_mask(p + 1, (unsigned char *)msk)) print_error("Problem with the IP mask"); } else *msk = 0xFFFFFFFF; if (undot_ip(address, (unsigned char *)addr)) print_error("Problem with the IP address"); *addr = *addr & *msk; }
void ebt_parse_ip_address(char *address, uint32_t *addr, uint32_t *msk) { char *p; if ((p = strrchr(address, '/')) != NULL) { *p = '\0'; if (ip_mask(p + 1, (unsigned char *)msk)) { ebt_print_error("Problem with the IP mask '%s'", p + 1); return; } } else *msk = 0xFFFFFFFF; if (undot_ip(address, (unsigned char *)addr)) { ebt_print_error("Problem with the IP address '%s'", address); return; } *addr = *addr & *msk; }
/* put the mask into 4 bytes */ static int ip_mask(char *mask, unsigned char *mask2) { char *end; long int bits; uint32_t mask22; if (undot_ip(mask, mask2)) { /* not the /a.b.c.e format, maybe the /x format */ bits = strtol(mask, &end, 10); if (*end != '\0' || bits > 32 || bits < 0) return -1; if (bits != 0) { mask22 = htonl(0xFFFFFFFF << (32 - bits)); memcpy(mask2, &mask22, 4); } else { mask22 = 0xFFFFFFFF; memcpy(mask2, &mask22, 4); } } return 0; }
static void ebt_parse_ip_address(char *address, uint32_t *addr, uint32_t *msk) { char *p; /* first the mask */ if ((p = strrchr(address, '/')) != NULL) { *p = '\0'; if (ip_mask(p + 1, (unsigned char *)msk)) { xtables_error(PARAMETER_PROBLEM, "Problem with the IP mask '%s'", p + 1); return; } } else *msk = 0xFFFFFFFF; if (undot_ip(address, (unsigned char *)addr)) { xtables_error(PARAMETER_PROBLEM, "Problem with the IP address '%s'", address); return; } *addr = *addr & *msk; }