From: Steven Barth Date: Fri, 13 Mar 2009 11:53:12 +0000 (+0000) Subject: nixio: +socket options SO_DONTROUTE, SO_BINDTODEVICE X-Git-Tag: 0.9.0~600 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5fa29b1c5a6f50817e3280ff9eb638f9ce0669ad;p=oweals%2Fluci.git nixio: +socket options SO_DONTROUTE, SO_BINDTODEVICE --- diff --git a/libs/nixio/src/sockopt.c b/libs/nixio/src/sockopt.c index 8884e9abc..5965eaefe 100644 --- a/libs/nixio/src/sockopt.c +++ b/libs/nixio/src/sockopt.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -107,6 +108,26 @@ static int nixio__gso_timev(lua_State *L, int fd, int level, int opt, int set) { return nixio__perror(L); } +static int nixio__gso_b(lua_State *L, int fd, int level, int opt, int set) { + if (!set) { + socklen_t optlen = IFNAMSIZ; + char ifname[IFNAMSIZ]; + if (!getsockopt(fd, level, opt, ifname, &optlen)) { + lua_pushlstring(L, ifname, optlen); + return 1; + } + } else { + size_t valuelen; + const char *value = luaL_checklstring(L, set, &valuelen); + luaL_argcheck(L, valuelen <= IFNAMSIZ, set, "invalid interface name"); + if (!setsockopt(fd, level, opt, value, valuelen)) { + lua_pushboolean(L, 1); + return 1; + } + } + return nixio__perror(L); +} + /** * get/setsockopt() helper */ @@ -133,15 +154,20 @@ static int nixio__getsetsockopt(lua_State *L, int set) { #endif } else if (!strcmp(option, "broadcast")) { return nixio__gso_int(L, sock->fd, SOL_SOCKET, SO_BROADCAST, set); + } else if (!strcmp(option, "dontroute")) { + return nixio__gso_int(L, sock->fd, SOL_SOCKET, SO_DONTROUTE, set); } else if (!strcmp(option, "linger")) { return nixio__gso_ling(L, sock->fd, SOL_SOCKET, SO_LINGER, set); } else if (!strcmp(option, "sndtimeo")) { return nixio__gso_timev(L, sock->fd, SOL_SOCKET, SO_SNDTIMEO, set); } else if (!strcmp(option, "rcvtimeo")) { return nixio__gso_timev(L, sock->fd, SOL_SOCKET, SO_RCVTIMEO, set); + } else if (!strcmp(option, "bindtodevice")) { + return nixio__gso_b(L, sock->fd, SOL_SOCKET, SO_BINDTODEVICE, set); } else { return luaL_argerror(L, 3, "supported values: keepalive, reuseaddr," - " sndbuf, rcvbuf, priority, broadcast, linger, sndtimeo, rcvtimeo" + " sndbuf, rcvbuf, priority, broadcast, linger, sndtimeo, rcvtimeo," + " dontroute, bindtodevice" ); } } else if (!strcmp(level, "tcp")) {