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