shivansh/dummynet-ipfw

Fix build on FreeBSD

shivansh opened this issue · 2 comments

make on FreeBSD terminates with following trace -
Note: gcc version 4.9.4

gmake
gmake[1]: Entering directory '/usr/home/zeebsd/source-codes/dummynet-ipfw'
Building userspace ...
gmake[2]: Entering directory '/usr/home/zeebsd/source-codes/dummynet-ipfw/ipfw'
   CC ipfw2.c
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:77:24: note: expanded from macro '__bswap32'
        (__builtin_constant_p(x) ?      \
                              ^
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:78:33: note: expanded from macro '__bswap32'
            __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
                                       ^
/usr/include/x86/endian.h:68:27: note: expanded from macro '__bswap32_gen'
        (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
                                 ^
/usr/include/x86/endian.h:74:37: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                                           ^
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:78:33: note: expanded from macro '__bswap32'
            __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
                                       ^
/usr/include/x86/endian.h:68:27: note: expanded from macro '__bswap32_gen'
        (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
                                 ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:40: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                              ^
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:78:33: note: expanded from macro '__bswap32'
            __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
                                       ^
/usr/include/x86/endian.h:68:27: note: expanded from macro '__bswap32_gen'
        (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
                                 ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:51: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                                         ^
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:78:33: note: expanded from macro '__bswap32'
            __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
                                       ^
/usr/include/x86/endian.h:68:60: note: expanded from macro '__bswap32_gen'
        (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
                                                                  ^
/usr/include/x86/endian.h:74:37: note: expanded from macro '__bswap16'
        ((__uint16_t)(__builtin_constant_p(x) ? \
                                           ^
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:78:33: note: expanded from macro '__bswap32'
            __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
                                       ^
/usr/include/x86/endian.h:68:60: note: expanded from macro '__bswap32_gen'
        (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
                                                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:40: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                              ^
ipfw2.c:2856:19: error: shifting a negative signed value is undefined
      [-Werror,-Wshift-negative-value]
                d[1] = htonl(~0 << (32 - 24));
                             ~~ ^
/usr/include/netinet/in.h:117:26: note: expanded from macro 'htonl'
#define htonl(x)        __htonl(x)
                                ^
/usr/include/x86/endian.h:126:30: note: expanded from macro '__htonl'
#define __htonl(x)      __bswap32(x)
                                  ^
/usr/include/x86/endian.h:78:33: note: expanded from macro '__bswap32'
            __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
                                       ^
/usr/include/x86/endian.h:68:60: note: expanded from macro '__bswap32_gen'
        (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
                                                                  ^
/usr/include/x86/endian.h:75:33: note: expanded from macro '__bswap16'
            __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
                                       ^
/usr/include/x86/endian.h:66:51: note: expanded from macro '__bswap16_gen'
#define __bswap16_gen(x)        (__uint16_t)((x) << 8 | (x) >> 8)
                                                         ^
7 errors generated.
gmake[2]: *** [../Makefile.inc:28: ipfw2.o] Error 1
gmake[2]: Leaving directory '/usr/home/zeebsd/source-codes/dummynet-ipfw/ipfw'
gmake[1]: *** [Makefile:17: ipfw] Error 2
gmake[1]: Leaving directory '/usr/home/zeebsd/source-codes/dummynet-ipfw'
*** Error code 2

Stop.
make: stopped in /usr/home/zeebsd/source-codes/dummynet-ipfw

Changing htonl(~0 << (32 - 24)) to htonl(~0UL << (32 - 24)) would fix that.

Thanks for the help.