nixio: FreeBSD compatibility #2
[project/luci.git] / libs / nixio / src / io.c
index 58054b2..0ce4fcc 100644 (file)
@@ -23,8 +23,7 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
-#include "nixio.h"
-
+#include <netinet/in.h>
 
 
 /**
@@ -36,8 +35,8 @@ static int nixio_sock__sendto(lua_State *L, int to) {
        socklen_t alen = 0;
 
        if (to) {
-               const char *address = luaL_checklstring(L, 2, NULL);
-               uint16_t port = (uint16_t)luaL_checkinteger(L, 3);
+               const char *address = luaL_checklstring(L, 3, NULL);
+               uint16_t port = (uint16_t)luaL_checkinteger(L, 4);
                struct sockaddr_storage addrstor;
                addr = (struct sockaddr*)&addrstor;
                if (sock->domain == AF_INET) {
@@ -65,7 +64,7 @@ static int nixio_sock__sendto(lua_State *L, int to) {
        do {
                sent = sendto(sock->fd, data, len, 0, addr, alen);
        } while(sent == -1 && errno == EINTR);
-       if (len >= 0) {
+       if (sent >= 0) {
                lua_pushinteger(L, sent);
                return 1;
        } else {
@@ -169,6 +168,8 @@ static const luaL_reg M[] = {
        {"sendto",      nixio_sock_sendto},
        {"recv",        nixio_sock_recv},
        {"recvfrom",nixio_sock_recvfrom},
+       {"write",       nixio_sock_send},
+       {"read",        nixio_sock_recv},
        {NULL,                  NULL}
 };