openwrt: allow unix domain sockets in nixio sendto and recvfrom
This commit is contained in:
parent
505ce638f5
commit
48f946e6aa
|
@ -0,0 +1,99 @@
|
|||
--- /tmp/luci-0.9.0/libs/nixio/src/io.c 2010-08-10 22:26:11.920381434 +0200
|
||||
+++ luci-0.9.0/libs/nixio/src/io.c 2010-08-11 11:28:09.724417190 +0200
|
||||
@@ -35,19 +35,35 @@
|
||||
|
||||
if (to) {
|
||||
argoff += 2;
|
||||
- const char *address = luaL_checkstring(L, 3);
|
||||
- struct sockaddr_storage addrstor;
|
||||
- addr = (struct sockaddr*)&addrstor;
|
||||
+ if (sock->domain == AF_INET || sock->domain == AF_INET6) {
|
||||
+ const char *address = luaL_checkstring(L, 3);
|
||||
+ struct sockaddr_storage addrstor;
|
||||
+ addr = (struct sockaddr*)&addrstor;
|
||||
|
||||
- nixio_addr naddr;
|
||||
- memset(&naddr, 0, sizeof(naddr));
|
||||
- strncpy(naddr.host, address, sizeof(naddr.host) - 1);
|
||||
- naddr.port = (uint16_t)luaL_checkinteger(L, 4);
|
||||
- naddr.family = sock->domain;
|
||||
+ nixio_addr naddr;
|
||||
+ memset(&naddr, 0, sizeof(naddr));
|
||||
+ strncpy(naddr.host, address, sizeof(naddr.host) - 1);
|
||||
+ naddr.port = (uint16_t)luaL_checkinteger(L, 4);
|
||||
+ naddr.family = sock->domain;
|
||||
|
||||
- if (nixio__addr_write(&naddr, addr)) {
|
||||
- return nixio__perror_s(L);
|
||||
+ if (nixio__addr_write(&naddr, addr)) {
|
||||
+ return nixio__perror_s(L);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+#ifndef __WINNT__
|
||||
+ else if (sock->domain == AF_UNIX) {
|
||||
+ size_t pathlen;
|
||||
+ const char *path = luaL_checklstring(L, 3, &pathlen);
|
||||
+
|
||||
+ struct sockaddr_un addr_un;
|
||||
+ addr_un.sun_family = AF_UNIX;
|
||||
+ luaL_argcheck(L, pathlen < sizeof(addr_un.sun_path), 3, "out of range");
|
||||
+ strncpy(addr_un.sun_path, path, sizeof(addr_un.sun_path));
|
||||
+
|
||||
+ addr = (struct sockaddr*)&addr_un;
|
||||
}
|
||||
+#endif
|
||||
}
|
||||
|
||||
size_t len;
|
||||
@@ -104,15 +120,22 @@
|
||||
nixio_sock *sock = nixio__checksock(L);
|
||||
char buffer[NIXIO_BUFFERSIZE];
|
||||
struct sockaddr_storage addrobj;
|
||||
+ struct sockaddr_un addrobj_un;
|
||||
+ struct sockaddr *addr;
|
||||
+ socklen_t alen;
|
||||
uint req = luaL_checkinteger(L, 2);
|
||||
int readc;
|
||||
|
||||
- if (from && sock->domain != AF_INET && sock->domain != AF_INET6) {
|
||||
- return luaL_argerror(L, 1, "supported families: inet, inet6");
|
||||
+ if (sock->domain == AF_INET || sock->domain == AF_INET6) {
|
||||
+ addr = (from) ? (struct sockaddr*)&addrobj : NULL;
|
||||
+ alen = (from) ? sizeof(addrobj) : 0;
|
||||
}
|
||||
-
|
||||
- struct sockaddr *addr = (from) ? (struct sockaddr*)&addrobj : NULL;
|
||||
- socklen_t alen = (from) ? sizeof(addrobj) : 0;
|
||||
+#ifndef __WINNT__
|
||||
+ else if (sock->domain == AF_UNIX) {
|
||||
+ addr = (from) ? (struct sockaddr*)&addrobj_un : NULL;
|
||||
+ alen = (from) ? sizeof(addrobj_un) : 0;
|
||||
+ }
|
||||
+#endif
|
||||
|
||||
/* We limit the readsize to NIXIO_BUFFERSIZE */
|
||||
req = (req > NIXIO_BUFFERSIZE) ? NIXIO_BUFFERSIZE : req;
|
||||
@@ -137,7 +160,8 @@
|
||||
|
||||
if (!from) {
|
||||
return 1;
|
||||
- } else {
|
||||
+ }
|
||||
+ else if (sock->domain == AF_INET || sock->domain == AF_INET6) {
|
||||
nixio_addr naddr;
|
||||
if (!nixio__addr_parse(&naddr, (struct sockaddr *)&addrobj)) {
|
||||
lua_pushstring(L, naddr.host);
|
||||
@@ -147,6 +171,12 @@
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
+#ifndef __WINNT__
|
||||
+ else if (sock->domain == AF_UNIX) {
|
||||
+ lua_pushstring(L, addrobj_un.sun_path);
|
||||
+ return 2;
|
||||
+ }
|
||||
+#endif
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue