vppinfra: fix compiling error due to incompatible udphdr field names
Compiling VPP on CentOS 7 will fail shown as below. The root cause is
that uh_sport/uh_dport field names for struct udphdr are chosen only if
macro __FAVOR_BSD in /usr/include/netinet/udp.h is defined for glibc
version less than 2.19. Fix this issue by using source and dest field
names in struct udphdr for compatibility reasons.
FAILED: vppinfra/CMakeFiles/vppinfra.dir/unix-formats.c.o
ccache /opt/rh/devtoolset-9/root/bin/cc -Dvppinfra_EXPORTS -I/vpp/src -I. -Iinclude -Wno-address-of-packed-member -g -fPIC -Werror -Wall -march=corei7 -mtune=corei7-avx -O2 -fstack-protector -D_FORTIFY_SOURCE=2 -fno-common -flto -fno-fat-lto-objects -fPIC -fvisibility=hidden -ffunction-sections -fdata-sections -MD -MT vppinfra/CMakeFiles/vppinfra.dir/unix-formats.c.o -MF vppinfra/CMakeFiles/vppinfra.dir/unix-formats.c.o.d -o vppinfra/CMakeFiles/vppinfra.dir/unix-formats.c.o -c /vpp/src/vppinfra/unix-formats.c
/vpp/src/vppinfra/unix-formats.c: In function 'format_udp4_packet':
/vpp/src/vppinfra/unix-formats.c:319:19: error: 'struct udphdr' has no member named 'uh_sport'
319 | u16 source = udp->uh_sport;
| ^~
/vpp/src/vppinfra/unix-formats.c:320:17: error: 'struct udphdr' has no member named 'uh_dport'
320 | u16 dest = udp->uh_dport;
Type: fix
Change-Id: Ifc99c7286ea3fac463096152267033ac0518c230
Signed-off-by: Jieqiang Wang <jieqiang.wang@arm.com>
Reviewed-by: Lijian Zhang <lijian.zhang@arm.com>
Reviewed-by: Tianyu Li <tianyu.li@arm.com>
diff --git a/src/vppinfra/unix-formats.c b/src/vppinfra/unix-formats.c
index 678700e..af1eb1a 100644
--- a/src/vppinfra/unix-formats.c
+++ b/src/vppinfra/unix-formats.c
@@ -316,13 +316,10 @@
struct iphdr * ip = (void *) p;
struct udphdr * udp = (void *) (ip + 1);
- u16 source = udp->uh_sport;
- u16 dest = udp->uh_dport;
-
s = format (s, "udp %U:%U -> %U:%U", format_network_address, AF_INET,
- &ip->saddr, format_network_port, IPPROTO_UDP, ntohs (source),
- format_network_address, AF_INET, &ip->daddr, format_network_port,
- IPPROTO_UDP, ntohs (dest));
+ &ip->saddr, format_network_port, IPPROTO_UDP,
+ ntohs (udp->source), format_network_address, AF_INET, &ip->daddr,
+ format_network_port, IPPROTO_UDP, ntohs (udp->dest));
return s;
}