File: ipxrcv.c

package info (click to toggle)
ipx 1.0-5
  • links: PTS
  • area: main
  • in suites: potato
  • size: 148 kB
  • ctags: 55
  • sloc: ansic: 1,054; sh: 76; makefile: 72
file content (52 lines) | stat: -rw-r--r-- 1,016 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.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)
{
	struct sockaddr_ipx	sipx;
	int	s;
	int	result;
	char	msg[100];
	int	len;

	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(0x5000);
	sipx.sipx_type = 17;
	len = sizeof(sipx);
	result = bind(s, (struct sockaddr *)&sipx, sizeof(sipx));
	if (result < 0) {
		perror("IPX: bind: ");
		exit(-1);
	}

	msg[0] = '\0';
	result = recvfrom(s, msg, sizeof(msg),  0, (struct sockaddr *)&sipx, 
			&len);
	if (result < 0) {
		perror("IPX: recvfrom: ");
	}

	printf("From %08lX:%02X%02X%02X%02X%02X%02X:%04X\n", 
		htonl(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));
	printf("\tGot \"%s\"\n", msg);
	return 0;
}