/** * Try with next host in the (already shuffled) list. */ static void uhc_try_next(void) { host_addr_t addr; g_assert(uhc_connecting); g_assert(uhc_ctx.timeout_ev == NULL); if (!uhc_pick()) { uhc_connecting = FALSE; return; } /* * The following may recurse if resolution is synchronous, but * we're protected by the `attempts' counter. */ if (string_to_host_addr(uhc_ctx.host, NULL, &addr)) { uhc_ctx.addr = addr; if (GNET_PROPERTY(bootstrap_debug)) g_debug("BOOT UDP host cache \"%s\"", uhc_ctx.host); uhc_send_ping(); } else { (void) adns_resolve(uhc_ctx.host, settings_dns_net(), uhc_host_resolved, NULL); } }
void on_entry_config_ipv6_trt_prefix_activate(GtkEditable *unused_editable, gpointer unused_udata) { const gchar *endptr; host_addr_t addr; gchar *text; (void) unused_editable; (void) unused_udata; text = STRTRACK(gtk_editable_get_chars( GTK_EDITABLE(gui_dlg_prefs_lookup("entry_config_ipv6_trt_prefix")), 0, -1)); g_strstrip(text); if ( string_to_host_addr(text, &endptr, &addr) && '\0' == endptr[0] && host_addr_is_ipv6(addr) ) { gnet_prop_set_ip_val(PROP_IPV6_TRT_PREFIX, addr); } else if (0 == strcmp(text, "") || 0 == strcmp(text, "<none>")) { gnet_prop_set_ip_val(PROP_IPV6_TRT_PREFIX, zero_host_addr); } G_FREE_NULL(text); }
/** * Is the X-Alt header really holding a collection of IP:port (with possible * push alt-locs containing a prefixing GUID) or is it mistakenly called * X-Alt but is really an old X-Gnutella-Alternate-Location containing a * list of HTTP URLs. */ static bool huge_is_pure_xalt(const char *value, size_t len) { host_addr_t addr; /* * This is pure heuristics, knowing that if we return TRUE, we'll parse * the X-Alt header in the format that is emitted by the majority of * vendors. * * We try to avoid the more costly pattern_qsearch() call if we can, * and our heuristic should catch 99% of the cases. And pattern_qsearch() * should quickly return true if the X-Alt is not a collection of IP:port. */ if (is_strcaseprefix(value, "tls=")) return TRUE; if (string_to_host_addr(value, NULL, &addr)) return TRUE; if (pattern_qsearch(has_http_urls, value, len, 0, qs_any)) return FALSE; return TRUE; }
/** * Parses the NUL-terminated string ``s'' for a host address or a hostname. * If ``s'' points to a parsable address, ``*ha'' will be set to it. Otherwise, * ``*ha'' is set to ``zero_host_addr''. If the string is a possible hostname * the function returns TRUE nonetheless and ``*endptr'' will point to the * first character after hostname. * * @param s the string to parse. * @param endptr if not NULL, it will point the first character after * the parsed host address or hostname. * @param ha if not NULL, it is set to the parsed host address or * ``zero_host_addr'' on failure. * @return TRUE if the string points to host address or is a possible * hostname. */ bool string_to_host_or_addr(const char *s, const char **endptr, host_addr_t *ha) { const char *ep; size_t len; host_addr_t addr; if (string_to_host_addr(s, endptr, &addr)) { if (ha) *ha = addr; return TRUE; } for (ep = s; '\0' != *ep; ep++) { if (!is_ascii_alnum(*ep) && '.' != *ep && '-' != *ep) break; } if (ha) *ha = zero_host_addr; if (endptr) *endptr = ep; len = ep - s; return len > 0 && len <= MAX_HOSTLEN; }
/** * Parse argument from specified name/value table into an IP address. * * @param nvt the name/value table holding arguments * @param name the argument name whose value we need to parse * @param addrp where to put the parsed address * * @return TRUE if OK with the address filled in, FALSE on failure. */ static gboolean upnp_ctrl_get_addr(nv_table_t *nvt, const char *name, host_addr_t *addrp) { const char *ip; ip = nv_table_lookup_str(nvt, name); if (NULL == ip) return FALSE; return string_to_host_addr(ip, NULL, addrp); }
void on_entry_config_force_ip_changed(GtkEditable *editable, gpointer unused_udata) { gchar *text = STRTRACK(gtk_editable_get_chars(editable, 0, -1)); const gchar *endptr; gboolean sensitive; (void) unused_udata; g_strstrip(text); sensitive = string_to_host_addr(text, &endptr, NULL) && '\0' == endptr[0]; gtk_widget_set_sensitive( gui_dlg_prefs_lookup("checkbutton_config_force_ip"), sensitive); gtk_widget_set_sensitive( gui_dlg_prefs_lookup("checkbutton_config_bind_ipv4"), sensitive); G_FREE_NULL(text); }
void on_entry_config_ipv6_trt_prefix_changed(GtkEditable *editable, gpointer unused_udata) { gchar *text = STRTRACK(gtk_editable_get_chars(editable, 0, -1)); const gchar *endptr; host_addr_t addr; gboolean sensitive; (void) unused_udata; g_strstrip(text); sensitive = string_to_host_addr(text, &endptr, &addr) && '\0' == endptr[0] && host_addr_is_ipv6(addr); gtk_widget_set_sensitive( gui_dlg_prefs_lookup("checkbutton_config_ipv6_trt_enable"), sensitive); G_FREE_NULL(text); }
void on_entry_config_force_ip_activate(GtkEditable *unused_editable, gpointer unused_udata) { gchar *text; host_addr_t addr; const gchar *endptr; (void) unused_editable; (void) unused_udata; text = STRTRACK(gtk_editable_get_chars( GTK_EDITABLE(gui_dlg_prefs_lookup("entry_config_force_ip")), 0, -1)); g_strstrip(text); if (string_to_host_addr(text, &endptr, &addr) && '\0' == endptr[0]) { gnet_prop_set_ip_val(PROP_FORCED_LOCAL_IP, addr); } else if (0 == strcmp(text, "") || 0 == strcmp(text, "<none>")) { gnet_prop_set_ip_val(PROP_FORCED_LOCAL_IP, zero_host_addr); } G_FREE_NULL(text); }