Commit Graph

119 Commits

Author SHA1 Message Date
29b3fc9db6 Consider connect timeout only when set
* libwget/net.c (set_socket_options): Skip SO_SNDTIMEO if connect timeout is <= 0.

Copyright-paperwork-exempt: Yes
2024-07-14 13:41:02 +02:00
21f41932af Fix ignoring connect timeout (regression)
* libwget/net.c (set_socket_options): Set SO_SNDTIMEO for socket

Reported-by: https://gitlab.com/plvalerio
Co-authored-by: https://gitlab.com/RogerMarcoHernandez
2024-07-07 20:12:17 +02:00
0e60ece89a Connect using synchronous socket
* libwget/dns.c (getaddrinfo_merging, resolve): Code cleanup.
* libwget/net.c (wget_tcp_connect): Connect first, then set socket to async.

Connecting asynchronously prevented wget2 to fallback to the next IP address
of a host when a connect error occurred.

Reported at https://github.com/rockdaboot/wget2/issues/325
2024-06-30 18:55:38 +02:00
7929bf887c Allow option --no-tcp-fastopen to work on Linux kernels >= 4.11.
* libwget/net.c (set_socket_options): Add check for tcp->tcp_fastopen.

Copyright-paperwork-exempt: Yes
2024-05-11 18:55:49 +02:00
fbfa096506 * libwget/net.c (wget_tcp_connect): Fix return code on resolve failure 2024-04-01 15:43:45 +02:00
188989e067 Update copyright year 2024-01-07 12:41:02 +01:00
1bab5454f9 Fix IPv6 address representation
* libwget/dns.c (resolve): Fix IPv6 in debug message,
  (wget_dns_cache_ip): Fix IPv6 in error message,
  (wget_dns_resolve): Fix IPv6 in debug message.
* libwget/dns_cache.c (wget_dns_cache_get): Fix IPv6 in debug message.
* libwget/hsts.c (hsts_db_add_entry): Fix IPv6 in debug message.
* libwget/http.c (wget_http_create_request): Fix IPv6 in Host header,
  (establish_proxy_connect): Fix IPv6 in CONNECT and in Host header.
* libwget/ip.c (wget_ip_is_family): Cosmetic change.
* libwget/iri.c (wget_iri_get_connection_part): Fix IPv6 in URL creation.
* libwget/net.c (debug_addr): Fix IPv6 in debug message.
* src/options.c (stats_callback_dns): Fix IPv6 in output.
* src/wget.c (test_modify_hsts): Fix IPv6 in console output,
  (http_create_request): Fix IPv6 in Referer header.
* unit-tests/test.c (test_iri_parse): Add two IPv6 parsing tests.
* libwget/Makefile.am (libwget_dnscache.la): Link with libwget_ip.la,
  (libwget_hsts.la): Link with libwget_ip.la.
2023-12-17 18:52:27 +01:00
0415d036b3 Fix minor typos in comments 2023-11-04 14:36:43 +01:00
15ba1db248 Update copyrights 2023-08-31 12:57:30 +02:00
bb20093f02 dns: Return all kinds of socket types available
The resolve() function only returned SOCK_STREAM (TCP) sockets. We lift
that limitation here, such that it will now return all socket types
available in the system, both SOCK_STREAM and SOCK_DGRAM. And we let the
calling function choose the socket type they want. We make this change
to adapt for the upcoming QUIC code, which works entirely over UDP.

 * libwget/dns.c (resolve): Remove SOCK_STREAM constraint, return all
   kinds of sock types available.
 * libwget/net.c (wget_tcp_connect): select SOCK_STREAM socket types
   only
   (tcp_connect): new function to establish TCP connections.
2023-08-23 11:00:17 +02:00
f1f23382d4 * libwget/net.c (wget_tcp_connect): Use bool type 2023-07-08 15:36:48 +02:00
279901855e Fix code to silence sc_gettext_printf
* libwget/http.c: Add _() around error messages where missing.
* libwget/net.c: Likewise.
* libwget/ssl_gnutls.c: Likewise.
* libwget/ssl_openssl.c: Likewise.
* src/wget.c: Likewise.
2023-07-08 13:00:40 +02:00
8dc11cafa9 * libwget/net.c (wget_tcp_write): Fix missing argument of print_error() 2023-07-01 13:24:15 +02:00
c7713482bc Use real destination port for DANE verification
* libwget/net.h (struct wget_tcp_st): New member remote_port.
* libwget/net.c (wget_tcp_connect): Set tcp->remote_port.
* libwget/ssl_gnutls.c (struct session_context): New member port,
  (wget_ssl_open): Set ctx->port,
  (verify_certificate_callback): Use ctx->port for DANE verification.
2023-04-23 19:50:33 +02:00
79925ea0c3 Extend network error messages with hostname and IP address
* libwget/net.c: New function print_error(),
  new function print_error_host(),
  (wget_tcp_connect): Use new functions for error messages,
  (wget_tcp_read): Likewise,
  (wget_tcp_write): Likewise.
2022-10-15 19:41:12 +02:00
73c89f7ae0 Add host information to tcp structure
* libwget/net.c (wget_tcp_connect): Set tcp.host,
  (wget_tcp_close): Free tcp.host.
* libwget/net.h (struct wget_tcp_st): Add new member 'host'.
2022-10-11 19:02:44 +02:00
35e9246787 * libwget/net.c (wget_tcp_write): Log 'Failed to send' instead of 'Failed to write' 2022-07-01 19:02:07 +02:00
3dc7f71098 Update copyright year 2022-02-25 17:46:43 +01:00
22162f82b2 Update copyright year 2021-01-22 21:58:38 +01:00
8145e07361 Fix findings from scan-build 11
* libwget/dns.c (wget_dns_resolve): 'rc' was set but not used.
* libwget/http.c (wget_http_get_response_cb): 'rc' was set but not used.
* libwget/net.c (wget_tcp_connect): 'rc' was set but not used.
* libwget/ssl_gnutls.c (send_ocsp_request): 'rc' was set but not used.
2020-12-20 17:13:27 +01:00
cef7950fcc * libwget/net.c (struct _stats_data_t): Remove unused struct 2020-03-17 16:49:35 +01:00
cd61b35fc5 * libwget/net.c (wget_tcp_set_bind_address): Simplify code 2020-03-17 16:49:35 +01:00
d7fca5d102 * libwget/net.c (wget_tcp_set_bind_address): Safer code with wget_strmemcpy_a 2020-02-25 11:31:25 +01:00
91bba3f697 Add option --bind-interface
* libwget/net.h (wget_tcp_st): New variable
  const char *bind_interface.
* libwget/net.c: Add function wget_tcp_bind_interface().
  (set_socket_options): Add parameter wget_tcp *tcp and
  implement binding of tcp to bind_interface.
* libwget/init.c (wget_global_init): Call wget_tcp_bind_interface().
* include/wget/wget.h: Add wget_tcp_bind_interface() and
  WGET_BIND_INTERFACE.
* src/options.c: Add --bind-interface handling.
  (init): Call wget_tcp_bind_interface().
* src/wget2_options.h (config): Add const char *bind_interface.
* docs/wget2.md: Add documentation for --bind-interface.

This finishes task #430
2020-02-24 12:28:00 +01:00
59d9ecd9c0 * Update copyright year to 2020 2020-01-10 00:33:02 +01:00
513605a420 Remove usage of strerror_r due to diverting GNU/POSIX behavior
* libwget/http_highlevel.c: Likewise
* libwget/net.c: Likewise
* src/wget.c: Likewise
2019-12-01 20:21:07 +01:00
e8ca510eda Replace strerror() by strerror_r() in multi-threaded code
* libwget/http_highlevel.c: Likewise
* libwget/net.c: Likewise
* src/wget.c: Likewise
2019-11-21 16:23:25 +01:00
fb302c1278 * libwget/net.c: Improve C99 compliancy 2019-09-23 21:17:38 +02:00
44f3411f73 Change type to bool for wget_tcp_set_ssl/wget_tcp_get_ssl
* include/wget/wget.h: Likewise
* libwget/net.c: Likewise
2019-09-18 13:16:18 +02:00
8d2acb05e4 Change return type of wget_tcp_get_tls_false_start() to bool
* include/wget/wget.h: Likewise
* libwget/net.c: Likewise
2019-09-18 13:07:16 +02:00
93245a5838 Change second param type of wget_tcp_set_tls_false_start() to bool
* include/wget/wget.h: Likewise
* libwget/net.c: Likewise
* src/wget_options.h (struct config): Change type of tls_false_start to bool
2019-09-18 13:05:50 +02:00
2013bd2168 Change return type of wget_tcp_get_tcp_fastopen() to bool
* include/wget/wget.h: Likewise
* libwget/net.c: Likewise
2019-09-18 13:02:46 +02:00
29d6777b57 Change second param type of wget_tcp_set_tcp_fastopen() to bool
* include/wget/wget.h: Likewise
* libwget/net.c: Likewise
* libwget/init.c (wget_global_init): Fix param type to wget_tcp_set_tcp_fastopen()
* src/wget_options.h (struct config): Change type of tcp_fastopen to bool
2019-09-18 12:59:43 +02:00
4b9edbad2d Update Copyright statements to be compatible with update-copyright module 2019-09-10 23:41:56 +02:00
c386741b58 * libwget/net.c (wget_tcp_init): Check malloc return value 2019-08-16 15:24:19 +02:00
6880c94e2e Move server stats code from library into wget2 tool
* fuzz/Makefile.am: Add src/stats_server.c
* src/Makefile.am: Likewise
* unit-tests/Makefile.am: Likewise
* include/wget/wget.h: Move `wget_server_stats_data` to src/stats_server.c,
  change wget_server_stats_callback,
  change wget_server_set_stats_callback(),
  add wget_tcp_get_ip(),
  remove host_ips_free()
* libwget/http.c: Move stats code to src/stats_server.c
* libwget/net.c: Add wget_tcp_get_ip()
* src/options.c: Move _hpkp_string() and stats_callback_server() to src/stats_server.c
* src/wget.c (main): Remove call to host_ips_free()
* src/wget_stats.h: Add prototypes of stats_server_add, server_stats_init, server_stats_exit
2019-08-12 16:14:48 +02:00
12f1a03693 Changed G_GNUC_WGET prefix to WGET_GCC
* include/wget/wget.h: Changed G_GNUC_WGET prefix to WGET_GCC
* */*.[ch]: Likewise
2019-08-08 17:13:24 +02:00
ad83fcf4c9 Rename wget_tcp_t -> wget_tcp
* include/wget/wget.h: Rename wget_tcp_t -> wget_tcp
* libwget/http.h: Likewise
* libwget/net.c: Likewise
* libwget/ssl_gnutls.c: Likewise
* libwget/ssl_none.c: Likewise
* libwget/ssl_wolfssl.c: Likewise
2019-07-19 16:25:18 +02:00
035753e4c8 Rename wget_dns_t -> wget_dns
* include/wget/wget.h: Rename wget_dns_t -> wget_dns
* libwget/dns.c: Likewise
* libwget/net.c: Likewise
* libwget/net.h: Likewise
* src/options.c: Likewise
2019-07-19 16:20:18 +02:00
db50c6a801 Rename wget_buffer_t -> wget_buffer
* include/wget/wget.h: Rename wget_buffer_t -> wget_buffer
* examples/*.c: Likewise
* fuzz/libwget_iri_fuzzer.c: Likewise
* libwget/*.c: Likewise
* src/*.c: Likewise
* tests/*.c: Likewise
* unit-tests/*.c: Likewise
2019-07-18 12:30:57 +02:00
31a792db9e * libwget/net.c: Fix compiler warning on MinGW 2019-06-24 12:34:51 +02:00
dcd9a3725a Separate DNS and DNS caching
* include/wget/wget.h: Rewrite parts of the DNS / DNS caching API
* libwget/dns.c: Likewise
* libwget/dns_cache.c: Likewise
* libwget/init.c (wget_global_init): Amend WGET_DNS_CACHING
* libwget/net.c: Cleanup and amend for the new API
* libwget/net.h: Cleanup
* src/options.c: Use DNS caching instance if caching is requested
2019-06-21 15:52:40 +02:00
b6c2f5f75c Put resolver/dns code into own source file
* docs/Makefile.am: Add libwget-dns.3 man page
* examples/batch_loader.c: Remove call to wget_tcp_set_dns_timeout()
* examples/check_url_types.c: Use wget_dns_set_timeout()
* include/wget/wget.h: Add wget_dns_ API
* libwget/Makefile.am: Add dns.c
* libwget/dns.c: New file
* libwget/init.c: Use wget_dns_set_caching()
* libwget/net.c: Remove DNS functions
* libwget/net.h (wget_tcp_st): Add dns member
* po/POTFILES.in: Add libwget/dns.c
* src/options.c: Use new DNS API
* src/stats.c: Add some checks
* src/stats_dns.c: Use wget_dns_get_stats()
2019-06-21 13:10:47 +02:00
5079807ffd Remove xmalloc define for wget_malloc
* libwget/private.h: Remove #define
* libwget/*.c: Replace xmalloc by wget_malloc
2019-06-20 16:43:46 +02:00
b4e81e1b3e Don't check for always true headers
* cfg.mk: Enable checking for always_true_header_tests
* libwget/http.c,net.c,ssl_gnutls.c: Don't check for HAVE_SYS_SOCKET_H.
  The gnulib module always provides it.
* libwget/ssl_gnutls.c: Don't check for HAVE_SYS_UIO_H. The gnulib
  module always provides it.
* bootstrap.conf: Add header sys_uio
* configure.ac: Remove check for sys/uio.h
2019-06-19 10:07:35 +02:00
9ca52e9e22 Add TCP FastOpen Linux 4.11+ style
* libwget/net.c: #define TCP_FASTOPEN_LINUX_411,
  (_set_socket_options): Set TCP_FASTOPEN_CONNECT socket option,
  (wget_tcp_connect): Add code for Linux 4.11+
2019-04-14 16:58:39 +02:00
cdb3600791 Update copyrigght to 2019 2019-01-02 12:42:53 +01:00
147ab3c96d Add new option --dns-cache-preload
* include/wget/wget.h: New function wget_tcp_dns_cache_add()
* libwget/dns_cache.c (wget_dns_cache_add): Fix docs
* libwget/net.c (_wget_tcp_resolve): Changed params,
  new function wget_tcp_dns_cache_add()
* src/options.c (options): Add --dns-cache-preload,
  new function _preload_dns_cache(),
  (init): Call _preload_dns_cache()
* src/wget_options.h (struct config): Add member dns_cache_preload
2018-08-08 14:49:17 +02:00
8a8d1de6b8 Remove usage of getaddrinfo_a() and gai_* functions
The glibc async functions turned out to be unstable and
error-prone. They also use threads to implement timeouts.
If we need DNS timeouts and/or async DNS lookups, we should
have a look at external resolver libraries.
2018-08-04 17:15:03 +02:00
3688ffb941 Update copyright to 2018 2018-04-30 20:52:11 +02:00