build standalone ipx utilities without ncpfs private headers
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <netipx/ipx.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include "samples.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_ipx sipx;
|
||||
int s;
|
||||
int rc;
|
||||
char msg[100];
|
||||
int len;
|
||||
struct sockaddr_ipx sipx;
|
||||
int s;
|
||||
int rct;
|
||||
char msg[100];
|
||||
socklen_t len;
|
||||
|
||||
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
|
||||
if (s < 0) {
|
||||
if (s < 0)
|
||||
{
|
||||
perror("IPX: socket: ");
|
||||
exit(-1);
|
||||
}
|
||||
@@ -25,25 +19,25 @@ int main(int argc, char **argv)
|
||||
sipx.sipx_network = 0;
|
||||
sipx.sipx_port = htons(0x5000);
|
||||
sipx.sipx_type = 17;
|
||||
len = sizeof(sipx);
|
||||
rc = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (rc < 0) {
|
||||
rc = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("IPX: bind: ");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
msg[0] = '\0';
|
||||
rc = recvfrom(s, msg, sizeof(msg), 0, (struct sockaddr *)&sipx, &len);
|
||||
if (rc < 0) {
|
||||
len = sizeof(sipx);
|
||||
rc = recvfrom(s, msg, sizeof(msg), 0, (struct sockaddr *) &sipx, &len);
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("IPX: recvfrom: ");
|
||||
}
|
||||
|
||||
printf("From %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
|
||||
(unsigned long)ntohl(sipx.sipx_network),
|
||||
sipx.sipx_node[0], sipx.sipx_node[1],
|
||||
sipx.sipx_node[2], sipx.sipx_node[3],
|
||||
sipx.sipx_node[4], sipx.sipx_node[5],
|
||||
ntohs(sipx.sipx_port));
|
||||
printf("From %08X:%02X%02X%02X%02X%02X%02X:%04X\n",
|
||||
(unsigned long)ntohl(sipx.sipx_network),
|
||||
sipx.sipx_node[0], sipx.sipx_node[1],
|
||||
sipx.sipx_node[2], sipx.sipx_node[3],
|
||||
sipx.sipx_node[4], sipx.sipx_node[5],
|
||||
ntohl(sipx.sipx_port));
|
||||
printf("\tGot \"%s\"\n", msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <netipx/ipx.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
#include "samples.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_ipx sipx;
|
||||
int s;
|
||||
int rc;
|
||||
char msg[100] = "Hello world!";
|
||||
int len = sizeof(sipx);
|
||||
struct sockaddr_ipx sipx;
|
||||
int s;
|
||||
int rc;
|
||||
char msg[100] = "Hello world!";
|
||||
socklen_t len = sizeof(sipx);
|
||||
|
||||
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
|
||||
if (s < 0) {
|
||||
if (s < 0)
|
||||
{
|
||||
perror("IPX: socket: ");
|
||||
exit(-1);
|
||||
}
|
||||
@@ -26,13 +20,13 @@ int main(int argc, char **argv)
|
||||
sipx.sipx_port = 0;
|
||||
sipx.sipx_type = 17;
|
||||
|
||||
rc = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (rc < 0) {
|
||||
rc = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
|
||||
if (rc < 0)
|
||||
{
|
||||
perror("IPX: bind: ");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
rc = getsockname(s, (struct sockaddr *)&sipx, &len);
|
||||
rc = getsockname(s, (struct sockaddr *) &sipx, &len);
|
||||
sipx.sipx_port = htons(0x5000);
|
||||
sipx.sipx_node[0] = 0xFF;
|
||||
sipx.sipx_node[1] = 0xFF;
|
||||
@@ -42,7 +36,7 @@ int main(int argc, char **argv)
|
||||
sipx.sipx_node[5] = 0xFF;
|
||||
|
||||
rc = sendto(s, msg, strlen(msg), 0, (struct sockaddr *)&sipx,
|
||||
sizeof(sipx));
|
||||
sizeof(sipx));
|
||||
if (rc < 0) {
|
||||
perror("IPX: send: ");
|
||||
exit(-1);
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
8
Samples/samples.h
Normal file
8
Samples/samples.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <netipx/ipx.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
103
Samples/sap.c
103
Samples/sap.c
@@ -1,93 +1,94 @@
|
||||
#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 sap_data {
|
||||
uint16_t sap_type;
|
||||
char sap_name[48];
|
||||
uint32_t sap_net;
|
||||
uint8_t sap_node[6];
|
||||
uint16_t sap_sock;
|
||||
uint16_t sap_hops;
|
||||
struct sap_data
|
||||
{
|
||||
uint16_t sap_type;
|
||||
char sap_name[48];
|
||||
uint32_t sap_net;
|
||||
uint8_t sap_node[6];
|
||||
uint16_t sap_sock;
|
||||
uint16_t sap_hops;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int s;
|
||||
int result;
|
||||
struct sockaddr_ipx sipx;
|
||||
char msg[1024];
|
||||
long val = 0;
|
||||
int len;
|
||||
char *bptr;
|
||||
struct sap_data *sp;
|
||||
int s;
|
||||
int result;
|
||||
struct sockaddr_ipx sipx;
|
||||
char msg[1024];
|
||||
long val = 0;
|
||||
char *bptr;
|
||||
struct sap_data *sp;
|
||||
|
||||
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
|
||||
if (s < 0) {
|
||||
if (s < 0)
|
||||
{
|
||||
perror("IPX: socket: ");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
result = setsockopt(s, SOL_SOCKET, SO_DEBUG, &val, 4);
|
||||
if (result < 0) {
|
||||
if (result < 0)
|
||||
{
|
||||
perror("IPX: setsockopt: ");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
sipx.sipx_family = PF_IPX;
|
||||
sipx.sipx_network = 0L;
|
||||
sipx.sipx_port = htons(0x452);
|
||||
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 = 1024;
|
||||
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 SAP packet (%d bytes)\n", result);
|
||||
continue;
|
||||
}
|
||||
rclen = result - 2;
|
||||
bptr = msg;
|
||||
result -= 2;
|
||||
printf("SAP: OP is %x %x\n", bptr[0], bptr[1]);
|
||||
printf("Length is %d\n", result);
|
||||
printf("Length is %zu\n", rclen);
|
||||
if (bptr[1] != 2)
|
||||
continue;
|
||||
|
||||
bptr += 2;
|
||||
sp = (struct sap_data *) bptr;
|
||||
while (result >= sizeof(struct sap_data)) {
|
||||
int i;
|
||||
|
||||
while (rclen >= sizeof(struct sap_data))
|
||||
{
|
||||
int i;
|
||||
|
||||
sp->sap_name[32] = '\0';
|
||||
for (i = 31; (i > 0) && (sp->sap_name[i] == '_'); i--);
|
||||
i++;
|
||||
sp->sap_name[i] = '\0';
|
||||
printf("NAME: %s TYPE: %x HOPS: %x\n", sp->sap_name,
|
||||
ntohs(sp->sap_type), ntohs(sp->sap_hops));
|
||||
ntohs(sp->sap_type), ntohs(sp->sap_hops));
|
||||
printf("%x:%x %x %x %x %x %x: %x\n",
|
||||
ntohl(sp->sap_net),
|
||||
sp->sap_node[0],
|
||||
sp->sap_node[1],
|
||||
sp->sap_node[2],
|
||||
sp->sap_node[3],
|
||||
sp->sap_node[4],
|
||||
sp->sap_node[5],
|
||||
ntohs(sp->sap_sock));
|
||||
result -= sizeof(struct sap_data);
|
||||
(u_int32_t)ntohl(sp->sap_net),
|
||||
sp->sap_node[0],
|
||||
sp->sap_node[1],
|
||||
sp->sap_node[2],
|
||||
sp->sap_node[3],
|
||||
sp->sap_node[4],
|
||||
sp->sap_node[5],
|
||||
ntohs(sp->sap_sock));
|
||||
rclen -= sizeof(struct sap_data);
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user