Fixed demo app
[ana-net.git] / opt / pflana.c
blobe914c298bbcb7b8a6010c46af1ef78c0f6acd477
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <unistd.h>
4 #include <signal.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <ctype.h>
8 #include <assert.h>
9 #include <sys/socket.h>
11 #define AF_LANA 27
13 int main(void)
15 int sock, i;
16 char buff[1600];
18 sock = socket(AF_LANA, SOCK_RAW, 0);
19 if (sock < 0) {
20 perror("socket");
21 return 0;
24 printf("Worked! Abort with ^C\n");
25 while (1) {
26 memset(buff, 0, sizeof(buff));
27 int ret = recv(sock, buff, sizeof(buff), 0);
28 if (ret < 0) {
29 perror("recvmsg");
30 continue;
31 } else {
32 assert(ret <= sizeof(buff));
33 printf("RECEIVED ......\n");
34 printf("hex:\n");
35 for (i = 0; i < ret; i++)
36 printf("0x%.2x ", (uint8_t) buff[i]);
37 printf("ascii:\n");
38 for (i = 0; i < ret; i++)
39 printf("%c ", isprint(buff[i]) ? buff[i] : '.');
40 printf("\n\n");
41 fflush(stdout);
45 close(sock);
46 return 0;