diff options
| author | Leso_KN <info@lesosoftware.com> | 2023-10-23 20:27:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-23 21:27:01 +0300 |
| commit | f741a88b80ffcf4de65b91ff82fc9f7865cbad0e (patch) | |
| tree | b037761c61edd06602410b2fd6705b1ef3682041 /src/options.c | |
| parent | 9100f7e3abf3511009fa21de1e0b304cac5489d3 (diff) | |
| download | luasocket-f741a88b80ffcf4de65b91ff82fc9f7865cbad0e.tar.gz luasocket-f741a88b80ffcf4de65b91ff82fc9f7865cbad0e.tar.bz2 luasocket-f741a88b80ffcf4de65b91ff82fc9f7865cbad0e.zip | |
feat(tcp): Add 'bindtodevice' option (#408)
Diffstat (limited to 'src/options.c')
| -rw-r--r-- | src/options.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/options.c b/src/options.c index 657947c..3856797 100644 --- a/src/options.c +++ b/src/options.c | |||
| @@ -55,6 +55,33 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) | |||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | /*------------------------------------------------------*/ | 57 | /*------------------------------------------------------*/ |
| 58 | /* binds socket to network interface */ | ||
| 59 | int opt_set_bindtodevice(lua_State *L, p_socket ps) | ||
| 60 | { | ||
| 61 | #ifdef __APPLE__ | ||
| 62 | return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); | ||
| 63 | #else | ||
| 64 | const char *dev = luaL_checkstring(L, 3); | ||
| 65 | return opt_set(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char*)dev, strlen(dev)+1); | ||
| 66 | #endif | ||
| 67 | } | ||
| 68 | |||
| 69 | int opt_get_bindtodevice(lua_State *L, p_socket ps) | ||
| 70 | { | ||
| 71 | #ifdef __APPLE__ | ||
| 72 | return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); | ||
| 73 | #else | ||
| 74 | char dev[IFNAMSIZ]; | ||
| 75 | int len = sizeof(dev); | ||
| 76 | int err = opt_get(L, ps, SOL_SOCKET, SO_BINDTODEVICE, &dev, &len); | ||
| 77 | if (err) | ||
| 78 | return err; | ||
| 79 | lua_pushstring(L, dev); | ||
| 80 | return 1; | ||
| 81 | #endif | ||
| 82 | } | ||
| 83 | |||
| 84 | /*------------------------------------------------------*/ | ||
| 58 | /* enables reuse of local address */ | 85 | /* enables reuse of local address */ |
| 59 | int opt_set_reuseaddr(lua_State *L, p_socket ps) | 86 | int opt_set_reuseaddr(lua_State *L, p_socket ps) |
| 60 | { | 87 | { |
