X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/102fa2f087554901001abcd106160a4ea0668206..HEAD:/pathmtu/pathmtu.c diff --git a/pathmtu/pathmtu.c b/pathmtu/pathmtu.c index 4eba80d6..9c5c8294 100644 --- a/pathmtu/pathmtu.c +++ b/pathmtu/pathmtu.c @@ -51,9 +51,11 @@ #include #include -#include -#include -#include +#ifdef HAVE_GETIFADDRS +# include +# include +# include +#endif #include #include @@ -132,23 +134,6 @@ static size_t addrsz(const union addr *a) } } -/* Compare two addresses. Maybe compare the port numbers too. */ -#define AEF_PORT 1u -static int addreq(const union addr *a, const union addr *b, unsigned f) -{ - switch (a->sa.sa_family) { - case AF_INET: - return (a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr && - (!(f&AEF_PORT) || a->sin.sin_port == b->sin.sin_port)); - case AF_INET6: - return (!memcmp(a->sin6.sin6_addr.s6_addr, - b->sin6.sin6_addr.s6_addr, 16) && - (!(f&AEF_PORT) || a->sin6.sin6_port == b->sin6.sin6_port)); - default: - abort(); - } -} - /*----- Main algorithm skeleton -------------------------------------------*/ struct param { @@ -403,8 +388,10 @@ fail_0: /*----- Doing it the hard way ---------------------------------------------*/ +#ifdef HAVE_GETIFADDRS + #if defined(linux) || defined(__OpenBSD__) -#define IPHDR_SANE +# define IPHDR_SANE #endif #ifdef IPHDR_SANE @@ -420,6 +407,23 @@ static int rawicmp6 = -1, rawudp6 = -1, rawerr6 = 0; #define IPCK_INIT 0xffff +/* Compare two addresses. Maybe compare the port numbers too. */ +#define AEF_PORT 1u +static int addreq(const union addr *a, const union addr *b, unsigned f) +{ + switch (a->sa.sa_family) { + case AF_INET: + return (a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr && + (!(f&AEF_PORT) || a->sin.sin_port == b->sin.sin_port)); + case AF_INET6: + return (!memcmp(a->sin6.sin6_addr.s6_addr, + b->sin6.sin6_addr.s6_addr, 16) && + (!(f&AEF_PORT) || a->sin6.sin6_port == b->sin6.sin6_port)); + default: + abort(); + } +} + /* Compute an IP checksum over some data. This is a restartable interface: * initialize A to `IPCK_INIT' for the first call. */ @@ -794,6 +798,8 @@ static const struct probe_ops raw_ops = { #undef OPS_CHAIN #define OPS_CHAIN &raw_ops +#endif + /*----- Doing the job on Linux --------------------------------------------*/ #if defined(linux) @@ -963,12 +969,14 @@ int main(int argc, char *argv[]) #define f_bogus 1u +#ifdef HAVE_GETIFADDRS if ((rawicmp = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0 || (rawudp = socket(PF_INET, SOCK_RAW, IPPROTO_UDP)) < 0) rawerr = errno; if ((rawicmp6 = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0 || (rawudp6 = socket(PF_INET6, SOCK_RAW, IPPROTO_RAW)) < 0) rawerr6 = errno; +#endif if (setuid(getuid())) abort();