Fix warnings and errors in samples

- Use <netipx/ipx.h> from glibc, because Linux 5.15 removes <linux/ipx.h>
- Pack whole structure instead of individual fields
- Network is 32bit value, avoid unsigned long to work on 64bit systems
This commit is contained in:
Dmitry Podgorny
2021-10-31 00:48:33 +03:00
parent 7d71376dca
commit 15526d8c4c
4 changed files with 24 additions and 28 deletions

View File

@@ -1,16 +1,18 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <linux/ipx.h>
#include <netipx/ipx.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <errno.h>
struct rip_data {
unsigned long rip_net;
unsigned short rip_hops __attribute__ ((packed));
unsigned short rip_ticks __attribute__ ((packed));
};
uint32_t rip_net;
uint16_t rip_hops;
uint16_t rip_ticks;
} __attribute__ ((packed));
int
main(int argc, char **argv)
{
@@ -47,7 +49,7 @@ main(int argc, char **argv)
}
bptr = msg;
result -= 2;
printf("RIP packet from: %08lX:%02X%02X%02X%02X%02X%02X\n",
printf("RIP packet from: %08X:%02X%02X%02X%02X%02X%02X\n",
htonl(sipx.sipx_network),
sipx.sipx_node[0], sipx.sipx_node[1],
sipx.sipx_node[2], sipx.sipx_node[3],
@@ -55,14 +57,10 @@ main(int argc, char **argv)
bptr += 2;
rp = (struct rip_data *) bptr;
while (result >= sizeof(struct rip_data)) {
printf("\tNET: %08lX HOPS: %d\n", ntohl(rp->rip_net),
printf("\tNET: %08X HOPS: %d\n", ntohl(rp->rip_net),
ntohs(rp->rip_hops));
result -= sizeof(struct rip_data);
rp++;
}
}
}