From ffa45eae76f01277182871415f2f3375be261bb7 Mon Sep 17 00:00:00 2001 From: hpa Date: Wed, 28 Mar 2001 18:24:25 +0000 Subject: [PATCH] Add code to always reply using the queried IP address, if the OS makes it possible. --- config.h.in | 19 ++ configure | 447 ++++++++++++++++++++++++++++++++++++----------- configure.in | 21 +++ tftp/main.c | 4 + tftpd/Makefile | 2 +- tftpd/recvfrom.c | 139 +++++++++++++++ tftpd/recvfrom.h | 28 +++ tftpd/tftpd.c | 15 +- 8 files changed, 569 insertions(+), 106 deletions(-) create mode 100644 config.h.in create mode 100644 tftpd/recvfrom.c create mode 100644 tftpd/recvfrom.h diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..c8d8c69 --- /dev/null +++ b/config.h.in @@ -0,0 +1,19 @@ +/* $Id$ */ +/* ----------------------------------------------------------------------- * + * + * Copyright 2001 H. Peter Anvin - All Rights Reserved + * + * This program is free software available under the same license + * as the "OpenBSD" operating system, distributed at + * http://www.openbsd.org/. + * + * ----------------------------------------------------------------------- */ + +/* + * config.h.in + * + * Pattern file for configurations + */ + +#undef HAVE_MSGHDR_MSG_CONTROL +#undef HAVE_RECVMSG diff --git a/configure b/configure index 2091ed2..de0e107 100755 --- a/configure +++ b/configure @@ -1,7 +1,7 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.12 +# Generated automatically using autoconf version 2.13 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. # # This configure script is free software; the Free Software Foundation @@ -49,6 +49,7 @@ mandir='${prefix}/man' # Initialize some other variables. subdirs= MFLAGS= MAKEFLAGS= +SHELL=${CONFIG_SHELL-/bin/sh} # Maximum number of lines to put in a shell here document. ac_max_here_lines=12 @@ -332,7 +333,7 @@ EOF verbose=yes ;; -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.12" + echo "configure generated by autoconf version 2.13" exit 0 ;; -with-* | --with-*) @@ -502,9 +503,11 @@ ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross +ac_exeext= +ac_objext=o if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then @@ -522,15 +525,16 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:526: checking for $ac_word" >&5 +echo "configure:529: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" - for ac_dir in $PATH; do + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="gcc" @@ -551,16 +555,17 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:555: checking for $ac_word" >&5 +echo "configure:559: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" ac_prog_rejected=no - for ac_dir in $PATH; do + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then @@ -595,25 +600,61 @@ else echo "$ac_t""no" 1>&6 fi + if test -z "$CC"; then + case "`uname -s`" in + *win32* | *WIN32*) + # Extract the first word of "cl", so it can be a program name with args. +set dummy cl; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 +echo "configure:610: checking for $ac_word" >&5 +if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + ac_dummy="$PATH" + for ac_dir in $ac_dummy; do + test -z "$ac_dir" && ac_dir=. + if test -f $ac_dir/$ac_word; then + ac_cv_prog_CC="cl" + break + fi + done + IFS="$ac_save_ifs" +fi +fi +CC="$ac_cv_prog_CC" +if test -n "$CC"; then + echo "$ac_t""$CC" 1>&6 +else + echo "$ac_t""no" 1>&6 +fi + ;; + esac + fi test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:603: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:642: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross -cat > conftest.$ac_ext < conftest.$ac_ext << EOF + +#line 653 "configure" #include "confdefs.h" + main(){return(0);} EOF -if { (eval echo configure:617: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:658: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -627,18 +668,24 @@ else ac_cv_prog_cc_works=no fi rm -fr conftest* +ac_ext=c +# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. +ac_cpp='$CPP $CPPFLAGS' +ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' +ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +cross_compiling=$ac_cv_prog_cc_cross echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:637: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:684: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:642: checking whether we are using GNU C" >&5 +echo "configure:689: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -647,7 +694,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:651: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:698: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -658,11 +705,15 @@ echo "$ac_t""$ac_cv_prog_gcc" 1>&6 if test $ac_cv_prog_gcc = yes; then GCC=yes - ac_test_CFLAGS="${CFLAGS+set}" - ac_save_CFLAGS="$CFLAGS" - CFLAGS= - echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:666: checking whether ${CC-cc} accepts -g" >&5 +else + GCC= +fi + +ac_test_CFLAGS="${CFLAGS+set}" +ac_save_CFLAGS="$CFLAGS" +CFLAGS= +echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 +echo "configure:717: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -677,25 +728,29 @@ rm -f conftest* fi echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 - if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" - elif test $ac_cv_prog_cc_g = yes; then +if test "$ac_test_CFLAGS" = set; then + CFLAGS="$ac_save_CFLAGS" +elif test $ac_cv_prog_cc_g = yes; then + if test "$GCC" = yes; then CFLAGS="-g -O2" else - CFLAGS="-O2" + CFLAGS="-g" fi else - GCC= - test "${CFLAGS+set}" = set || CFLAGS="-g" + if test "$GCC" = yes; then + CFLAGS="-O2" + else + CFLAGS= + fi fi echo $ac_n "checking for working const""... $ac_c" 1>&6 -echo "configure:694: checking for working const" >&5 +echo "configure:749: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:803: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else @@ -765,21 +820,21 @@ EOF fi echo $ac_n "checking for inline""... $ac_c" 1>&6 -echo "configure:769: checking for inline" >&5 +echo "configure:824: checking for inline" >&5 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:838: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_inline=$ac_kw; break else @@ -805,19 +860,110 @@ EOF esac +for ac_func in recvmsg +do +echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 +echo "configure:867: checking for $ac_func" >&5 +if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +/* Override any gcc2 internal prototype to avoid an error. */ +/* 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(); + +int main() { + +/* 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 +$ac_func(); +#endif + +; return 0; } +EOF +if { (eval echo configure:895: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_func_$ac_func=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_func_$ac_func=no" +fi +rm -f conftest* +fi + +if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` + cat >> confdefs.h <&6 +fi +done + + +echo $ac_n "checking for msg_control in struct msghdr""... $ac_c" 1>&6 +echo "configure:921: checking for msg_control in struct msghdr" >&5 +cat > conftest.$ac_ext < +#include + +int main() { + + struct msghdr msg; + void *p = (void *) &msg.msg_control; + +; return 0; } +EOF +if { (eval echo configure:936: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + + cat >> confdefs.h <<\EOF +#define HAVE_MSGHDR_MSG_CONTROL 1 +EOF + + echo "$ac_t""yes" 1>&6 + +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + + echo "$ac_t""no" 1>&6 + +fi +rm -f conftest* + echo $ac_n "checking if $CC accepts -Wall""... $ac_c" 1>&6 -echo "configure:810: checking if $CC accepts -Wall" >&5 +echo "configure:956: checking if $CC accepts -Wall" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wall" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:821: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:967: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -829,18 +975,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -W""... $ac_c" 1>&6 -echo "configure:833: checking if $CC accepts -W" >&5 +echo "configure:979: checking if $CC accepts -W" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -W" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:844: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:990: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -852,18 +998,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wpointer-arith""... $ac_c" 1>&6 -echo "configure:856: checking if $CC accepts -Wpointer-arith" >&5 +echo "configure:1002: checking if $CC accepts -Wpointer-arith" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wpointer-arith" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:867: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1013: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -875,18 +1021,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wbad-function-cast""... $ac_c" 1>&6 -echo "configure:879: checking if $CC accepts -Wbad-function-cast" >&5 +echo "configure:1025: checking if $CC accepts -Wbad-function-cast" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wbad-function-cast" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:890: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1036: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -898,18 +1044,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wcast-equal""... $ac_c" 1>&6 -echo "configure:902: checking if $CC accepts -Wcast-equal" >&5 +echo "configure:1048: checking if $CC accepts -Wcast-equal" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wcast-equal" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:913: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1059: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -921,18 +1067,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wstrict-prototypes""... $ac_c" 1>&6 -echo "configure:925: checking if $CC accepts -Wstrict-prototypes" >&5 +echo "configure:1071: checking if $CC accepts -Wstrict-prototypes" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wstrict-prototypes" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:936: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1082: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -944,18 +1090,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wmissing-prototypes""... $ac_c" 1>&6 -echo "configure:948: checking if $CC accepts -Wmissing-prototypes" >&5 +echo "configure:1094: checking if $CC accepts -Wmissing-prototypes" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wmissing-prototypes" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:959: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1105: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -967,18 +1113,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wmissing-declarations""... $ac_c" 1>&6 -echo "configure:971: checking if $CC accepts -Wmissing-declarations" >&5 +echo "configure:1117: checking if $CC accepts -Wmissing-declarations" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wmissing-declarations" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:982: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1128: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -990,18 +1136,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wnested-externs""... $ac_c" 1>&6 -echo "configure:994: checking if $CC accepts -Wnested-externs" >&5 +echo "configure:1140: checking if $CC accepts -Wnested-externs" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wnested-externs" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:1005: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1151: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -1013,18 +1159,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Winline""... $ac_c" 1>&6 -echo "configure:1017: checking if $CC accepts -Winline" >&5 +echo "configure:1163: checking if $CC accepts -Winline" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Winline" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:1028: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1174: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -1036,18 +1182,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -Wcast-align""... $ac_c" 1>&6 -echo "configure:1040: checking if $CC accepts -Wcast-align" >&5 +echo "configure:1186: checking if $CC accepts -Wcast-align" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -Wcast-align" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:1051: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1197: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -1059,18 +1205,18 @@ else fi rm -f conftest* echo $ac_n "checking if $CC accepts -pipe""... $ac_c" 1>&6 -echo "configure:1063: checking if $CC accepts -pipe" >&5 +echo "configure:1209: checking if $CC accepts -pipe" >&5 pa_add_cflags__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -pipe" cat > conftest.$ac_ext < int main() { printf("Hello, World!\n"); ; return 0; } EOF -if { (eval echo configure:1074: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1220: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* echo "$ac_t""yes" 1>&6 else @@ -1083,12 +1229,12 @@ fi rm -f conftest* echo $ac_n "checking for BSD signal semantics""... $ac_c" 1>&6 -echo "configure:1087: checking for BSD signal semantics" >&5 +echo "configure:1233: checking for BSD signal semantics" >&5 if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < @@ -1106,7 +1252,7 @@ int main() { } EOF -if { (eval echo configure:1110: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1256: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then BSD_SIGNAL=1 else @@ -1119,14 +1265,14 @@ fi if test -z "$BSD_SIGNAL"; then echo "$ac_t""no" 1>&6 echo $ac_n "checking if -D__USE_BSD_SIGNAL helps""... $ac_c" 1>&6 -echo "configure:1123: checking if -D__USE_BSD_SIGNAL helps" >&5 +echo "configure:1269: checking if -D__USE_BSD_SIGNAL helps" >&5 pa_bsd_signal__old_cflags="$CFLAGS" CFLAGS="$CFLAGS -D__USE_BSD_SIGNAL" if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < @@ -1144,7 +1290,7 @@ int main() { } EOF -if { (eval echo configure:1148: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1294: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then BSD_SIGNAL=1 else @@ -1158,14 +1304,14 @@ fi echo "$ac_t""no" 1>&6 CFLAGS="$pa_bsd_signal__old_cflags" echo $ac_n "checking if -lbsd helps""... $ac_c" 1>&6 -echo "configure:1162: checking if -lbsd helps" >&5 +echo "configure:1308: checking if -lbsd helps" >&5 pa_bsd_signal__old_libs="$LIBS" LIBS="$LIBS -lbsd" if test "$cross_compiling" = yes; then { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; } else cat > conftest.$ac_ext < @@ -1183,7 +1329,7 @@ int main() { } EOF -if { (eval echo configure:1187: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1333: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then BSD_SIGNAL=1 else @@ -1233,28 +1379,30 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # SunOS /usr/etc/install # IRIX /sbin/install # AIX /bin/install +# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag # AFS /usr/afsws/bin/install, which mishandles nonexistent args # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:1241: checking for a BSD compatible install" >&5 +echo "configure:1388: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:" + IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":" for ac_dir in $PATH; do # Account for people who put trailing slashes in PATH elements. case "$ac_dir/" in /|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. - for ac_prog in ginstall installbsd scoinst install; do + # Don't use installbsd from OSF since it installs stuff as root + # by default. + for ac_prog in ginstall scoinst install; do if test -f $ac_dir/$ac_prog; then if test $ac_prog = install && grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. - # OSF/1 installbsd also uses dspmsg, but is usable. : else ac_cv_path_install="$ac_dir/$ac_prog -c" @@ -1284,9 +1432,12 @@ echo "$ac_t""$INSTALL" 1>&6 # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' +test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}' + test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' + trap '' 1 2 15 cat > confcache <<\EOF # This file is a shell script that caches the results of configure @@ -1310,7 +1461,7 @@ EOF # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. (set) 2>&1 | - case `(ac_space=' '; set) 2>&1` in + case `(ac_space=' '; set | grep ac_space) 2>&1` in *ac_space=\ *) # `set' does not quote correctly, so add quotes (double-quote substitution # turns \\\\ into \\, and sed turns \\ into \). @@ -1350,19 +1501,7 @@ fi trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 -# Transform confdefs.h into DEFS. -# Protect against shell expansion while executing Makefile rules. -# Protect against Makefile macro expansion. -cat > conftest.defs <<\EOF -s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%-D\1=\2%g -s%[ `~#$^&*(){}\\|;'"<>?]%\\&%g -s%\[%\\&%g -s%\]%\\&%g -s%\$%$$%g -EOF -DEFS=`sed -f conftest.defs confdefs.h | tr '\012' ' '` -rm -f conftest.defs - +DEFS=-DHAVE_CONFIG_H # Without the "./", some shells look in PATH for config.status. : ${CONFIG_STATUS=./config.status} @@ -1389,7 +1528,7 @@ do echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.12" + echo "$CONFIG_STATUS generated by autoconf version 2.13" exit 0 ;; -help | --help | --hel | --he | --h) echo "\$ac_cs_usage"; exit 0 ;; @@ -1400,7 +1539,7 @@ done ac_given_srcdir=$srcdir ac_given_INSTALL="$INSTALL" -trap 'rm -fr `echo "MCONFIG" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 +trap 'rm -fr `echo "MCONFIG config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15 EOF cat >> $CONFIG_STATUS < conftest.subs <<\\CEOF $ac_vpsub $extrasub +s%@SHELL@%$SHELL%g s%@CFLAGS@%$CFLAGS%g s%@CPPFLAGS@%$CPPFLAGS%g s%@CXXFLAGS@%$CXXFLAGS%g +s%@FFLAGS@%$FFLAGS%g s%@DEFS@%$DEFS%g s%@LDFLAGS@%$LDFLAGS%g s%@LIBS@%$LIBS%g @@ -1432,6 +1573,7 @@ s%@infodir@%$infodir%g s%@mandir@%$mandir%g s%@CC@%$CC%g s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g +s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g s%@INSTALL_DATA@%$INSTALL_DATA%g CEOF @@ -1533,6 +1675,113 @@ s%@INSTALL@%$INSTALL%g fi; done rm -f conftest.s* +# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where +# NAME is the cpp macro being defined and VALUE is the value it is being given. +# +# ac_d sets the value in "#define NAME VALUE" lines. +ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)' +ac_dB='\([ ][ ]*\)[^ ]*%\1#\2' +ac_dC='\3' +ac_dD='%g' +# ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE". +ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_uB='\([ ]\)%\1#\2define\3' +ac_uC=' ' +ac_uD='\4%g' +# ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE". +ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_eB='$%\1#\2define\3' +ac_eC=' ' +ac_eD='%g' + +if test "${CONFIG_HEADERS+set}" != set; then +EOF +cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF +fi +for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then + # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in". + case "$ac_file" in + *:*) ac_file_in=`echo "$ac_file"|sed 's%[^:]*:%%'` + ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; + *) ac_file_in="${ac_file}.in" ;; + esac + + echo creating $ac_file + + rm -f conftest.frag conftest.in conftest.out + ac_file_inputs=`echo $ac_file_in|sed -e "s%^%$ac_given_srcdir/%" -e "s%:% $ac_given_srcdir/%g"` + cat $ac_file_inputs > conftest.in + +EOF + +# Transform confdefs.h into a sed script conftest.vals that substitutes +# the proper values into config.h.in to produce config.h. And first: +# Protect against being on the right side of a sed subst in config.status. +# Protect against being in an unquoted here document in config.status. +rm -f conftest.vals +cat > conftest.hdr <<\EOF +s/[\\&%]/\\&/g +s%[\\$`]%\\&%g +s%#define \([A-Za-z_][A-Za-z0-9_]*\) *\(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp +s%ac_d%ac_u%gp +s%ac_u%ac_e%gp +EOF +sed -n -f conftest.hdr confdefs.h > conftest.vals +rm -f conftest.hdr + +# This sed command replaces #undef with comments. This is necessary, for +# example, in the case of _POSIX_SOURCE, which is predefined and required +# on some systems where configure will not decide to define it. +cat >> conftest.vals <<\EOF +s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */% +EOF + +# Break up conftest.vals because some shells have a limit on +# the size of here documents, and old seds have small limits too. + +rm -f conftest.tail +while : +do + ac_lines=`grep -c . conftest.vals` + # grep -c gives empty output for an empty file on some AIX systems. + if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi + # Write a limited-size here document to conftest.frag. + echo ' cat > conftest.frag <> $CONFIG_STATUS + sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS + echo 'CEOF + sed -f conftest.frag conftest.in > conftest.out + rm -f conftest.in + mv conftest.out conftest.in +' >> $CONFIG_STATUS + sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail + rm -f conftest.vals + mv conftest.tail conftest.vals +done +rm -f conftest.vals + +cat >> $CONFIG_STATUS <<\EOF + rm -f conftest.frag conftest.h + echo "/* $ac_file. Generated automatically by configure. */" > conftest.h + cat conftest.in >> conftest.h + rm -f conftest.in + if cmp -s $ac_file conftest.h 2>/dev/null; then + echo "$ac_file is unchanged" + rm -f conftest.h + else + # Remove last slash and all that follows it. Not all systems have dirname. + ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` + if test "$ac_dir" != "$ac_file" && test "$ac_dir" != .; then + # The file is in a subdirectory. + test ! -d "$ac_dir" && mkdir "$ac_dir" + fi + rm -f $ac_file + mv conftest.h $ac_file + fi +fi; done + EOF cat >> $CONFIG_STATUS < +#include +], +[ + struct msghdr msg; + void *p = (void *) &msg.msg_control; +], +[ + AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL) + AC_MSG_RESULT([yes]) +], +[ + AC_MSG_RESULT([no]) +]) + PA_ADD_CFLAGS(-Wall) PA_ADD_CFLAGS(-W) PA_ADD_CFLAGS(-Wpointer-arith) @@ -25,4 +45,5 @@ PA_BSD_SIGNAL() AC_PROG_INSTALL +AC_CONFIG_HEADER(config.h) AC_OUTPUT(MCONFIG) diff --git a/tftp/main.c b/tftp/main.c index 42139a7..83da81d 100644 --- a/tftp/main.c +++ b/tftp/main.c @@ -43,6 +43,10 @@ static const char *copyright = static const char *rcsid = "tftp-hpa $Id$"; #endif /* not lint */ +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 256 +#endif + /* Many bug fixes are from Jim Guyton */ /* diff --git a/tftpd/Makefile b/tftpd/Makefile index 73b51ea..f64faab 100644 --- a/tftpd/Makefile +++ b/tftpd/Makefile @@ -3,7 +3,7 @@ all: tftpd include ../MCONFIG include ../MRULES -OBJS = tftpd.o tftpsubs.o +OBJS = tftpd.o tftpsubs.o recvfrom.o tftpd: $(OBJS) $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ diff --git a/tftpd/recvfrom.c b/tftpd/recvfrom.c new file mode 100644 index 0000000..4f3b4b4 --- /dev/null +++ b/tftpd/recvfrom.c @@ -0,0 +1,139 @@ +/* $Id$ */ +/* ----------------------------------------------------------------------- * + * + * Copyright 2001 H. Peter Anvin - All Rights Reserved + * + * This program is free software available under the same license + * as the "OpenBSD" operating system, distributed at + * http://www.openbsd.org/. + * + * ----------------------------------------------------------------------- */ + +/* + * recvfrom.c + * + * Emulate recvfrom() using recvmsg(), but try to capture the local address + * since some TFTP clients consider it an error to get the reply from another + * IP address than the request was sent to. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "../config.h" + +#if defined(HAVE_RECVMSG) && defined(HAVE_MSGHDR_MSG_CONTROL) + +#include + +#ifndef CMSG_LEN +#define CMSG_LEN(size) (sizeof(struct cmsghdr) + (size)) +#endif +#ifndef CMSG_SPACE +#define CMSG_SPACE(size) (sizeof(struct cmsghdr) + (size)) +#endif + +int +myrecvfrom(int s, void *buf, int len, unsigned int flags, + struct sockaddr *from, int *fromlen, + struct sockaddr_in *myaddr) +{ + struct msghdr msg; + struct iovec iov[1]; + int n; + struct cmsghdr *cmptr; + union { + struct cmsghdr cm; +#ifdef IP_PKTINFO + char control[CMSG_SPACE(sizeof(struct in_addr)) + + CMSG_SPACE(sizeof(struct in_pktinfo))]; +#else + char control[CMSG_SPACE(sizeof(struct in_addr))]; +#endif + } control_un; + int on = 1; +#ifdef IP_PKTINFO + struct in_pktinfo pktinfo; +#endif + + /* Try to enable getting the return address */ +#ifdef IP_RECVDSTADDR + setsockopt(s, IPPROTO_IP, IP_RECVDSTADDR, &on, sizeof(on)); +#endif +#ifdef IP_PKTINFO + setsockopt(s, IPPROTO_IP, IP_PKTINFO, &on, sizeof(on)); +#endif + + msg.msg_control = control_un.control; + msg.msg_controllen = sizeof(control_un.control); + msg.msg_flags = 0; + + msg.msg_name = from; + msg.msg_namelen = *fromlen; + iov[0].iov_base = buf; + iov[0].iov_len = len; + msg.msg_iov = iov; + msg.msg_iovlen = 1; + + if ( (n = recvmsg(s, &msg, flags)) < 0 ) + return n; /* Error */ + + *fromlen = msg.msg_namelen; + + if ( myaddr ) { + bzero(myaddr, sizeof(struct sockaddr_in)); + myaddr->sin_family = AF_INET; + + if ( msg.msg_controllen < sizeof(struct cmsghdr) || + (msg.msg_flags & MSG_CTRUNC) ) + return n; /* No information available */ + + for ( cmptr = CMSG_FIRSTHDR(&msg) ; cmptr != NULL ; + cmptr = CMSG_NXTHDR(&msg, cmptr) ) { + +#ifdef IP_RECVSTDADDR + if ( cmptr->cmsg_level == IPPROTO_IP && + cmptr->cmsg_type == IP_RECVDSTADDR ) { + memcpy(&myaddr->sin_addr, CMSG_DATA(cmptr), + sizeof(struct in_addr)); + } +#endif + +#ifdef IP_PKTINFO + if ( cmptr->cmsg_level == IPPROTO_IP && + cmptr->cmsg_type == IP_PKTINFO ) { + memcpy(&pktinfo, CMSG_DATA(cmptr), sizeof(struct in_pktinfo)); + memcpy(&myaddr->sin_addr, &pktinfo.ipi_addr, sizeof(struct in_addr)); + } +#endif + + } + } + + return n; +} + +#else /* pointless... */ + +int +myrecvfrom(int s, void *buf, int len, unsigned int flags, + struct sockaddr *from, int *fromlen, + struct sockaddr_in *myaddr) +{ + /* There is no way we can get the local address, fudge it */ + + bzero(myaddr, sizeof(struct sockaddr_in)); + myaddr->sin_family = AF_INET; + + myaddr->sin_port = htons(IPPORT_TFTP); + bzero(&myaddr->sin_addr, sizeof(myaddr->sin_addr)); + + return recvfrom(s,buf,len,flags,from,fromlen); +} + +#endif diff --git a/tftpd/recvfrom.h b/tftpd/recvfrom.h new file mode 100644 index 0000000..3bb2b39 --- /dev/null +++ b/tftpd/recvfrom.h @@ -0,0 +1,28 @@ +/* $Id$ */ +/* ----------------------------------------------------------------------- * + * + * Copyright 2001 H. Peter Anvin - All Rights Reserved + * + * This program is free software available under the same license + * as the "OpenBSD" operating system, distributed at + * http://www.openbsd.org/. + * + * ----------------------------------------------------------------------- */ + +/* + * recvfrom.h + * + * Header for recvfrom substitute + * + */ + +#include +#include +#include +#include +#include + +int +myrecvfrom(int s, void *buf, int len, unsigned int flags, + struct sockaddr *from, int *fromlen, + struct sockaddr_in *myaddr); diff --git a/tftpd/tftpd.c b/tftpd/tftpd.c index 4d355a6..0bc56a4 100644 --- a/tftpd/tftpd.c +++ b/tftpd/tftpd.c @@ -73,6 +73,7 @@ static const char *rcsid = "tftp-hpa $Id$"; #include #include "tftpsubs.h" +#include "recvfrom.h" #define TIMEOUT 5 /* Default timeout (seconds) */ #define TRIES 4 /* Number of attempts to send each packet */ @@ -87,7 +88,6 @@ static const char *rcsid = "tftp-hpa $Id$"; extern int errno; extern char *__progname; -struct sockaddr_in s_in = { AF_INET }; int peer; int timeout = TIMEOUT; int rexmtval = TIMEOUT; @@ -147,6 +147,7 @@ main(int argc, char **argv) struct tftphdr *tp; struct passwd *pw; struct options *opt; + struct sockaddr_in myaddr; int n = 0; int on = 1; int fd = 0; @@ -232,8 +233,9 @@ main(int argc, char **argv) exit(1); } fromlen = sizeof (from); - n = recvfrom(fd, buf, sizeof (buf), 0, - (struct sockaddr *)&from, &fromlen); + n = myrecvfrom(fd, buf, sizeof (buf), 0, + (struct sockaddr *)&from, &fromlen, + &myaddr); if (n < 0) { syslog(LOG_ERR, "recvfrom: %m"); exit(1); @@ -267,8 +269,8 @@ main(int argc, char **argv) * a single request from a single client. */ j = sizeof from; - i = recvfrom(fd, buf, sizeof (buf), 0, - (struct sockaddr *)&from, &j); + i = myrecvfrom(fd, buf, sizeof (buf), 0, + (struct sockaddr *)&from, &j, &myaddr); if (i > 0) { n = i; fromlen = j; @@ -291,7 +293,8 @@ main(int argc, char **argv) syslog(LOG_ERR, "socket: %m"); exit(1); } - if (bind(peer, (struct sockaddr *)&s_in, sizeof (s_in)) < 0) { + myaddr.sin_port = htons(0); /* We want a new local port */ + if (bind(peer, (struct sockaddr *)&myaddr, sizeof (myaddr)) < 0) { syslog(LOG_ERR, "bind: %m"); exit(1); }