traceroute: fix compilation if netinet/protocols.h is missing

This commit is contained in:
Denis Vlasenko 2006-10-03 18:19:02 +00:00
parent f0a97fb43a
commit 6edaddec02

View File

@ -204,27 +204,11 @@
#undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP #undef CONFIG_FEATURE_TRACEROUTE_USE_ICMP
//#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP //#define CONFIG_FEATURE_TRACEROUTE_USE_ICMP
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <endian.h>
#include <getopt.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/select.h>
#include "inet_common.h" #include "inet_common.h"
#include <net/if.h> #include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/protocols.h> #include <netinet/in.h>
#include <netinet/udp.h> #include <netinet/udp.h>
#include <netinet/ip.h> #include <netinet/ip.h>
#include <netinet/ip_icmp.h> #include <netinet/ip_icmp.h>
@ -238,6 +222,14 @@
*/ */
#define IPVERSION 4 #define IPVERSION 4
#ifndef IPPROTO_ICMP
/* Grrrr.... */
#define IPPROTO_ICMP 1
#endif
#ifndef IPPROTO_IP
#define IPPROTO_IP 0
#endif
/* /*
* Overlay for ip header used by other protocols (tcp, udp). * Overlay for ip header used by other protocols (tcp, udp).
*/ */
@ -1080,7 +1072,7 @@ traceroute_main(int argc, char *argv[])
if (n > 2) if (n > 2)
close(n); close(n);
s = xsocket(AF_INET, SOCK_RAW, IP_ICMP); s = xsocket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG #ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
if (op & USAGE_OP_DEBUG) if (op & USAGE_OP_DEBUG)
@ -1098,10 +1090,6 @@ traceroute_main(int argc, char *argv[])
if (lsrr > 0) { if (lsrr > 0) {
unsigned char optlist[MAX_IPOPTLEN]; unsigned char optlist[MAX_IPOPTLEN];
cp = "ip";
if ((pe = getprotobyname(cp)) == NULL)
bb_perror_msg_and_die("unknown protocol");
/* final hop */ /* final hop */
gwlist[lsrr] = to->sin_addr.s_addr; gwlist[lsrr] = to->sin_addr.s_addr;
++lsrr; ++lsrr;
@ -1116,7 +1104,7 @@ traceroute_main(int argc, char *argv[])
optlist[3] = IPOPT_MINOFF; optlist[3] = IPOPT_MINOFF;
memcpy(optlist + 4, gwlist, i); memcpy(optlist + 4, gwlist, i);
if ((setsockopt(sndsock, pe->p_proto, IP_OPTIONS, if ((setsockopt(sndsock, IPPROTO_IP, IP_OPTIONS,
(char *)optlist, i + sizeof(gwlist[0]))) < 0) { (char *)optlist, i + sizeof(gwlist[0]))) < 0) {
bb_perror_msg_and_die("IP_OPTIONS"); bb_perror_msg_and_die("IP_OPTIONS");
} }