Subject: Support to bind accepted socket to device on Linux
[platform/upstream/libwebsockets.git] / test-server / test-server.c
index 93fb116..d6ddb9d 100644 (file)
@@ -122,17 +122,20 @@ static struct lws_protocols protocols[] = {
  */
 static lws_fop_fd_t
 test_server_fops_open(const struct lws_plat_file_ops *fops,
-                    const char *filename,
-                    lws_filepos_t *filelen,
+                    const char *vfs_path, const char *vpath,
                     lws_fop_flags_t *flags)
 {
        lws_fop_fd_t fop_fd;
 
        /* call through to original platform implementation */
-       fop_fd = fops_plat.open(fops, filename, filelen, flags);
+       fop_fd = fops_plat.open(fops, vfs_path, vpath, flags);
 
-       lwsl_info("%s: opening %s, ret %p, len %lu\n", __func__, filename,
-                       fop_fd, (long)*filelen);
+       if (fop_fd)
+               lwsl_info("%s: opening %s, ret %p, len %lu\n", __func__,
+                               vfs_path, fop_fd,
+                               (long)lws_vfs_get_length(fop_fd));
+       else
+               lwsl_info("%s: open %s failed\n", __func__, vfs_path);
 
        return fop_fd;
 }
@@ -219,7 +222,7 @@ int main(int argc, char **argv)
        info.port = 7681;
 
        while (n >= 0) {
-               n = getopt_long(argc, argv, "eci:hsap:d:Dr:C:K:A:R:vu:g:P:", options, NULL);
+               n = getopt_long(argc, argv, "eci:hsap:d:Dr:C:K:A:R:vu:g:P:k", options, NULL);
                if (n < 0)
                        continue;
                switch (n) {
@@ -257,6 +260,13 @@ int main(int argc, char **argv)
                        interface_name[(sizeof interface_name) - 1] = '\0';
                        iface = interface_name;
                        break;
+               case 'k':
+                       info.bind_iface = 1;
+#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
+                       info.caps[0] = CAP_NET_RAW;
+                       info.count_caps = 1;
+#endif
+                       break;
                case 'c':
                        close_testing = 1;
                        fprintf(stderr, " Close testing mode -- closes on "