static gboolean ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { const char *slash; const char *addr_str; char *addr_str_to_free = NULL; unsigned int nmask_bits; fvalue_t *nmask_fvalue; /* Look for prefix: Is there a single slash in the string? */ slash = strchr(s, '/'); if (slash) { /* Make a copy of the string up to but not including the * slash; that's the address portion. */ addr_str_to_free = wmem_strndup(NULL, s, slash-s); addr_str = addr_str_to_free; } else addr_str = s; if (!get_host_ipaddr6(addr_str, &(fv->value.ipv6.addr))) { if (err_msg != NULL) *err_msg = g_strdup_printf("\"%s\" is not a valid hostname or IPv6 address.", s); if (addr_str_to_free) wmem_free(NULL, addr_str_to_free); return FALSE; } if (addr_str_to_free) wmem_free(NULL, addr_str_to_free); /* If prefix */ if (slash) { /* XXX - this is inefficient */ nmask_fvalue = fvalue_from_unparsed(FT_UINT32, slash+1, FALSE, err_msg); if (!nmask_fvalue) { return FALSE; } nmask_bits = fvalue_get_uinteger(nmask_fvalue); FVALUE_FREE(nmask_fvalue); if (nmask_bits > 128) { if (err_msg != NULL) { *err_msg = g_strdup_printf("Prefix in a IPv6 address should be <= 128, not %u", nmask_bits); } return FALSE; } fv->value.ipv6.prefix = nmask_bits; } else { /* Not CIDR; mask covers entire address. */ fv->value.ipv6.prefix = 128; } return TRUE; }
static void follow_arg_filter(const char **opt_argp, follow_info_t *follow_info) { int len; unsigned int ii; char addr[ADDR_LEN]; cli_follow_info_t* cli_follow_info = (cli_follow_info_t*)follow_info->gui_data; if (sscanf(*opt_argp, ",%u%n", &cli_follow_info->stream_index, &len) == 1 && ((*opt_argp)[len] == 0 || (*opt_argp)[len] == ',')) { *opt_argp += len; } else { for (ii = 0; ii < sizeof cli_follow_info->addr/sizeof *cli_follow_info->addr; ii++) { if ((sscanf(*opt_argp, ADDRv6_FMT, addr, &cli_follow_info->port[ii], &len) != 2 && sscanf(*opt_argp, ADDRv4_FMT, addr, &cli_follow_info->port[ii], &len) != 2) || cli_follow_info->port[ii] <= 0 || cli_follow_info->port[ii] > G_MAXUINT16) { follow_exit("Invalid address:port pair."); } if (strcmp("ip6", host_ip_af(addr)) == 0) { if (!get_host_ipaddr6(addr, (struct e_in6_addr *)cli_follow_info->addrBuf[ii])) { follow_exit("Can't get IPv6 address"); } set_address(&cli_follow_info->addr[ii], AT_IPv6, 16, cli_follow_info->addrBuf[ii]); } else { if (!get_host_ipaddr(addr, (guint32 *)cli_follow_info->addrBuf[ii])) { follow_exit("Can't get IPv4 address"); } set_address(&cli_follow_info->addr[ii], AT_IPv4, 4, cli_follow_info->addrBuf[ii]); } *opt_argp += len; } if (cli_follow_info->addr[0].type != cli_follow_info->addr[1].type) { follow_exit("Mismatched IP address types."); } cli_follow_info->stream_index = -1; } }
static gboolean ipv6_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogFunc logfunc) { char *has_slash, *addr_str; unsigned int nmask_bits; fvalue_t *nmask_fvalue; /* Look for prefix: Is there a single slash in the string? */ if ((has_slash = strchr(s, '/'))) addr_str = ep_strndup(s, has_slash-s); else addr_str = s; if (!get_host_ipaddr6(addr_str, &(fv->value.ipv6.addr))) { logfunc("\"%s\" is not a valid hostname or IPv6 address.", s); return FALSE; } /* If prefix */ if (has_slash) { /* XXX - this is inefficient */ nmask_fvalue = fvalue_from_unparsed(FT_UINT32, has_slash+1, FALSE, logfunc); if (!nmask_fvalue) { return FALSE; } nmask_bits = fvalue_get_uinteger(nmask_fvalue); FVALUE_FREE(nmask_fvalue); if (nmask_bits > 128) { logfunc("Prefix in a IPv6 address should be <= 128, not %u", nmask_bits); return FALSE; } fv->value.ipv6.prefix = nmask_bits; } else { /* Not CIDR; mask covers entire address. */ fv->value.ipv6.prefix = 128; } return TRUE; }
static void follow_arg_filter(const char **opt_argp, follow_info_t *follow_info) { int len; unsigned int ii; char addr[ADDR_LEN]; cli_follow_info_t* cli_follow_info = (cli_follow_info_t*)follow_info->gui_data; gboolean is_ipv6; if (sscanf(*opt_argp, ",%d%n", &cli_follow_info->stream_index, &len) == 1 && ((*opt_argp)[len] == 0 || (*opt_argp)[len] == ',')) { *opt_argp += len; } else { for (ii = 0; ii < sizeof cli_follow_info->addr/sizeof *cli_follow_info->addr; ii++) { if (sscanf(*opt_argp, ADDRv6_FMT, addr, &cli_follow_info->port[ii], &len) == 2) { is_ipv6 = TRUE; } else if (sscanf(*opt_argp, ADDRv4_FMT, addr, &cli_follow_info->port[ii], &len) == 2) { is_ipv6 = FALSE; } else { follow_exit("Invalid address."); } if (cli_follow_info->port[ii] <= 0 || cli_follow_info->port[ii] > G_MAXUINT16) { follow_exit("Invalid port."); } if (is_ipv6) { if (!get_host_ipaddr6(addr, &cli_follow_info->addrBuf[ii].addrBuf_v6)) { follow_exit("Can't get IPv6 address"); } set_address(&cli_follow_info->addr[ii], AT_IPv6, 16, (void *)&cli_follow_info->addrBuf[ii].addrBuf_v6); } else { if (!get_host_ipaddr(addr, &cli_follow_info->addrBuf[ii].addrBuf_v4)) { follow_exit("Can't get IPv4 address"); } set_address(&cli_follow_info->addr[ii], AT_IPv4, 4, (void *)&cli_follow_info->addrBuf[ii].addrBuf_v4); } *opt_argp += len; } if (cli_follow_info->addr[0].type != cli_follow_info->addr[1].type) { follow_exit("Mismatched IP address types."); } cli_follow_info->stream_index = -1; } }