build standalone ipx utilities without ncpfs private headers
This commit is contained in:
@@ -1,31 +1,24 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <netipx/ipx.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include "samples.h"
|
||||
|
||||
struct rip_data {
|
||||
struct rip_data
|
||||
{
|
||||
uint32_t rip_net;
|
||||
uint16_t rip_hops;
|
||||
uint16_t rip_ticks;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_ipx sipx;
|
||||
int result;
|
||||
int s;
|
||||
char msg[1024];
|
||||
int len;
|
||||
char *bptr;
|
||||
struct rip_data *rp;
|
||||
struct sockaddr_ipx sipx;
|
||||
int result;
|
||||
int s;
|
||||
char msg[1024];
|
||||
char *bptr;
|
||||
struct rip_data *rp;
|
||||
|
||||
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
|
||||
if (s < 0) {
|
||||
if (s < 0)
|
||||
{
|
||||
perror("IPX: socket: ");
|
||||
exit(-1);
|
||||
}
|
||||
@@ -33,33 +26,43 @@ main(int argc, char **argv)
|
||||
sipx.sipx_network = 0;
|
||||
sipx.sipx_port = htons(0x453);
|
||||
sipx.sipx_type = 17;
|
||||
result = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (result < 0) {
|
||||
result = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
|
||||
if (result < 0)
|
||||
{
|
||||
perror("IPX: bind: ");
|
||||
exit(-1);
|
||||
}
|
||||
while (1)
|
||||
{
|
||||
socklen_t len;
|
||||
size_t rclen;
|
||||
|
||||
while (1) {
|
||||
len = sizeof(sipx);
|
||||
result = recvfrom(s, msg, sizeof(msg), 0,
|
||||
(struct sockaddr *)&sipx, &len);
|
||||
if (result < 0) {
|
||||
result = recvfrom(s, msg, sizeof(msg), 0,
|
||||
(struct sockaddr *) &sipx, &len);
|
||||
if (result < 0)
|
||||
{
|
||||
perror("IPX: recvfrom");
|
||||
exit(-1);
|
||||
}
|
||||
if (result < 2) {
|
||||
fprintf(stderr, "Received packet is too short to be RIP packet (%d bytes)\n", result);
|
||||
continue;
|
||||
}
|
||||
rclen = result - 2;
|
||||
bptr = msg;
|
||||
result -= 2;
|
||||
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],
|
||||
sipx.sipx_node[6], sipx.sipx_node[5]);
|
||||
(u_int32_t)htonl(sipx.sipx_network),
|
||||
sipx.sipx_node[0], sipx.sipx_node[1],
|
||||
sipx.sipx_node[2], sipx.sipx_node[3],
|
||||
sipx.sipx_node[6], sipx.sipx_node[5]);
|
||||
bptr += 2;
|
||||
rp = (struct rip_data *) bptr;
|
||||
while (result >= sizeof(struct rip_data)) {
|
||||
printf("\tNET: %08X HOPS: %d\n", ntohl(rp->rip_net),
|
||||
ntohs(rp->rip_hops));
|
||||
result -= sizeof(struct rip_data);
|
||||
while (rclen >= sizeof(struct rip_data))
|
||||
{
|
||||
printf("\tNET: %08X HOPS: %d\n", (u_int32_t)ntohl(rp->rip_net),
|
||||
ntohs(rp->rip_hops));
|
||||
rclen -= sizeof(struct rip_data);
|
||||
rp++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user