105 lines
2.0 KiB
C
105 lines
2.0 KiB
C
#include "samples.h"
|
|
|
|
struct sap_data
|
|
{
|
|
uint16_t sap_type;
|
|
char sap_name[48];
|
|
uint32_t sap_net;
|
|
unsigned char sap_node[6];
|
|
uint16_t sap_sock;
|
|
uint16_t sap_hops;
|
|
} __attribute__ ((packed));
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
struct sockaddr_ipx sipx;
|
|
int result;
|
|
int s;
|
|
char msg[1024];
|
|
char *bptr;
|
|
struct sap_data *sp;
|
|
|
|
(void)argc;
|
|
(void)argv;
|
|
|
|
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
|
|
if (s < 0)
|
|
{
|
|
perror("IPX: socket: ");
|
|
exit(-1);
|
|
}
|
|
|
|
sipx.sipx_family = AF_IPX;
|
|
sipx.sipx_network = 0;
|
|
sipx.sipx_port = htons(0x452);
|
|
sipx.sipx_type = 0x4;
|
|
|
|
result = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
|
|
if (result < 0)
|
|
{
|
|
perror("IPX: bind: ");
|
|
exit(-1);
|
|
}
|
|
|
|
while (1)
|
|
{
|
|
socklen_t len;
|
|
size_t rclen;
|
|
|
|
len = sizeof(sipx);
|
|
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 = (size_t)result - 2;
|
|
bptr = msg;
|
|
|
|
printf("SAP packet from: %08X:%02X%02X%02X%02X%02X%02X\n",
|
|
(uint32_t)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]);
|
|
|
|
bptr += 2;
|
|
sp = (struct sap_data *) bptr;
|
|
|
|
while (rclen >= sizeof(struct sap_data))
|
|
{
|
|
int i;
|
|
|
|
/* Keep output readable if the SAP name is blank-padded. */
|
|
sp->sap_name[47] = '\0';
|
|
for (i = 46; i > 0 && sp->sap_name[i] == '_'; i--)
|
|
;
|
|
sp->sap_name[i + 1] = '\0';
|
|
|
|
printf("NAME: %s TYPE: %x HOPS: %x\n",
|
|
sp->sap_name,
|
|
ntohs(sp->sap_type),
|
|
ntohs(sp->sap_hops));
|
|
|
|
printf("\tADDR: %08X:%02X%02X%02X%02X%02X%02X:%04X\n",
|
|
(uint32_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++;
|
|
}
|
|
}
|
|
}
|