Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/networking/traceroute.c

    r3232 r3621  
    212212
    213213//usage:#define traceroute_trivial_usage
    214 //usage:       "[-"IF_TRACEROUTE6("46")"FIldnrv] [-f 1ST_TTL] [-m MAXTTL] [-p PORT] [-q PROBES]\n"
    215 //usage:       "    [-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-g GATEWAY] [-i IFACE]\n"
     214//usage:       "[-"IF_TRACEROUTE6("46")"FIlnrv] [-f 1ST_TTL] [-m MAXTTL] [-q PROBES] [-p PORT]\n"
     215//usage:       "    [-t TOS] [-w WAIT_SEC]"
     216//usage:       IF_FEATURE_TRACEROUTE_SOURCE_ROUTE(" [-g GATEWAY]")" [-s SRC_IP] [-i IFACE]\n"
    216217//usage:       "    [-z PAUSE_MSEC] HOST [BYTES]"
    217218//usage:#define traceroute_full_usage "\n\n"
     
    220221//usage:     "\n    -4,-6   Force IP or IPv6 name resolution"
    221222//usage:    )
    222 //usage:     "\n    -F  Set the don't fragment bit"
     223//usage:     "\n    -F  Set don't fragment bit"
     224//usage:    IF_FEATURE_TRACEROUTE_USE_ICMP(
    223225//usage:     "\n    -I  Use ICMP ECHO instead of UDP datagrams"
    224 //usage:     "\n    -l  Display the TTL value of the returned packet"
    225 //usage:     "\n    -d  Set SO_DEBUG options to socket"
     226//usage:    )
     227//usage:     "\n    -l  Display TTL value of the returned packet"
     228//Currently disabled (TRACEROUTE_SO_DEBUG==0)
     229////usage:     "\n  -d  Set SO_DEBUG options to socket"
    226230//usage:     "\n    -n  Print numeric addresses"
    227231//usage:     "\n    -r  Bypass routing tables, send directly to HOST"
     232//usage:    IF_FEATURE_TRACEROUTE_VERBOSE(
    228233//usage:     "\n    -v  Verbose"
    229 //usage:     "\n    -m  Max time-to-live (max number of hops)"
    230 //usage:     "\n    -p  Base UDP port number used in probes"
     234//usage:    )
     235//usage:     "\n    -f N    First number of hops (default 1)"
     236//usage:     "\n    -m N    Max number of hops"
     237//usage:     "\n    -q N    Number of probes per hop (default 3)"
     238//usage:     "\n    -p N    Base UDP port number used in probes"
    231239//usage:     "\n        (default 33434)"
    232 //usage:     "\n    -q  Number of probes per TTL (default 3)"
    233 //usage:     "\n    -s  IP address to use as the source address"
    234 //usage:     "\n    -t  Type-of-service in probe packets (default 0)"
    235 //usage:     "\n    -w  Time in seconds to wait for a response (default 3)"
    236 //usage:     "\n    -g  Loose source route gateway (8 max)"
     240//usage:     "\n    -s IP   Source address"
     241//usage:     "\n    -i IFACE Source interface"
     242//usage:     "\n    -t N    Type-of-service in probe packets (default 0)"
     243//usage:     "\n    -w SEC  Time to wait for a response (default 3)"
     244//usage:     "\n    -g IP   Loose source route gateway (8 max)"
    237245//usage:
    238246//usage:#define traceroute6_trivial_usage
    239 //usage:       "[-dnrv] [-m MAXTTL] [-p PORT] [-q PROBES]\n"
    240 //usage:       "    [-s SRC_IP] [-t TOS] [-w WAIT_SEC] [-i IFACE]\n"
     247//usage:       "[-nrv] [-m MAXTTL] [-q PROBES] [-p PORT]\n"
     248//usage:       "    [-t TOS] [-w WAIT_SEC] [-s SRC_IP] [-i IFACE]\n"
    241249//usage:       "    HOST [BYTES]"
    242250//usage:#define traceroute6_full_usage "\n\n"
    243251//usage:       "Trace the route to HOST\n"
    244 //usage:     "\n    -d  Set SO_DEBUG options to socket"
     252//Currently disabled (TRACEROUTE_SO_DEBUG==0)
     253////usage:     "\n  -d  Set SO_DEBUG options to socket"
    245254//usage:     "\n    -n  Print numeric addresses"
    246255//usage:     "\n    -r  Bypass routing tables, send directly to HOST"
     256//usage:    IF_FEATURE_TRACEROUTE_VERBOSE(
    247257//usage:     "\n    -v  Verbose"
    248 //usage:     "\n    -m  Max time-to-live (max number of hops)"
    249 //usage:     "\n    -p  Base UDP port number used in probes"
    250 //usage:     "\n        (default is 33434)"
    251 //usage:     "\n    -q  Number of probes per TTL (default 3)"
    252 //usage:     "\n    -s  IP address to use as the source address"
    253 //usage:     "\n    -t  Type-of-service in probe packets (default 0)"
    254 //usage:     "\n    -w  Time in seconds to wait for a response (default 3)"
     258//usage:    )
     259//usage:     "\n    -m N    Max number of hops"
     260//usage:     "\n    -q N    Number of probes per hop (default 3)"
     261//usage:     "\n    -p N    Base UDP port number used in probes"
     262//usage:     "\n        (default 33434)"
     263//usage:     "\n    -s IP   Source address"
     264//usage:     "\n    -i IFACE Source interface"
     265//usage:     "\n    -t N    Type-of-service in probe packets (default 0)"
     266//usage:     "\n    -w SEC  Time wait for a response (default 3)"
    255267
    256268#define TRACEROUTE_SO_DEBUG 0
    257 
    258 /* TODO: undefs were uncommented - ??! we have config system for that! */
    259 /* probably ok to remove altogether */
    260 //#undef CONFIG_FEATURE_TRACEROUTE_VERBOSE
    261 //#define CONFIG_FEATURE_TRACEROUTE_VERBOSE
    262 //#undef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
    263 //#define CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
    264 //#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP
    265 //#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP
    266 
    267269
    268270#include <net/if.h>
     
    388390
    389391
    390 /* libbb candidate? tftp uses this idiom too */
    391 static len_and_sockaddr* dup_sockaddr(const len_and_sockaddr *lsa)
    392 {
    393     len_and_sockaddr *new_lsa = xzalloc(LSA_LEN_SIZE + lsa->len);
    394     memcpy(new_lsa, lsa, LSA_LEN_SIZE + lsa->len);
    395     return new_lsa;
    396 }
    397 
    398 
    399392static int
    400393wait_for_reply(len_and_sockaddr *from_lsa, struct sockaddr *to, unsigned *timestamp_us, int *left_ms)
     
    481474#if ENABLE_TRACEROUTE6
    482475    if (dest_lsa->u.sa.sa_family == AF_INET6) {
    483         res = setsockopt(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl));
    484         if (res < 0)
    485             bb_perror_msg_and_die("setsockopt UNICAST_HOPS %d", ttl);
     476        res = setsockopt_int(sndsock, SOL_IPV6, IPV6_UNICAST_HOPS, ttl);
     477        if (res != 0)
     478            bb_perror_msg_and_die("setsockopt(%s) %d", "UNICAST_HOPS", ttl);
    486479        out = outip;
    487480        len = packlen;
     
    490483    {
    491484#if defined IP_TTL
    492         res = setsockopt(sndsock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl));
    493         if (res < 0)
    494             bb_perror_msg_and_die("setsockopt ttl %d", ttl);
     485        res = setsockopt_int(sndsock, IPPROTO_IP, IP_TTL, ttl);
     486        if (res != 0)
     487            bb_perror_msg_and_die("setsockopt(%s) %d", "TTL", ttl);
    495488#endif
    496489        out = outicmp;
     
    505498    res = xsendto(sndsock, out, len, &dest_lsa->u.sa, dest_lsa->len);
    506499    if (res != len)
    507         bb_info_msg("sent %d octets, ret=%d", len, res);
     500        bb_error_msg("sent %d octets, ret=%d", len, res);
    508501}
    509502
     
    792785{
    793786    int minpacket;
     787#ifdef IP_TOS
    794788    int tos = 0;
     789#endif
    795790    int max_ttl = 30;
    796791    int nprobes = 3;
     
    806801    char *pausemsecs_str;
    807802    char *first_ttl_str;
     803    char *dest_str;
    808804#if ENABLE_FEATURE_TRACEROUTE_SOURCE_ROUTE
    809805    llist_t *source_route_list = NULL;
     
    838834        bb_error_msg("warning: ip checksums disabled");
    839835#endif
     836#ifdef IP_TOS
    840837    if (op & OPT_TOS)
    841838        tos = xatou_range(tos_str, 0, 255);
     839#endif
    842840    if (op & OPT_MAX_TTL)
    843841        max_ttl = xatou_range(max_ttl_str, 1, 255);
     
    905903        xmove_fd(xsocket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6), rcvsock);
    906904# ifdef IPV6_RECVPKTINFO
    907         setsockopt(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO,
    908                 &const_int_1, sizeof(const_int_1));
    909         setsockopt(rcvsock, SOL_IPV6, IPV6_2292PKTINFO,
    910                 &const_int_1, sizeof(const_int_1));
     905        setsockopt_1(rcvsock, SOL_IPV6, IPV6_RECVPKTINFO);
     906        setsockopt_1(rcvsock, SOL_IPV6, IPV6_2292PKTINFO);
    911907# else
    912         setsockopt(rcvsock, SOL_IPV6, IPV6_PKTINFO,
    913                 &const_int_1, sizeof(const_int_1));
     908        setsockopt_1(rcvsock, SOL_IPV6, IPV6_PKTINFO);
    914909# endif
    915910    } else
     
    921916#if TRACEROUTE_SO_DEBUG
    922917    if (op & OPT_DEBUG)
    923         setsockopt(rcvsock, SOL_SOCKET, SO_DEBUG,
    924                 &const_int_1, sizeof(const_int_1));
     918        setsockopt_SOL_SOCKET_1(rcvsock, SO_DEBUG);
    925919#endif
    926920    if (op & OPT_BYPASS_ROUTE)
    927         setsockopt(rcvsock, SOL_SOCKET, SO_DONTROUTE,
    928                 &const_int_1, sizeof(const_int_1));
     921        setsockopt_SOL_SOCKET_1(rcvsock, SO_DONTROUTE);
    929922
    930923#if ENABLE_TRACEROUTE6
    931924    if (af == AF_INET6) {
    932         static const int two = 2;
    933         if (setsockopt(rcvsock, SOL_RAW, IPV6_CHECKSUM, &two, sizeof(two)) < 0)
    934             bb_perror_msg_and_die("setsockopt RAW_CHECKSUM");
     925        if (setsockopt_int(rcvsock, SOL_RAW, IPV6_CHECKSUM, 2) != 0)
     926            bb_perror_msg_and_die("setsockopt(%s)", "IPV6_CHECKSUM");
    935927        xmove_fd(xsocket(af, SOCK_DGRAM, 0), sndsock);
    936928    } else
     
    969961
    970962#ifdef SO_SNDBUF
    971     if (setsockopt(sndsock, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(packlen)) < 0) {
    972         bb_perror_msg_and_die("SO_SNDBUF");
     963    if (setsockopt_SOL_SOCKET_int(sndsock, SO_SNDBUF, packlen) != 0) {
     964        bb_perror_msg_and_die("setsockopt(%s)", "SO_SNDBUF");
    973965    }
    974966#endif
    975967#ifdef IP_TOS
    976     if ((op & OPT_TOS) && setsockopt(sndsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) {
    977         bb_perror_msg_and_die("setsockopt tos %d", tos);
     968    if ((op & OPT_TOS) && setsockopt_int(sndsock, IPPROTO_IP, IP_TOS, tos) != 0) {
     969        bb_perror_msg_and_die("setsockopt(%s) %d", "TOS", tos);
    978970    }
    979971#endif
    980972#ifdef IP_DONTFRAG
    981973    if (op & OPT_DONT_FRAGMNT)
    982         setsockopt(sndsock, IPPROTO_IP, IP_DONTFRAG,
    983                 &const_int_1, sizeof(const_int_1));
     974        setsockopt_1(sndsock, IPPROTO_IP, IP_DONTFRAG);
    984975#endif
    985976#if TRACEROUTE_SO_DEBUG
    986977    if (op & OPT_DEBUG)
    987         setsockopt(sndsock, SOL_SOCKET, SO_DEBUG,
    988                 &const_int_1, sizeof(const_int_1));
     978        setsockopt_SOL_SOCKET_1(sndsock, SO_DEBUG);
    989979#endif
    990980    if (op & OPT_BYPASS_ROUTE)
    991         setsockopt(sndsock, SOL_SOCKET, SO_DONTROUTE,
    992                 &const_int_1, sizeof(const_int_1));
     981        setsockopt_SOL_SOCKET_1(sndsock, SO_DONTROUTE);
    993982
    994983    outip = xzalloc(packlen);
     
    10601049    xsetuid(getuid());
    10611050
    1062     printf("traceroute to %s (%s)", argv[0],
    1063             xmalloc_sockaddr2dotted_noport(&dest_lsa->u.sa));
     1051    dest_str = xmalloc_sockaddr2dotted_noport(&dest_lsa->u.sa);
     1052    printf("traceroute to %s (%s)", argv[0], dest_str);
     1053    if (ENABLE_FEATURE_CLEAN_UP) {
     1054        free(dest_str);
     1055    }
     1056
    10641057    if (op & OPT_SOURCE)
    10651058        printf(" from %s", source);
    10661059    printf(", %d hops max, %d byte packets\n", max_ttl, packlen);
    10671060
    1068     from_lsa = dup_sockaddr(dest_lsa);
     1061    from_lsa = xmemdup(dest_lsa, LSA_LEN_SIZE + dest_lsa->len);
    10691062    lastaddr = xzalloc(dest_lsa->len);
    10701063    to = xzalloc(dest_lsa->len);
     
    12171210    }
    12181211
     1212    if (ENABLE_FEATURE_CLEAN_UP) {
     1213        free(to);
     1214        free(lastaddr);
     1215        free(from_lsa);
     1216    }
     1217
    12191218    return 0;
    12201219}
Note: See TracChangeset for help on using the changeset viewer.