int main()
{
+ /* create a single download session */
Swift s = socketSwift(1);
struct sockSwiftaddr my_addr;
char buf[100];
struct listsockaddr lsa;
-
+
// populate sockSwiftaddr
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(SWIFT_PORT);
- my_addr.sin_addr.N = 1;
- my_addr.sin_addr.s_addr[0] = htonl(INADDR_LOOPBACK);
-
+ my_addr.sin_addr.N = 1;
+ my_addr.sin_addr.s_addr[0] = htonl(INADDR_LOOPBACK);
+
recvfromSwift(s, buf, 100, 0, &my_addr, sizeof(my_addr));
-
+
transformFromSwiftToAddr(&lsa, my_addr);
printf("Received packet from %s:%d\nData: %s\n\n", inet_ntoa(lsa.sa[0].sin_addr), ntohs(my_addr.sin_port), buf);
-
+
closeSwift(s);
- return 0;
+
+ return 0;
}
#define DEBUG
#include "lib_swift.h"
+/*
+ * TODO: send ssa as pointer
+ */
+
void transformFromAddrToSwift(struct sockSwiftaddr *ssa, struct listsockaddr lsa)
{
int i;
}
}
+/*
+ * TODO: send ssa as pointer
+ */
+
void transformFromSwiftToAddr(struct listsockaddr *lsa, struct sockSwiftaddr ssa)
{
int i;
int maxChannels;
} *Swift;
-// swift_addr structure similar with in_addr
+/*
+ * TODO: uniform structure names
+ */
+
+// swift_addr structure similar with in_addr
struct swift_addr {
unsigned short N; // e.g. number of s_addr
unsigned long s_addr[MAX_IPs]; // i.p. ip list
// swift struct similar with sock_addr
typedef struct sockSwiftaddr {
short sin_family; // e.g. AF_INET
- unsigned short sin_port; // e.g. htons(3490)
- struct swift_addr sin_addr; // see struct swift_addr, below
+ unsigned short sin_port; // e.g. htons(3490)
+ struct swift_addr sin_addr; // see struct swift_addr, below
} *SockSwiftaddr;
// list of swift_addr
struct listsockaddr {
unsigned short N;
struct sockaddr_in sa[MAX_IPs];
-};
+};
// Function to create a Swift socket
Swift socketSwift(int maxChannels);
// Function to receive a message
ssize_t recvfromSwift(Swift s, void *buf, size_t len, int flags,
struct sockSwiftaddr *from, socklen_t fromlen);
-
+
// Function to send a message
-ssize_t sendToSwift(Swift s, const void *buf, size_t len, int flags,
- const struct sockSwiftaddr *to, socklen_t tolen);
+ssize_t sendToSwift(Swift s, const void *buf, size_t len, int flags,
+ const struct sockSwiftaddr *to, socklen_t tolen);
// test function -- don't commit
+/*
+ * Sample server implementation using SWIFT library
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include "lib_swift.h"
-int main()
+int main(void)
{
Swift s = socketSwift(1);
struct sockSwiftaddr my_addr, from;
socklen_t slen;
struct listsockaddr lsa;
ssize_t len;
-
+
// populate sockSwiftaddr
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(SWIFT_PORT);
- my_addr.sin_addr.N = 1;
- my_addr.sin_addr.s_addr[0] = htonl(INADDR_ANY);
-
+ my_addr.sin_addr.N = 1;
+ my_addr.sin_addr.s_addr[0] = htonl(INADDR_ANY);
+
//recvfromSwift(s, buf, 100, 0, (struct sockaddr *)&si_other, &slen);
-
+
bindSwift(s, &my_addr, sizeof(my_addr));
len = listenfromSwift(s, buf, 100, 0, &from, &slen);
transformFromSwiftToAddr(&lsa, from);
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);
-
+
sendToSwift(s, buf, len, 0, &from, slen);
-
+
closeSwift(s);
+
return 0;
}