--- embedaddon/mtr/packet/wait_unix.c 2019/10/21 14:25:31 1.1.1.1 +++ embedaddon/mtr/packet/wait_unix.c 2021/03/17 00:07:30 1.1.1.2 @@ -11,15 +11,20 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "wait.h" #include #include +#ifdef HAVE_ERROR_H +#include +#else +#include "portability/error.h" +#endif #include #include #include @@ -39,8 +44,8 @@ int gather_read_fds( { int nfds; int probe_nfds; - int ip4_socket = net_state->platform.ip4_recv_socket; - int ip6_socket = net_state->platform.ip6_recv_socket; + int ip4_socket; + int ip6_socket; int command_stream = command_buffer->command_stream; FD_ZERO(read_set); @@ -49,14 +54,42 @@ int gather_read_fds( FD_SET(command_stream, read_set); nfds = command_stream + 1; - FD_SET(ip4_socket, read_set); - if (ip4_socket >= nfds) { - nfds = ip4_socket + 1; + if (net_state->platform.ip4_socket_raw) { + ip4_socket = net_state->platform.ip4_recv_socket; + FD_SET(ip4_socket, read_set); + if (ip4_socket >= nfds) { + nfds = ip4_socket + 1; + } + } else { + ip4_socket = net_state->platform.ip4_txrx_icmp_socket; + FD_SET(ip4_socket, read_set); + if (ip4_socket >= nfds) { + nfds = ip4_socket + 1; + } + ip4_socket = net_state->platform.ip4_txrx_udp_socket; + FD_SET(ip4_socket, read_set); + if (ip4_socket >= nfds) { + nfds = ip4_socket + 1; + } } - FD_SET(ip6_socket, read_set); - if (ip6_socket >= nfds) { - nfds = ip6_socket + 1; + if (net_state->platform.ip6_socket_raw) { + ip6_socket = net_state->platform.ip6_recv_socket; + FD_SET(ip6_socket, read_set); + if (ip6_socket >= nfds) { + nfds = ip6_socket + 1; + } + } else { + ip6_socket = net_state->platform.ip6_txrx_icmp_socket; + FD_SET(ip6_socket, read_set); + if (ip6_socket >= nfds) { + nfds = ip6_socket + 1; + } + ip6_socket = net_state->platform.ip6_txrx_udp_socket; + FD_SET(ip6_socket, read_set); + if (ip6_socket >= nfds) { + nfds = ip6_socket + 1; + } } probe_nfds = gather_probe_sockets(net_state, write_set); @@ -71,7 +104,7 @@ int gather_read_fds( Sleep until we receive a new probe response, a new command on the command stream, or a probe timeout. On Unix systems, this means we use select to wait on file descriptors for the command stream - and the raw recieve socket. + and the raw receive socket. */ void wait_for_activity( struct command_buffer_t *command_buffer, @@ -116,8 +149,7 @@ void wait_for_activity( */ if (errno != EINTR && errno != EAGAIN) { /* We don't expect other errors, so report them */ - perror("unexpected select error"); - exit(EXIT_FAILURE); + error(EXIT_FAILURE, errno, "unexpected select error"); } } }