Samples: clean ipxrcv and ipxsend
Zero sipx buffers not to have garbage. Send message to broadcast address, so the remote side receives the message.
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/ipx.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_ipx sipx;
|
||||
int s;
|
||||
int result;
|
||||
int rc;
|
||||
char msg[100];
|
||||
int len;
|
||||
|
||||
@@ -19,34 +20,30 @@ main(int argc, char **argv)
|
||||
perror("IPX: socket: ");
|
||||
exit(-1);
|
||||
}
|
||||
memset(&sipx, 0, sizeof(sipx));
|
||||
sipx.sipx_family = AF_IPX;
|
||||
sipx.sipx_network = 0;
|
||||
sipx.sipx_port = htons(0x5000);
|
||||
sipx.sipx_type = 17;
|
||||
len = sizeof(sipx);
|
||||
result = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (result < 0) {
|
||||
rc = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (rc < 0) {
|
||||
perror("IPX: bind: ");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
msg[0] = '\0';
|
||||
result = recvfrom(s, msg, sizeof(msg), 0, (struct sockaddr *)&sipx,
|
||||
&len);
|
||||
if (result < 0) {
|
||||
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",
|
||||
htonl(sipx.sipx_network),
|
||||
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],
|
||||
htons(sipx.sipx_port));
|
||||
ntohs(sipx.sipx_port));
|
||||
printf("\tGot \"%s\"\n", msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <linux/ipx.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <errno.h>
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_ipx sipx;
|
||||
int s;
|
||||
int result;
|
||||
char msg[100] = "Hi Mom";
|
||||
int rc;
|
||||
char msg[100] = "Hello world!";
|
||||
int len = sizeof(sipx);
|
||||
|
||||
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
|
||||
@@ -19,28 +20,32 @@ main(int argc, char **argv)
|
||||
perror("IPX: socket: ");
|
||||
exit(-1);
|
||||
}
|
||||
memset(&sipx, 0, sizeof(sipx));
|
||||
sipx.sipx_family = AF_IPX;
|
||||
sipx.sipx_network = 0;
|
||||
sipx.sipx_port = 0;
|
||||
sipx.sipx_type = 17;
|
||||
|
||||
result = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (result < 0) {
|
||||
rc = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
|
||||
if (rc < 0) {
|
||||
perror("IPX: bind: ");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
result = getsockname(s, (struct sockaddr *)&sipx, &len);
|
||||
rc = getsockname(s, (struct sockaddr *)&sipx, &len);
|
||||
sipx.sipx_port = htons(0x5000);
|
||||
result = sendto(s, msg, sizeof(msg), 0, (struct sockaddr *)&sipx,
|
||||
sizeof(sipx));
|
||||
if (result < 0) {
|
||||
sipx.sipx_node[0] = 0xFF;
|
||||
sipx.sipx_node[1] = 0xFF;
|
||||
sipx.sipx_node[2] = 0xFF;
|
||||
sipx.sipx_node[3] = 0xFF;
|
||||
sipx.sipx_node[4] = 0xFF;
|
||||
sipx.sipx_node[5] = 0xFF;
|
||||
|
||||
rc = sendto(s, msg, strlen(msg), 0, (struct sockaddr *)&sipx,
|
||||
sizeof(sipx));
|
||||
if (rc < 0) {
|
||||
perror("IPX: send: ");
|
||||
exit(-1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user