xref: /aosp_15_r20/external/libcap/contrib/capso/bind.c (revision 2810ac1b38eead2603277920c78344c84ddf3aff)
1 /*
2  * Unprivileged program that binds to port 80. It does this by
3  * leveraging a file capable shared library.
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/socket.h>
9 #include <unistd.h>
10 
11 #include "capso.h"
12 
main(int argc,char ** argv)13 int main(int argc, char **argv) {
14     int f = bind80("127.0.0.1");
15     if (f < 0) {
16 	perror("unable to bind to port 80");
17 	exit(1);
18     }
19     if (listen(f, 10) == -1) {
20 	perror("unable to listen to port 80");
21 	exit(1);
22     }
23     printf("Webserver code to use filedes = %d goes here.\n"
24 	   "(Sleeping for 60s... Try 'netstat -tlnp|grep :80')\n", f);
25     fflush(stdout);
26     sleep(60);
27     close(f);
28     printf("Done.\n");
29 }
30