Darren Reed wrote:

Looking through ip.c for the refactor review, I found this gem;

5900 ip_net_mask(ipaddr_t addr)
5901 {
5902         uchar_t *up = (uchar_t *)&addr;
5903         ipaddr_t mask = 0;
5904         uchar_t *maskp = (uchar_t *)&mask;
5905 5906 #if defined(__i386) || defined(__amd64)
5907 #define TOTALLY_BRAIN_DAMAGED_C_COMPILER
5908 #endif
5909 #ifdef  TOTALLY_BRAIN_DAMAGED_C_COMPILER
5910         maskp[0] = maskp[1] = maskp[2] = maskp[3] = 0;
5911 #endif


It predates the refactoring project so I'm reluctant to mention it here
but has anyone attempted to confirm if the above is still requried?

It looks like a workaround for an optimisation bug?


To test if this was still a problem, I used the following:

$ /ws/onnv-tools/SUNWspro/SS12/bin/cc -m64 -Ui386 -U__i386 -xO3 -D_ASM_INLINES -Xa -xspace -Wu,-save_args -v -xildoff -g -xc99=%all -W0,-noglobal -xdebugformat=stabs -errtags=yes -errwarn=%all -W0,-xglobalstatic -xstrconst -xinline=tcp_set_ws_value -D_SYSCALL32 -D_SYSCALL32_IMPL -D_ELF64 -D_DDI_STRICT -Dsun -D__sun -D__SVR4 foo.c -lnsl
$ ./a.out 1.2.3.4 224.1.1.1 192.168.1.1 129.1.1.1
255.0.0.0
240.0.0.0
255.255.255.0
255.255.0.0

$ cat foo.c
#include <stdio.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>

#ifdef  _BIG_ENDIAN
#define N_IN_CLASSA_NET         IN_CLASSA_NET
#define N_IN_CLASSD_NET         IN_CLASSD_NET
#define N_INADDR_UNSPEC_GROUP   INADDR_UNSPEC_GROUP
#define N_IN_LOOPBACK_NET       (ipaddr_t)0x7f000000U
#else /* _BIG_ENDIAN */
#define N_IN_CLASSA_NET         (ipaddr_t)0x000000ffU
#define N_IN_CLASSD_NET         (ipaddr_t)0x000000f0U
#define N_INADDR_UNSPEC_GROUP   (ipaddr_t)0x000000e0U
#define N_IN_LOOPBACK_NET       (ipaddr_t)0x0000007fU
#endif /* _BIG_ENDIAN */
#define CLASSD(addr) (((addr) & N_IN_CLASSD_NET) == N_INADDR_UNSPEC_GROUP)
#define CLASSE(addr)    (((addr) & N_IN_CLASSD_NET) == N_IN_CLASSD_NET)
#define IP_LOOPBACK_ADDR(addr)                  \
       (((addr) & N_IN_CLASSA_NET == N_IN_LOOPBACK_NET))

/*
* Return the network mask
* associated with the specified address.
*/
ipaddr_t
ip_net_mask(ipaddr_t addr)
{
       uchar_t *up = (uchar_t *)&addr;
       ipaddr_t mask = 0;
       uchar_t *maskp = (uchar_t *)&mask;

#if defined(__i386) || defined(__amd64)
#define TOTALLY_BRAIN_DAMAGED_C_COMPILERX
#endif
#ifdef  TOTALLY_BRAIN_DAMAGED_C_COMPILER
       maskp[0] = maskp[1] = maskp[2] = maskp[3] = 0;
#endif
       if (CLASSD(addr)) {
               maskp[0] = 0xF0;
               return (mask);
       }

       /* We assume Class E default netmask to be 32 */
       if (CLASSE(addr))
               return (0xffffffffU);

       if (addr == 0)
               return (0);
       maskp[0] = 0xFF;
       if ((up[0] & 0x80) == 0)
               return (mask);

       maskp[1] = 0xFF;
       if ((up[0] & 0xC0) == 0x80)
               return (mask);

       maskp[2] = 0xFF;
       if ((up[0] & 0xE0) == 0xC0)
               return (mask);

       /* Otherwise return no mask */
       return ((ipaddr_t)0);
}

int
main(int argc, char *argv[])
{
       struct in_addr ip;
       ipaddr_t in;

       while (argc > 1) {
               inet_pton(AF_INET, argv[1], &in);
               ip.s_addr = ip_net_mask(in);
               printf("%s\n", inet_ntoa(ip));
               argc--;
               argv++;
       }

       return (0);
}

Looks safe for removal... comments on compiling?

Darren

_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to