Fix -Wstrict-aliasing messages

Moving from uint32 -> struct in_addr
This commit is contained in:
Job Snijders
2021-08-17 22:16:56 +00:00
parent b816c1023b
commit 32a3520e62

View File

@@ -1306,10 +1306,12 @@ checkSon:
static void static void
bgpq4_print_ceacl(struct sx_radix_node *n, void *ff) bgpq4_print_ceacl(struct sx_radix_node *n, void *ff)
{ {
char prefix[128]; char prefix[128];
FILE *f = (FILE*)ff; FILE *f = (FILE*)ff;
char *c; char *c;
uint32_t netmask = 0xfffffffful; struct in_addr netmask;
netmask.s_addr = 0xfffffffful;
if (!f) if (!f)
f = stdout; f = stdout;
@@ -1324,65 +1326,64 @@ bgpq4_print_ceacl(struct sx_radix_node *n, void *ff)
if (c) if (c)
*c = 0; *c = 0;
if (n->prefix->masklen == 32) { if (n->prefix->masklen == 32)
netmask = 0; netmask.s_addr = 0;
} else { else {
netmask <<= (32 - n->prefix->masklen); netmask.s_addr <<= (32 - n->prefix->masklen);
netmask &= 0xfffffffful; netmask.s_addr &= 0xfffffffful;
} }
netmask = htonl(netmask);
netmask.s_addr = htonl(netmask.s_addr);
if (n->isAggregate) { if (n->isAggregate) {
unsigned long mask = 0xfffffffful, wildaddr, wild2addr, wildmask; struct in_addr mask, wildaddr, wild2addr, wildmask;
int masklen = n->aggregateLow; int masklen = n->aggregateLow;
wildaddr = 0xfffffffful >> n->prefix->masklen;
if (n->aggregateHi == 32) { mask.s_addr = 0xfffffffful;
wild2addr = 0; wildaddr.s_addr = 0xfffffffful >> n->prefix->masklen;
} else {
wild2addr = 0xfffffffful >> n->aggregateHi;
}
wildaddr = wildaddr &(~wild2addr);
if (masklen == 32)
mask = 0xfffffffful;
else
mask = 0xfffffffful & (0xfffffffful << (32 - masklen));
if (n->aggregateHi == 32) if (n->aggregateHi == 32)
wild2addr = 0; wild2addr.s_addr = 0;
else else
wild2addr = 0xfffffffful >> n->aggregateHi; wild2addr.s_addr = 0xfffffffful >> n->aggregateHi;
wildmask = (0xfffffffful >> n->aggregateLow) & (~wild2addr); wildaddr.s_addr = wildaddr.s_addr & (~wild2addr.s_addr);
mask = htonl(mask); if (masklen == 32)
wildaddr = htonl(wildaddr); mask.s_addr = 0xfffffffful;
wildmask = htonl(wildmask); else
mask.s_addr = 0xfffffffful & (0xfffffffful << (32 - masklen));
if (wildaddr) { if (n->aggregateHi == 32)
fprintf(f, " permit ip %s ", wild2addr.s_addr = 0;
else
wild2addr.s_addr = 0xfffffffful >> n->aggregateHi;
wildmask.s_addr = (0xfffffffful >> n->aggregateLow)
& (~wild2addr.s_addr);
mask.s_addr = htonl(mask.s_addr);
wildaddr.s_addr = htonl(wildaddr.s_addr);
wildmask.s_addr = htonl(wildmask.s_addr);
if (wildaddr.s_addr) {
fprintf(f, "permit ip %s ",
inet_ntoa(n->prefix->addr.addr)); inet_ntoa(n->prefix->addr.addr));
fprintf(f, "%s ", fprintf(f, "%s ", inet_ntoa(wildaddr));
inet_ntoa(*(struct in_addr*)&wildaddr));
} else { } else {
fprintf(f, " permit ip host %s ", fprintf(f, "permit ip host %s ",
inet_ntoa(n->prefix->addr.addr)); inet_ntoa(n->prefix->addr.addr));
} }
if (wildmask) { if (wildmask.s_addr)
fprintf(f, "%s ", fprintf(f, "%s %s\n", inet_ntoa(mask),
inet_ntoa(*(struct in_addr*)&mask)); inet_ntoa(wildmask));
fprintf(f, "%s\n", else {
inet_ntoa(*(struct in_addr*)&wildmask)); fprintf(f, "host %s\n", inet_ntoa(mask));
} else {
fprintf(f, "host %s\n",
inet_ntoa(*(struct in_addr*)&mask));
} }
} else { } else {
fprintf(f, " permit ip host %s host %s\n", prefix, fprintf(f, "permit ip host %s host %s\n", prefix,
inet_ntoa(*(struct in_addr*)&netmask)); inet_ntoa(netmask));
} }
checkSon: checkSon: