Subject: Support to bind accepted socket to device on Linux
[platform/upstream/libwebsockets.git] / lib / lws-plat-unix.c
index ae73dfc..a2284f4 100644 (file)
@@ -255,6 +255,17 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd)
 #endif
        }
 
+#if defined(SO_BINDTODEVICE)
+       if (vhost->bind_iface) {
+               lwsl_info("binding listen skt to %s using SO_BINDTODEVICE\n", vhost->iface);
+               if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, vhost->iface,
+                               strlen(vhost->iface)) < 0) {
+                       lwsl_warn("Failed to bind to device %s\n", vhost->iface);
+                       return 1;
+               }
+       }
+#endif
+
        /* Disable Nagle */
        optval = 1;
 #if defined (__sun)