--- /dev/null
+CFLAGS = -Wall -g
+
+.PHONY: all clean
+
+all: swift_raw_simple_test
+
+swift_raw_simple_test: swift_raw_simple_test.o swift_raw.o
+
+swift_raw_simple_test.o: swift_raw_simple_test.c swift_raw.h util.h
+
+swift_raw.o: swift_raw.c swift_raw.h
+
+clean:
+ -rm -f *~
+ -rm -f *.o
+ -rm -f swift_raw_simple_test
--- /dev/null
+/*
+ * Simple test for raw socket based implementation of swift socket API.
+ *
+ * 2011, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+
+#include "swift_types.h"
+#include "swift_raw.h"
+#include "util.h"
+
+/*
+ * Create a socket, bind it and send data.
+ */
+int main(void)
+{
+ int sockfd;
+ struct sockaddr_sw local_addr;
+ struct sockaddr_sw remote_addr;
+ char buffer[BUFSIZ];
+ ssize_t bytes_sent;
+ int rc;
+
+ sockfd = sw_socket(PF_INET, SOCK_DGRAM, IPPROTO_SWIFT);
+ DIE(sockfd < 0, "sw_socket");
+
+ /* TODO: init_addr */
+
+ rc = sw_bind(sockfd, (struct sockaddr *) &local_addr, sizeof(local_addr));
+ DIE(rc < 0, "sw_bind");
+
+ /* TODO: init remote_addr */
+ bytes_sent = sw_sendto(sockfd, buffer, BUFSIZ, 0,
+ (struct sockaddr *) &remote_addr, sizeof(remote_addr));
+ DIE(bytes_sent < 0, "sw_sendto");
+
+ return 0;
+}
--- /dev/null
+/*
+ * useful structures/macros
+ *
+ * 2011, Operating Systems
+ */
+
+#ifndef UTIL_H_
+#define UTIL_H_ 1
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#if defined (_WIN32)
+
+#include <windows.h>
+
+static VOID PrintLastError(const PCHAR message)
+{
+ CHAR errBuff[1024];
+
+ FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK,
+ NULL,
+ GetLastError(),
+ 0,
+ errBuff,
+ sizeof(errBuff) - 1,
+ NULL);
+
+ fprintf(stderr, "%s: %s\n", message, errBuff);
+}
+
+#define ERR(call_description) \
+ do { \
+ fprintf(stderr, "(%s, %d): ", \
+ __FILE__, __LINE__); \
+ PrintLastError(call_description); \
+ } while (0)
+
+#elif defined (__linux__)
+
+/* error printing macro */
+#define ERR(call_description) \
+ do { \
+ fprintf(stderr, "(%s, %d): ", \
+ __FILE__, __LINE__); \
+ perror(call_description); \
+ } while (0)
+
+#else
+ #error "Unknown platform"
+#endif
+
+/* print error (call ERR) and exit */
+#define DIE(assertion, call_description) \
+ do { \
+ if (assertion) { \
+ ERR(call_description); \
+ exit(EXIT_FAILURE); \
+ } \
+ } while(0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif