Add counters for MPTP buffers and syscalls.
[swifty.git] / src / lib / server.c
1 /*
2  * Sample server implementation using SWIFT library
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <arpa/inet.h>
8 #include <netinet/in.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <unistd.h>
12
13 #include "lib_swift.h"
14
15 int main(void)
16 {
17         Swift s = socketSwift(1);
18         struct sockSwiftaddr my_addr, from;
19         char buf[100];
20         socklen_t slen;
21         struct listsockaddr lsa;
22         ssize_t len;
23
24         // populate sockSwiftaddr
25         my_addr.sin_family = AF_INET;
26         my_addr.sin_port = htons(SWIFT_PORT);
27         my_addr.sin_addr.N = 1;
28         my_addr.sin_addr.s_addr[0] = htonl(INADDR_ANY);
29
30         //recvfromSwift(s, buf, 100, 0, (struct sockaddr *)&si_other, &slen);
31
32         bindSwift(s, &my_addr, sizeof(my_addr));
33         len = listenfromSwift(s, buf, 100, 0, &from, &slen);
34         transformFromSwiftToAddr(&lsa, from);
35         printf("Received packet from %s:%d with data: %s %d\n", inet_ntoa(lsa.sa[0].sin_addr), ntohs(lsa.sa[0].sin_port), buf, (int)len);
36
37         sendToSwift(s, buf, len, 0, &from, slen);
38
39         closeSwift(s);
40
41         return 0;
42 }