Proper header inclusion.
[swifty.git] / src / raw / swift_raw.c
index b2d96e0..b7eb04a 100644 (file)
 #include <unistd.h>
 #include <errno.h>
 
-#include "include/swift_types.h"
-#include "include/swift_raw.h"
-#include "include/swift_list.h"
+#include "swift_types.h"
+#include "swift_raw.h"
+#include "swift_list.h"
+#include "debug.h"
+#include "util.h"
 
 /*
  * Create a new socket of type TYPE in domain DOMAIN, using
@@ -140,20 +142,21 @@ ssize_t sw_sendto(int __fd, __const void *__buf, size_t __n,
        struct sock_list *list;
        struct iovec __iov[1];
        struct msghdr __msgh;
-       
+       struct sockaddr_sw *__sw_addr = (struct sockaddr_sw *) __addr;
+
        list = list_elem_from_socket(__fd);
-       if (list == NULL) {
-               errno = EBADF;
+       if (list != NULL && list->bind_state == STATE_NOTBOUND) {
+               errno = EAFNOSUPPORT;
                goto sock_err;
        }
 
-/*
-       if (list->state == STATE_NOBOUND) {
-               errno = EDESTADDRREQ;
-               goto sock_err;
+       {
+               char str[INET_ADDRSTRLEN];
+
+               inet_ntop(AF_INET, &(__sw_addr->sin_addr), str, INET_ADDRSTRLEN);       
+               printf("=== ADDR: %s ===\n", str);
        }
- */
-       
+
        /* Specify the components of the message in an "iovec".   */
        __iov[0].iov_base = (void *) __buf;
        __iov[0].iov_len = __n;
@@ -186,10 +189,23 @@ ssize_t sw_recvfrom(int __fd, void *__restrict __buf, size_t __n,
                         socklen_t *__restrict __addr_len)
 {
        ssize_t bytes_recv;
+       struct sock_list *list;
+       struct iovec __iov[1];
+       struct msghdr __msgh;
+       struct sockaddr_sw *__sw_addr = (struct sockaddr_sw *) __addr;
 
+       list = list_elem_from_socket(__fd);
+       if (list != NULL && list->bind_state == STATE_NOTBOUND) {
+               errno = EAFNOSUPPORT;
+               goto sock_err;
+       }
        /* TODO */
 
-       return bytes_recv;
+       return recvmsg(__fd, &__msgh, 0);
+       
+sock_err:
+       return -1;
 }
 
 /*
@@ -204,6 +220,8 @@ ssize_t sw_sendmsg(int __fd, __const struct msghdr *__message,
 {
        ssize_t bytes_sent;
 
+       /* TODO */
+       
        return sendmsg(__fd, __message, __flags);
 }
 
@@ -220,7 +238,7 @@ ssize_t sw_recvmsg(int __fd, struct msghdr *__message, int __flags)
 
        /* TODO */
 
-       return bytes_recv;
+       return recvmsg(__fd, __message, __flags);
 }
 
 /*