Discussion:
[PATCH] cmd. line switch to force IPv4 / IPv6 connection
Urs Janßen
2011-01-30 01:50:14 UTC
Permalink
I noticed that there is no way to force IPv4 connection if compiled with
IPv6 support. This is usefull when the server has an IPv6 address
and AAAA record but is not reachable via IPv6 cause of routing
problems or the like.

diff -Nur doc/tin.1 doc/tin.1
--- doc/tin.1 2011-01-29 20:20:59.699519750 +0100
+++ doc/tin.1 2011-01-30 02:29:16.244390499 +0100
@@ -26,6 +26,7 @@
.RB \|\| \-s
.IR News_dir \|]
.RB [\| \-cuvZ \|]
+.RB [\| \-4 \||\| \-6 \|]
.RB [\| \-N \||\| \-M
.IR address \|]
.RB [\| \-o \||\| \-w \|]\|]
@@ -100,6 +101,12 @@
.\"
.SH OPTIONS
.TP 12
+.B \-4
+Force connecting via IPv4 to the remote NNTP server.
+.TP
+.B \-6
+Force connecting via IPv6 to the remote NNTP server.
+.TP
.B \-a
Toggle ANSI color (default is off).
.TP
diff -Nur include/extern.h include/extern.h
--- include/extern.h 2011-01-29 20:04:20.808698598 +0100
+++ include/extern.h 2011-01-30 02:20:39.586435551 +0100
@@ -1254,6 +1254,10 @@
#ifdef NNTP_ABLE
extern constext txt_unparseable_counts[];
extern constext txt_usage_force_authentication[];
+#ifdef INET6
+ extern constext txt_usage_force_ipv4[];
+ extern constext txt_usage_force_ipv6[];
+#endif /* INET6 */
extern constext txt_usage_newsserver[];
extern constext txt_usage_port[];
extern constext txt_usage_read_news_remotely[];
@@ -1449,6 +1453,10 @@
extern t_bool disable_sender;
extern t_bool force_no_post;
extern t_bool force_reread_active_file;
+#if defined(NNTP_ABLE) && defined(INET6)
+ extern t_bool force_ipv4;
+ extern t_bool force_ipv6;
+#endif /* NNTP_ABLE && INET6 */
extern t_bool have_linescroll;
extern t_bool list_active;
extern t_bool newsrc_active;
diff -Nur src/init.c src/init.c
--- src/init.c 2011-01-29 20:22:11.602373961 +0100
+++ src/init.c 2011-01-30 02:19:17.618070499 +0100
@@ -132,6 +132,10 @@
#else
t_bool force_no_post = FALSE; /* don't force no posting mode */
#endif /* NO_POSTING */
+#if defined(NNTP_ABLE) && defined(INET6)
+ t_bool force_ipv4 = FALSE;
+ t_bool force_ipv6 = FALSE;
+#endif /* NNTP_ABLE && INET6 */
t_bool list_active;
t_bool newsrc_active;
t_bool no_write = FALSE; /* do not write newsrc on quit (-X cmd-line flag) */
diff -Nur src/lang.c src/lang.c
--- src/lang.c 2011-01-29 20:05:21.181813508 +0100
+++ src/lang.c 2011-01-30 02:20:04.045073978 +0100
@@ -1100,6 +1100,8 @@
constext txt_usage_read_only_active[] = N_(" -l use only LIST instead of GROUP (-n) command");
constext txt_usage_read_only_subscribed[] = N_(" -n only read subscribed .newsrc groups from NNTP server");
# ifdef INET6
+ constext txt_usage_force_ipv4[] = N_(" -4 force connecting via IPv4");
+ constext txt_usage_force_ipv6[] = N_(" -6 force connecting via IPv6");
constext txt_error_socket_or_connect_problem[] = N_("\nsocket or connect problem\n");
# else
constext txt_connection_to[] = N_("\nConnection to %s: ");
diff -Nur src/main.c src/main.c
--- src/main.c 2011-01-29 15:06:15.898322793 +0100
+++ src/main.c 2011-01-30 02:18:56.678911933 +0100
@@ -418,7 +418,7 @@
/*
* process command line options
*/
-#define OPTIONS "aAcdD:f:g:G:hHI:lm:M:nNop:qQrRs:SuvVwxXzZ"
+#define OPTIONS "46aAcdD:f:g:G:hHI:lm:M:nNop:qQrRs:SuvVwxXzZ"

static void
read_cmd_line_options(
@@ -432,6 +432,31 @@

while ((ch = getopt(argc, argv, OPTIONS)) != -1) {
switch (ch) {
+
+ case '4':
+#if defined(NNTP_ABLE) && defined(INET6)
+ force_ipv4 = TRUE;
+ read_news_via_nntp = TRUE;
+#else
+ error_message(2, _(txt_option_not_enabled), "-DNNTP_ABLE");
+ giveup();
+ /* keep lint quiet: */
+ /* NOTREACHED */
+#endif /* NNTP_ABLE && INET6 */
+ break;
+
+ case '6':
+#if defined(NNTP_ABLE) && defined(INET6)
+ force_ipv6 = TRUE;
+ read_news_via_nntp = TRUE;
+# else
+ error_message(2, _(txt_option_not_enabled), "-DNNTP_ABLE");
+ giveup();
+ /* keep lint quiet: */
+ /* NOTREACHED */
+#endif /* NNTP_ABLE && INET6 */
+ break;
+
case 'a':
#ifdef HAVE_COLOR
cmdline.args |= CMDLINE_USE_COLOR;
@@ -446,6 +471,7 @@
case 'A':
#ifdef NNTP_ABLE
force_auth_on_conn_open = TRUE;
+ read_news_via_nntp = TRUE;
#else
error_message(2, _(txt_option_not_enabled), "-DNNTP_ABLE");
giveup();
@@ -733,6 +759,14 @@
wait_message(2, _(txt_useless_combination), "-Z", "-z", "-Z");
check_any_unread = FALSE;
}
+
+#if defined(NNTP_ABLE) && defined(INET6)
+ if (force_ipv4 && force_ipv6) {
+ wait_message(2, _(txt_useless_combination), "-4", "-6", "-6");
+ force_ipv6 = FALSE;
+ }
+#endif /* NNTP_ABLE && INET6 */
+
if (mail_news || save_news || update_index || check_any_unread || catchup)
batch_mode = TRUE;
else
@@ -775,6 +809,11 @@
{
error_message(2, _(txt_usage_tin), theProgname);

+#if defined(NNTP_ABLE) && defined(INET6)
+ error_message(2, _(txt_usage_force_ipv4));
+ error_message(2, _(txt_usage_force_ipv6));
+#endif /* NNTP_ABLE && INET6 */
+
#ifdef HAVE_COLOR
error_message(2, _(txt_usage_toggle_color));
#endif /* HAVE_COLOR */
diff -Nur src/nntplib.c src/nntplib.c
--- src/nntplib.c 2011-01-25 18:33:55.000000000 +0100
+++ src/nntplib.c 2011-01-30 02:00:30.740094081 +0100
@@ -615,7 +615,7 @@
# endif /* AF_UNSPEC */
memset(&hints, 0, sizeof(hints));
/* hints.ai_flags = AI_CANONNAME; */
- hints.ai_family = ADDRFAM;
+ hints.ai_family = (force_ipv4 ? AF_INET : (force_ipv6 ? AF_INET6 : ADDRFAM));
hints.ai_socktype = SOCK_STREAM;
res = (struct addrinfo *) 0;
res0 = (struct addrinfo *) 0;

Loading...