https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=198365 2006-09-30 Jan Kratochvil * ser-tcp.c (net_open): Support IPv6, "tcp6:"&co. notation. * configure.ac: Check for IPv6 getaddrinfo, getnameinfo and AF_INET6. * configure, config.in: Regenerate. 2006-09-30 Jan Kratochvil * gdbreplay.c (remote_open): Support IPv6, "tcp6:"&co. notation. * remote-utils.c (remote_open): Likewise. * configure.ac: Check for IPv6 getaddrinfo, getnameinfo and AF_INET6. * configure, config.in: Regenerate. 2006-09-30 Jan Kratochvil * gdb.texinfo (Connecting to a remote target): Support IPv6, "tcp6:"&co. notation. (Using the gdbserver program): Likewise. diff -u -rup gdb-6.5-orig/gdb/config.in gdb-6.5/gdb/config.in --- gdb-6.5-orig/gdb/config.in 2005-07-03 18:05:11.000000000 +0200 +++ gdb-6.5/gdb/config.in 2006-09-30 14:18:50.000000000 +0200 @@ -72,6 +72,10 @@ /* Define to 1 if you have the `dcgettext' function. */ #undef HAVE_DCGETTEXT +/* Define to 1 if you have the declaration of `AF_INET6', and to 0 if you + don't. */ +#undef HAVE_DECL_AF_INET6 + /* Define to 1 if you have the declaration of `free', and to 0 if you don't. */ #undef HAVE_DECL_FREE @@ -118,12 +122,18 @@ /* Define if has fpregset_t. */ #undef HAVE_FPREGSET_T +/* Define to 1 if you have the `getaddrinfo' function. */ +#undef HAVE_GETADDRINFO + /* Define to 1 if you have the `getcwd' function. */ #undef HAVE_GETCWD /* Define to 1 if you have the `getgid' function. */ #undef HAVE_GETGID +/* Define to 1 if you have the `getnameinfo' function. */ +#undef HAVE_GETNAMEINFO + /* Define to 1 if you have the `getpagesize' function. */ #undef HAVE_GETPAGESIZE diff -u -rup gdb-6.5-orig/gdb/configure gdb-6.5/gdb/configure --- gdb-6.5-orig/gdb/configure 2006-09-30 13:21:47.000000000 +0200 +++ gdb-6.5/gdb/configure 2006-09-30 14:25:10.000000000 +0200 @@ -16593,6 +16593,285 @@ fi done +for ac_func in getaddrinfo +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +for ac_func in getnameinfo +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + +echo "$as_me:$LINENO: checking whether AF_INET6 is declared" >&5 +echo $ECHO_N "checking whether AF_INET6 is declared... $ECHO_C" >&6 +if test "${ac_cv_have_decl_AF_INET6+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include + + +int +main () +{ +#ifndef AF_INET6 + char *p = (char *) AF_INET6; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_decl_AF_INET6=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_have_decl_AF_INET6=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_decl_AF_INET6" >&5 +echo "${ECHO_T}$ac_cv_have_decl_AF_INET6" >&6 +if test $ac_cv_have_decl_AF_INET6 = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_AF_INET6 1 +_ACEOF + + +else + cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_AF_INET6 0 +_ACEOF + + +fi + + + # Check the return and argument types of ptrace. No canned test for # this, so roll our own. gdb_ptrace_headers=' @@ -21471,7 +21750,7 @@ ac_x_header_dirs=' /usr/openwin/share/include' if test "$ac_x_includes" = no; then - # Guess where to find include files, by looking for Intrinsic.h. + # Guess where to find include files, by looking for Xlib.h. # First, try using that file with no special directory specified. cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ @@ -21479,7 +21758,7 @@ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include _ACEOF if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5 (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1 @@ -21506,7 +21785,7 @@ else sed 's/^/| /' conftest.$ac_ext >&5 for ac_dir in $ac_x_header_dirs; do - if test -r "$ac_dir/X11/Intrinsic.h"; then + if test -r "$ac_dir/X11/Xlib.h"; then ac_x_includes=$ac_dir break fi @@ -21520,18 +21799,18 @@ if test "$ac_x_libraries" = no; then # See if we find them without any special options. # Don't add to $LIBS permanently. ac_save_LIBS=$LIBS - LIBS="-lXt $LIBS" + LIBS="-lX11 $LIBS" cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ -#include +#include int main () { -XtMalloc (0) +XrmInitialize () ; return 0; } diff -u -rup gdb-6.5-orig/gdb/configure.ac gdb-6.5/gdb/configure.ac --- gdb-6.5-orig/gdb/configure.ac 2006-09-30 13:21:48.000000000 +0200 +++ gdb-6.5/gdb/configure.ac 2006-09-30 14:24:56.000000000 +0200 @@ -473,6 +473,12 @@ AC_CHECK_FUNCS(socketpair) AC_CHECK_FUNCS(syscall) AC_CHECK_FUNCS(ttrace) AC_CHECK_FUNCS(wborder) +AC_CHECK_FUNCS(getaddrinfo) +AC_CHECK_FUNCS(getnameinfo) +AC_CHECK_DECLS(AF_INET6, [], [], +[#include +#include +]) # Check the return and argument types of ptrace. No canned test for # this, so roll our own. diff -u -rup gdb-6.5-orig/gdb/doc/gdb.texinfo gdb-6.5/gdb/doc/gdb.texinfo --- gdb-6.5-orig/gdb/doc/gdb.texinfo 2006-09-30 13:21:48.000000000 +0200 +++ gdb-6.5/gdb/doc/gdb.texinfo 2006-09-30 13:34:32.000000000 +0200 @@ -12358,8 +12358,10 @@ If you're using a serial line, you may w (@pxref{Remote configuration, set remotebaud}) before the @code{target} command. -@item target remote @code{@var{host}:@var{port}} +@item target remote @code{@var{host}:@var{port}} @itemx target remote @code{tcp:@var{host}:@var{port}} +@itemx target remote @code{tcp4:@var{host}:@var{port}} +@itemx target remote @code{tcp6:@var{host}:@var{port}} @cindex @acronym{TCP} port, @code{target remote} Debug using a @acronym{TCP} connection to @var{port} on @var{host}. The @var{host} may be either a host name or a numeric @acronym{IP} @@ -12368,6 +12370,9 @@ the target machine itself, if it is dire it might be a terminal server which in turn has a serial line to the target. +@code{tcp6:} prefix forces IPv6 network connection while @code{tcp4:} forces +IPv4, both on the reliable stream TCP connection. + For example, to connect to port 2828 on a terminal server named @code{manyfarms}: @@ -12388,10 +12393,15 @@ target remote :1234 Note that the colon is still required here. @item target remote @code{udp:@var{host}:@var{port}} +@itemx target remote @code{udp6:@var{host}:@var{port}} +@itemx target remote @code{udp4:@var{host}:@var{port}} @cindex @acronym{UDP} port, @code{target remote} Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}: +@code{udp6:} prefix forces IPv6 network connection while @code{udp4:} forces +IPv4, both on the unreliable datagram UDP connection. + @smallexample target remote udp:manyfarms:2828 @end smallexample @@ -12532,14 +12542,30 @@ The only difference from the previous ex specifying that you are communicating with the host @value{GDBN} via TCP. The @samp{host:2345} argument means that @code{gdbserver} is to expect a TCP connection from machine @samp{host} to local TCP port 2345. -(Currently, the @samp{host} part is ignored.) You can choose any number -you want for the port number as long as it does not conflict with any -TCP ports already in use on the target system (for example, @code{23} is -reserved for @code{telnet}).@footnote{If you choose a port number that -conflicts with another service, @code{gdbserver} prints an error message +(The @samp{host} part is usually omitted as it defaults to listen from any +host. You may use a local address as expected by the @code{bind} syscall.) +You can choose any number you want for the port number as long as it does not +conflict with any TCP ports already in use on the target system (for example, +@code{23} is reserved for @code{telnet}).@footnote{If you choose a port number +that conflicts with another service, @code{gdbserver} prints an error message and exits.} You must use the same port number with the host @value{GDBN} @code{target remote} command. +@item gdbserver @code{tcp:@var{host}:@var{port}} emacs foo.txt +@itemx gdbserver @code{tcp6:@var{host}:@var{port}} emacs foo.txt +@itemx gdbserver @code{tcp4:@var{host}:@var{port}} emacs foo.txt +@itemx gdbserver @code{udp:@var{host}:@var{port}} emacs foo.txt +@itemx gdbserver @code{udp6:@var{host}:@var{port}} emacs foo.txt +@itemx gdbserver @code{udp4:@var{host}:@var{port}} emacs foo.txt + +The @code{::} part can be also replaced by the optional @var{host} part as +in the sample case of @code{tcp:@var{host}:@var{port}}. +These all alternative syntaxes force either the reliable stream TCP protocol or +the unreliable datagram UDP protocol appropriately. You may also force the use +of IPv6 or IPv4 network connections; @code{tcp:} and @code{udp:} select the +network version type according to the provided @var{host}. +The connection type defaults to the @code{tcp:} prefix behavior. + On some targets, @code{gdbserver} can also attach to running programs. This is accomplished via the @code{--attach} argument. The syntax is: diff -u -rup gdb-6.5-orig/gdb/gdbserver/config.in gdb-6.5/gdb/gdbserver/config.in --- gdb-6.5-orig/gdb/gdbserver/config.in 2006-03-15 17:13:28.000000000 +0100 +++ gdb-6.5/gdb/gdbserver/config.in 2006-09-30 16:23:20.000000000 +0200 @@ -1,5 +1,9 @@ /* config.in. Generated from configure.ac by autoheader. */ +/* Define to 1 if you have the declaration of `AF_INET6', and to 0 if you + don't. */ +#undef HAVE_DECL_AF_INET6 + /* Define to 1 if you have the declaration of `strerror', and to 0 if you don't. */ #undef HAVE_DECL_STRERROR @@ -7,6 +11,12 @@ /* Define if has elf_fpregset_t. */ #undef HAVE_ELF_FPREGSET_T +/* Define to 1 if you have the `getaddrinfo' function. */ +#undef HAVE_GETADDRINFO + +/* Define to 1 if you have the `getnameinfo' function. */ +#undef HAVE_GETNAMEINFO + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff -u -rup gdb-6.5-orig/gdb/gdbserver/configure gdb-6.5/gdb/gdbserver/configure --- gdb-6.5-orig/gdb/gdbserver/configure 2006-03-15 17:13:28.000000000 +0100 +++ gdb-6.5/gdb/gdbserver/configure 2006-09-30 16:23:19.000000000 +0200 @@ -947,7 +947,7 @@ esac else echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi - cd "$ac_popdir" + cd $ac_popdir done fi @@ -1865,7 +1865,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -1923,7 +1924,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2039,7 +2041,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2093,7 +2096,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2138,7 +2142,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2182,7 +2187,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2708,7 +2714,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2879,7 +2886,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -2956,7 +2964,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3104,7 +3113,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3179,7 +3189,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3213,6 +3224,285 @@ fi . ${srcdir}/configure.srv +for ac_func in getaddrinfo +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + +for ac_func in getnameinfo +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + +echo "$as_me:$LINENO: checking whether AF_INET6 is declared" >&5 +echo $ECHO_N "checking whether AF_INET6 is declared... $ECHO_C" >&6 +if test "${ac_cv_have_decl_AF_INET6+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +#include + + +int +main () +{ +#ifndef AF_INET6 + char *p = (char *) AF_INET6; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 + (eval $ac_compile) 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest.$ac_objext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + ac_cv_have_decl_AF_INET6=yes +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +ac_cv_have_decl_AF_INET6=no +fi +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: $ac_cv_have_decl_AF_INET6" >&5 +echo "${ECHO_T}$ac_cv_have_decl_AF_INET6" >&6 +if test $ac_cv_have_decl_AF_INET6 = yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_AF_INET6 1 +_ACEOF + + +else + cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_AF_INET6 0 +_ACEOF + + +fi + + + if test "${srv_linux_usrregs}" = "yes"; then cat >>confdefs.h <<\_ACEOF @@ -3257,7 +3547,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3318,7 +3609,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3383,7 +3675,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3447,7 +3740,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3511,7 +3805,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3575,7 +3870,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3654,7 +3950,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_l cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3711,7 +4008,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_l cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3776,7 +4074,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_l cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -3833,7 +4132,8 @@ if { (eval echo "$as_me:$LINENO: \"$ac_c cat conftest.err >&5 echo "$as_me:$LINENO: \$? = $ac_status" >&5 (exit $ac_status); } && - { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { ac_try='test -z "$ac_c_werror_flag" + || test ! -s conftest.err' { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 (eval $ac_try) 2>&5 ac_status=$? @@ -4686,6 +4986,11 @@ esac *) ac_INSTALL=$ac_top_builddir$INSTALL ;; esac + if test x"$ac_file" != x-; then + { echo "$as_me:$LINENO: creating $ac_file" >&5 +echo "$as_me: creating $ac_file" >&6;} + rm -f "$ac_file" + fi # Let's still pretend it is `configure' which instantiates (i.e., don't # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ @@ -4724,12 +5029,6 @@ echo "$as_me: error: cannot find input f fi;; esac done` || { (exit 1); exit 1; } - - if test x"$ac_file" != x-; then - { echo "$as_me:$LINENO: creating $ac_file" >&5 -echo "$as_me: creating $ac_file" >&6;} - rm -f "$ac_file" - fi _ACEOF cat >>$CONFIG_STATUS <<_ACEOF sed "$ac_vpsub diff -u -rup gdb-6.5-orig/gdb/gdbserver/configure.ac gdb-6.5/gdb/gdbserver/configure.ac --- gdb-6.5-orig/gdb/gdbserver/configure.ac 2006-03-15 17:13:29.000000000 +0100 +++ gdb-6.5/gdb/gdbserver/configure.ac 2006-09-30 16:23:06.000000000 +0200 @@ -47,6 +47,12 @@ AC_CHECK_TYPES(socklen_t, [], [], #include ]) . ${srcdir}/configure.srv +AC_CHECK_FUNCS(getaddrinfo) +AC_CHECK_FUNCS(getnameinfo) +AC_CHECK_DECLS(AF_INET6, [], [], +[#include +#include +]) if test "${srv_linux_usrregs}" = "yes"; then AC_DEFINE(HAVE_LINUX_USRREGS, 1, diff -u -rup gdb-6.5-orig/gdb/gdbserver/gdbreplay.c gdb-6.5/gdb/gdbserver/gdbreplay.c --- gdb-6.5-orig/gdb/gdbserver/gdbreplay.c 2005-12-23 19:11:55.000000000 +0100 +++ gdb-6.5/gdb/gdbserver/gdbreplay.c 2006-09-30 16:26:09.000000000 +0200 @@ -99,6 +99,8 @@ remote_close (void) static void remote_open (char *name) { + char *name_orig = name; + if (!strchr (name, ':')) { fprintf (stderr, "%s: Must specify tcp connection as host:addr\n", name); @@ -108,56 +110,232 @@ remote_open (char *name) else { char *port_str; - int port; - struct sockaddr_in sockaddr; socklen_t tmp; - int tmp_desc; + int tmp_desc = -1; + struct prefix + { + const char *string; + int family; + int socktype; + }; + const struct prefix prefixes[] = + { + { "udp:", AF_UNSPEC, SOCK_DGRAM }, + { "tcp:", AF_UNSPEC, SOCK_STREAM }, + { "udp4:", AF_INET, SOCK_DGRAM }, + { "tcp4:", AF_INET, SOCK_STREAM }, +/* We do not support `AF_INET6' without getaddrinfo(3). */ +#if defined (HAVE_GETADDRINFO) && HAVE_DECL_AF_INET6 + { "udp6:", AF_INET6, SOCK_DGRAM }, + { "tcp6:", AF_INET6, SOCK_STREAM }, +#endif /* defined (HAVE_GETADDRINFO) && HAVE_DECL_AF_INET6 */ + }; + const struct prefix *prefix; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints; + struct addrinfo *addrinfo_base, *addrinfo = NULL; + int err; +#else /* !HAVE_GETADDRINFO */ + struct sockaddr_in sockaddr; +#endif /* !HAVE_GETADDRINFO */ +#ifdef HAVE_GETNAMEINFO + char back_host[64], back_port[16]; +#endif /* HAVE_GETNAMEINFO */ + char *name_base; + + name_base = strdup (name); + name = name_base; +#ifdef HAVE_GETADDRINFO + memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; +#endif /* HAVE_GETADDRINFO */ + for (prefix = prefixes; + prefix < prefixes + sizeof (prefixes) / sizeof (*prefixes); + prefix++) + if (strncmp (name, prefix->string, strlen (prefix->string)) == 0) + { + name += strlen (prefix->string); +#ifdef HAVE_GETADDRINFO + hints.ai_family = prefix->family; + hints.ai_socktype = prefix->socktype; +#endif /* HAVE_GETADDRINFO */ + break; + } + if (prefix >= prefixes + sizeof (prefixes) / sizeof (*prefixes)) + prefix = NULL; + if ((prefix == NULL || prefix->family != AF_INET) + && name[0] == '[' && (port_str = strchr (name, ']'))) + { + name++; + *port_str++ = 0; + } + else + port_str = strchr (name, ':'); + /* It may happen with IPv6 for like "[::1]". */ + if (port_str == NULL || *port_str != ':') + { + fprintf (stderr, "net_open: No colon in host name!\n"); + fflush (stderr); + exit (1); + } + *port_str++ = 0; - port_str = strchr (name, ':'); + /* Default hostname for `node == NULL' is `INADDR_ANY'/`in6addr_any'. + as we did specify `hints.ai_flags & AI_PASSIVE'. */ + if (name[0] == 0) + name = NULL; + +#ifdef HAVE_GETADDRINFO + err = getaddrinfo (name, port_str, &hints, &addrinfo_base); + if (err != 0) + { + /* `name_base' is used here for `port_str'. */ + fprintf (stderr, "%s:%s: cannot resolve name: %s\n", + name, port_str, gai_strerror (err)); + fflush (stderr); + exit (1); + } - port = atoi (port_str + 1); + for (addrinfo = addrinfo_base; + addrinfo != NULL; + addrinfo = addrinfo->ai_next) + { + tmp_desc = socket (addrinfo->ai_family, addrinfo->ai_socktype, + addrinfo->ai_protocol); + if (tmp_desc >= 0) + break; + } + if (addrinfo == NULL) + { + freeaddrinfo (addrinfo_base); + perror_with_name ("Can't open socket"); + } +#else /* !HAVE_GETADDRINFO */ + sockaddr.sin_family = PF_INET; + sockaddr.sin_port = htons (atoi (port_str)); - tmp_desc = socket (PF_INET, SOCK_STREAM, 0); + if (name == NULL) + sockaddr.sin_addr.s_addr = INADDR_ANY; + else + { + struct hostent *hostent; + + hostent = gethostbyname (name); + if (hostent == NULL) + { + fprintf (stderr, "%s: unknown host\n", name); + free (name_base); + perror_with_name ("gethostbyname(3) resolving"); + } + + memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + } + + /* We assume matching `AF_*' and `PF_*'. */ + tmp_desc = socket (sockaddr.sin_family, + (prefix != NULL ? prefix->socktype : SOCK_STREAM), + 0); if (tmp_desc < 0) - perror_with_name ("Can't open socket"); + { + free (name_base); + perror_with_name ("Can't open socket"); + } +#endif /* !HAVE_GETADDRINFO */ /* Allow rapid reuse of this port. */ tmp = 1; setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp)); - sockaddr.sin_family = PF_INET; - sockaddr.sin_port = htons (port); - sockaddr.sin_addr.s_addr = INADDR_ANY; - +#ifdef HAVE_GETADDRINFO + if (bind (tmp_desc, addrinfo->ai_addr, addrinfo->ai_addrlen) + || ((prefix == NULL || prefix->socktype != SOCK_DGRAM) + && listen (tmp_desc, 1))) +#else /* !HAVE_GETADDRINFO */ if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) - || listen (tmp_desc, 1)) - perror_with_name ("Can't bind address"); - - tmp = sizeof (sockaddr); - remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp); - if (remote_desc == -1) - perror_with_name ("Accept failed"); - - /* Enable TCP keep alive process. */ - tmp = 1; - setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp)); - - /* Tell TCP not to delay small packets. This greatly speeds up - interactive response. */ - tmp = 1; - setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY, - (char *) &tmp, sizeof (tmp)); + || ((prefix == NULL || prefix->socktype != SOCK_DGRAM) + && listen (tmp_desc, 1))) +#endif /* !HAVE_GETADDRINFO */ + { +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + free (name_base); + perror_with_name ("Can't bind address"); + } + +#ifdef HAVE_GETNAMEINFO + if (0 == getnameinfo (addrinfo->ai_addr, addrinfo->ai_addrlen, + back_host, sizeof (back_host), + back_port, sizeof (back_port), + NI_NUMERICHOST | NI_NUMERICSERV)) + fprintf (stderr, "Listening on port %s (on host %s)\n", + back_port, back_host); + else +#endif /* !HAVE_GETNAMEINFO */ + fprintf (stderr, "Listening on port %s (on host %s)\n", + port_str, (name != NULL ? name : "")); + fflush (stderr); - close (tmp_desc); /* No longer need this */ + /* Used for `port_str' above. */ + free (name_base); - signal (SIGPIPE, SIG_IGN); /* If we don't do this, then gdbreplay simply - exits when the remote side dies. */ + if (prefix != NULL && prefix->socktype == SOCK_DGRAM) + remote_desc = tmp_desc; + else + { + struct sockaddr_storage sockaddr; + socklen_t sockaddr_len = sizeof (sockaddr); + remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &sockaddr_len); + if (remote_desc == -1) + { +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + perror_with_name ("Accept failed"); + } + + /* Enable TCP keep alive process. */ + tmp = 1; + setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp)); + + /* Tell TCP not to delay small packets. This greatly speeds up + interactive response. */ + if (prefix == NULL || prefix->socktype == SOCK_STREAM) + { + tmp = 1; + setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY, + (char *) &tmp, sizeof (tmp)); + } +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + + close (tmp_desc); /* No longer need this */ + + signal (SIGPIPE, SIG_IGN); /* If we don't do this, then gdbserver simply + exits when the remote side dies. */ + +#ifdef HAVE_GETNAMEINFO + /* Convert IP address to string. */ + if (0 == getnameinfo ((struct sockaddr *) &sockaddr, sockaddr_len, + back_host, sizeof (back_host), + back_port, sizeof (back_port), + NI_NUMERICHOST | NI_NUMERICSERV)) + fprintf (stderr, "Remote debugging from host %s port %s\n", + back_host, back_port); + else +#endif /* !HAVE_GETNAMEINFO */ + fprintf (stderr, "Remote debugging started\n"); + } + fflush (stderr); } fcntl (remote_desc, F_SETFL, FASYNC); - fprintf (stderr, "Replay logfile using %s\n", name); + fprintf (stderr, "Replay logfile using %s\n", name_orig); fflush (stderr); } diff -u -rup gdb-6.5-orig/gdb/gdbserver/remote-utils.c gdb-6.5/gdb/gdbserver/remote-utils.c --- gdb-6.5-orig/gdb/gdbserver/remote-utils.c 2006-03-03 15:48:55.000000000 +0100 +++ gdb-6.5/gdb/gdbserver/remote-utils.c 2006-09-30 16:25:16.000000000 +0200 @@ -124,57 +124,222 @@ remote_open (char *name) else { char *port_str; - int port; - struct sockaddr_in sockaddr; socklen_t tmp; - int tmp_desc; + int tmp_desc = -1; + struct prefix + { + const char *string; + int family; + int socktype; + }; + const struct prefix prefixes[] = + { + { "udp:", AF_UNSPEC, SOCK_DGRAM }, + { "tcp:", AF_UNSPEC, SOCK_STREAM }, + { "udp4:", AF_INET, SOCK_DGRAM }, + { "tcp4:", AF_INET, SOCK_STREAM }, +/* We do not support `AF_INET6' without getaddrinfo(3). */ +#if defined (HAVE_GETADDRINFO) && HAVE_DECL_AF_INET6 + { "udp6:", AF_INET6, SOCK_DGRAM }, + { "tcp6:", AF_INET6, SOCK_STREAM }, +#endif /* defined (HAVE_GETADDRINFO) && HAVE_DECL_AF_INET6 */ + }; + const struct prefix *prefix; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints; + struct addrinfo *addrinfo_base, *addrinfo = NULL; + int err; +#else /* !HAVE_GETADDRINFO */ + struct sockaddr_in sockaddr; +#endif /* !HAVE_GETADDRINFO */ +#ifdef HAVE_GETNAMEINFO + char back_host[64], back_port[16]; +#endif /* HAVE_GETNAMEINFO */ + char *name_base; + + name_base = strdup (name); + name = name_base; +#ifdef HAVE_GETADDRINFO + memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE; +#endif /* HAVE_GETADDRINFO */ + for (prefix = prefixes; + prefix < prefixes + sizeof (prefixes) / sizeof (*prefixes); + prefix++) + if (strncmp (name, prefix->string, strlen (prefix->string)) == 0) + { + name += strlen (prefix->string); +#ifdef HAVE_GETADDRINFO + hints.ai_family = prefix->family; + hints.ai_socktype = prefix->socktype; +#endif /* HAVE_GETADDRINFO */ + break; + } + if (prefix >= prefixes + sizeof (prefixes) / sizeof (*prefixes)) + prefix = NULL; + if ((prefix == NULL || prefix->family != AF_INET) + && name[0] == '[' && (port_str = strchr (name, ']'))) + { + name++; + *port_str++ = 0; + } + else + port_str = strchr (name, ':'); + /* It may happen with IPv6 for like "[::1]". */ + if (port_str == NULL || *port_str != ':') + error ("net_open: No colon in host name!"); + *port_str++ = 0; + + /* Default hostname for `node == NULL' is `INADDR_ANY'/`in6addr_any'. + as we did specify `hints.ai_flags & AI_PASSIVE'. */ + if (name[0] == 0) + name = NULL; + +#ifdef HAVE_GETADDRINFO + err = getaddrinfo (name, port_str, &hints, &addrinfo_base); + if (err != 0) + { + /* `name_base' is used here for `port_str'. */ + error ("%s:%s: cannot resolve name: %s\n", + name, port_str, gai_strerror (err)); + } + + for (addrinfo = addrinfo_base; + addrinfo != NULL; + addrinfo = addrinfo->ai_next) + { + tmp_desc = socket (addrinfo->ai_family, addrinfo->ai_socktype, + addrinfo->ai_protocol); + if (tmp_desc >= 0) + break; + } + if (addrinfo == NULL) + { + freeaddrinfo (addrinfo_base); + free (name_base); + perror_with_name ("Can't open socket"); + } +#else /* !HAVE_GETADDRINFO */ + sockaddr.sin_family = PF_INET; + sockaddr.sin_port = htons (atoi (port_str)); - port_str = strchr (name, ':'); + if (name == NULL) + sockaddr.sin_addr.s_addr = INADDR_ANY; + else + { + struct hostent *hostent; - port = atoi (port_str + 1); + hostent = gethostbyname (name); + if (hostent == NULL) + { + fprintf (stderr, "%s: unknown host\n", name); + free (name_base); + perror_with_name ("gethostbyname(3) resolving"); + } - tmp_desc = socket (PF_INET, SOCK_STREAM, 0); + memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + } + + /* We assume matching `AF_*' and `PF_*'. */ + tmp_desc = socket (sockaddr.sin_family, + (prefix != NULL ? prefix->socktype : SOCK_STREAM), + 0); if (tmp_desc < 0) - perror_with_name ("Can't open socket"); + { + free (name_base); + perror_with_name ("Can't open socket"); + } +#endif /* !HAVE_GETADDRINFO */ /* Allow rapid reuse of this port. */ tmp = 1; setsockopt (tmp_desc, SOL_SOCKET, SO_REUSEADDR, (char *) &tmp, sizeof (tmp)); - sockaddr.sin_family = PF_INET; - sockaddr.sin_port = htons (port); - sockaddr.sin_addr.s_addr = INADDR_ANY; - +#ifdef HAVE_GETADDRINFO + if (bind (tmp_desc, addrinfo->ai_addr, addrinfo->ai_addrlen) + || ((prefix == NULL || prefix->socktype != SOCK_DGRAM) + && listen (tmp_desc, 1))) +#else /* !HAVE_GETADDRINFO */ if (bind (tmp_desc, (struct sockaddr *) &sockaddr, sizeof (sockaddr)) - || listen (tmp_desc, 1)) - perror_with_name ("Can't bind address"); - - fprintf (stderr, "Listening on port %d\n", port); - - tmp = sizeof (sockaddr); - remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &tmp); - if (remote_desc == -1) - perror_with_name ("Accept failed"); - - /* Enable TCP keep alive process. */ - tmp = 1; - setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp)); + || ((prefix == NULL || prefix->socktype != SOCK_DGRAM) + && listen (tmp_desc, 1))) +#endif /* !HAVE_GETADDRINFO */ + { +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + free (name_base); + perror_with_name ("Can't bind address"); + } - /* Tell TCP not to delay small packets. This greatly speeds up - interactive response. */ - tmp = 1; - setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY, - (char *) &tmp, sizeof (tmp)); +#ifdef HAVE_GETNAMEINFO + if (0 == getnameinfo (addrinfo->ai_addr, addrinfo->ai_addrlen, + back_host, sizeof (back_host), + back_port, sizeof (back_port), + NI_NUMERICHOST | NI_NUMERICSERV)) + fprintf (stderr, "Listening on port %s (on host %s)\n", + back_port, back_host); + else +#endif /* !HAVE_GETNAMEINFO */ + fprintf (stderr, "Listening on port %s (on host %s)\n", + port_str, (name != NULL ? name : "")); + fflush (stderr); - close (tmp_desc); /* No longer need this */ + /* Used for `port_str' above. */ + free (name_base); - signal (SIGPIPE, SIG_IGN); /* If we don't do this, then gdbserver simply - exits when the remote side dies. */ + if (prefix != NULL && prefix->socktype == SOCK_DGRAM) + remote_desc = tmp_desc; + else + { + struct sockaddr_storage sockaddr; + socklen_t sockaddr_len = sizeof (sockaddr); + remote_desc = accept (tmp_desc, (struct sockaddr *) &sockaddr, &sockaddr_len); + if (remote_desc == -1) + { +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + perror_with_name ("Accept failed"); + } - /* Convert IP address to string. */ - fprintf (stderr, "Remote debugging from host %s\n", - inet_ntoa (sockaddr.sin_addr)); + /* Enable TCP keep alive process. */ + tmp = 1; + setsockopt (tmp_desc, SOL_SOCKET, SO_KEEPALIVE, (char *) &tmp, sizeof (tmp)); + + /* Tell TCP not to delay small packets. This greatly speeds up + interactive response. */ + if (prefix == NULL || prefix->socktype == SOCK_STREAM) + { + tmp = 1; + setsockopt (remote_desc, IPPROTO_TCP, TCP_NODELAY, + (char *) &tmp, sizeof (tmp)); + } +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + + close (tmp_desc); /* No longer need this */ + + signal (SIGPIPE, SIG_IGN); /* If we don't do this, then gdbserver simply + exits when the remote side dies. */ + +#ifdef HAVE_GETNAMEINFO + /* Convert IP address to string. */ + if (0 == getnameinfo ((struct sockaddr *) &sockaddr, sockaddr_len, + back_host, sizeof (back_host), + back_port, sizeof (back_port), + NI_NUMERICHOST | NI_NUMERICSERV)) + fprintf (stderr, "Remote debugging from host %s port %s\n", + back_host, back_port); + else +#endif /* !HAVE_GETNAMEINFO */ + fprintf (stderr, "Remote debugging started\n"); + } + fflush (stderr); } #if defined(F_SETFL) && defined (FASYNC) diff -u -rup gdb-6.5-orig/gdb/ser-tcp.c gdb-6.5/gdb/ser-tcp.c --- gdb-6.5-orig/gdb/ser-tcp.c 2006-02-10 23:01:43.000000000 +0100 +++ gdb-6.5/gdb/ser-tcp.c 2006-09-30 15:53:48.000000000 +0200 @@ -68,67 +68,142 @@ void _initialize_ser_tcp (void); int net_open (struct serial *scb, const char *name) { - char *port_str, hostname[100]; - int n, port, tmp; - int use_udp; - struct hostent *hostent; - struct sockaddr_in sockaddr; + char *name_base; + char *port_str; + int n, tmp; #ifdef USE_WIN32API u_long ioarg; #else int ioarg; #endif - - use_udp = 0; - if (strncmp (name, "udp:", 4) == 0) + struct prefix + { + const char *string; + int family; + int socktype; + }; + const struct prefix prefixes[] = { - use_udp = 1; - name = name + 4; + { "udp:", AF_UNSPEC, SOCK_DGRAM }, + { "tcp:", AF_UNSPEC, SOCK_STREAM }, + { "udp4:", AF_INET, SOCK_DGRAM }, + { "tcp4:", AF_INET, SOCK_STREAM }, +/* We do not support `AF_INET6' without getaddrinfo(3). */ +#if defined (HAVE_GETADDRINFO) && HAVE_DECL_AF_INET6 + { "udp6:", AF_INET6, SOCK_DGRAM }, + { "tcp6:", AF_INET6, SOCK_STREAM }, +#endif /* defined (HAVE_GETADDRINFO) && HAVE_DECL_AF_INET6 */ + }; + const struct prefix *prefix; +#ifdef HAVE_GETADDRINFO + struct addrinfo hints; + struct addrinfo *addrinfo_base, *addrinfo = NULL; +#else /* !HAVE_GETADDRINFO */ + struct hostent *hostent; + struct sockaddr_in sockaddr; +#endif /* !HAVE_GETADDRINFO */ + /* Error by default. */ + int retval = -1; + + name_base = xstrdup (name); + name = name_base; +#ifdef HAVE_GETADDRINFO + memset (&hints, 0, sizeof (hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_ADDRCONFIG; +#endif /* HAVE_GETADDRINFO */ + for (prefix = prefixes; prefix < prefixes + ARRAY_SIZE (prefixes); prefix++) + if (strncmp (name, prefix->string, strlen (prefix->string)) == 0) + { + name += strlen (prefix->string); +#ifdef HAVE_GETADDRINFO + hints.ai_family = prefix->family; + hints.ai_socktype = prefix->socktype; +#endif /* HAVE_GETADDRINFO */ + break; + } + if (prefix >= prefixes + ARRAY_SIZE (prefixes)) + prefix = NULL; + if ((prefix == NULL || prefix->family != AF_INET) + && name[0] == '[' && (port_str = strchr (name, ']'))) + { + name++; + *port_str++ = 0; + } + else + port_str = strchr (name, ':'); + /* It may happen with IPv6 for like "[::1]". */ + if (port_str == NULL || *port_str != ':') + error (_("net_open: No colon in host name!")); + *port_str++ = 0; + + /* Default hostname for `node == NULL' is localhost + as we did not specify `hints.ai_flags & AI_PASSIVE'. */ + if (name[0] == 0) + name = NULL; + +#ifdef HAVE_GETADDRINFO + n = getaddrinfo (name, port_str, &hints, &addrinfo_base); + if (n != 0) + { + fprintf_unfiltered (gdb_stderr, "%s:%s: cannot resolve name: %s\n", + (name != NULL ? name : ""), + port_str, gai_strerror (n)); + errno = ENOENT; + free (name_base); + return -1; } - else if (strncmp (name, "tcp:", 4) == 0) - name = name + 4; - - port_str = strchr (name, ':'); - - if (!port_str) - error (_("net_open: No colon in host name!")); /* Shouldn't ever happen */ - - tmp = min (port_str - name, (int) sizeof hostname - 1); - strncpy (hostname, name, tmp); /* Don't want colon */ - hostname[tmp] = '\000'; /* Tie off host name */ - port = atoi (port_str + 1); - /* default hostname is localhost */ - if (!hostname[0]) - strcpy (hostname, "localhost"); + /* Still used for `port_str' above. */ + free (name_base); - hostent = gethostbyname (hostname); - if (!hostent) + for (addrinfo = addrinfo_base; addrinfo != NULL; addrinfo = addrinfo->ai_next) + { + scb->fd = socket (addrinfo->ai_family, addrinfo->ai_socktype, + addrinfo->ai_protocol); + if (scb->fd >= 0) + break; + } + if (addrinfo == NULL) { - fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", hostname); + freeaddrinfo (addrinfo_base); + return -1; + } +#else /* !HAVE_GETADDRINFO */ + hostent = gethostbyname ((name != NULL ? name : "localhost")); + if (hostent == NULL) + { + fprintf_unfiltered (gdb_stderr, "%s: unknown host\n", name); errno = ENOENT; + free (name_base); return -1; } - if (use_udp) - scb->fd = socket (PF_INET, SOCK_DGRAM, 0); - else - scb->fd = socket (PF_INET, SOCK_STREAM, 0); + sockaddr.sin_family = PF_INET; + sockaddr.sin_port = htons (atoi (port_str)); + memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, + sizeof (struct in_addr)); + /* Still used for `port_str' above. */ + free (name_base); + + scb->fd = socket (sockaddr.sin_family, + (prefix != NULL ? prefix->socktype : SOCK_STREAM), + 0); if (scb->fd < 0) return -1; - - sockaddr.sin_family = PF_INET; - sockaddr.sin_port = htons (port); - memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, - sizeof (struct in_addr)); +#endif /* !HAVE_GETADDRINFO */ /* set socket nonblocking */ ioarg = 1; ioctl (scb->fd, FIONBIO, &ioarg); /* Use Non-blocking connect. connect() will return 0 if connected already. */ +#ifdef HAVE_GETADDRINFO + n = connect (scb->fd, addrinfo->ai_addr, addrinfo->ai_addrlen); +#else /* !HAVE_GETADDRINFO */ n = connect (scb->fd, (struct sockaddr *) &sockaddr, sizeof (sockaddr)); +#endif /* !HAVE_GETADDRINFO */ if (n < 0 #ifdef USE_WIN32API @@ -143,8 +218,7 @@ net_open (struct serial *scb, const char #ifdef USE_WIN32API errno = WSAGetLastError(); #endif - net_close (scb); - return -1; + goto cleanup_scb; } if (n) @@ -165,8 +239,7 @@ net_open (struct serial *scb, const char if (deprecated_ui_loop_hook (0)) { errno = EINTR; - net_close (scb); - return -1; + goto cleanup_scb; } } @@ -192,8 +265,7 @@ net_open (struct serial *scb, const char { if (polls > TIMEOUT * POLL_INTERVAL) errno = ETIMEDOUT; - net_close (scb); - return -1; + goto cleanup_scb; } } @@ -211,8 +283,7 @@ net_open (struct serial *scb, const char { if (err) errno = err; - net_close (scb); - return -1; + goto cleanup_scb; } } @@ -220,7 +291,7 @@ net_open (struct serial *scb, const char ioarg = 0; ioctl (scb->fd, FIONBIO, &ioarg); - if (use_udp == 0) + if (prefix == NULL || prefix->socktype == SOCK_STREAM) { /* Disable Nagle algorithm. Needed in some cases. */ tmp = 1; @@ -234,7 +305,16 @@ net_open (struct serial *scb, const char signal (SIGPIPE, SIG_IGN); #endif - return 0; + retval = 0; + goto cleanup_addrinfo_base; + +cleanup_scb: + net_close (scb); +cleanup_addrinfo_base: +#ifdef HAVE_GETADDRINFO + freeaddrinfo (addrinfo_base); +#endif /* HAVE_GETADDRINFO */ + return retval; } void