github.com/olljanat/moby@v1.13.1/contrib/syscall-test/socket.c (about)

     1  #include <stdio.h>
     2  #include <unistd.h>
     3  #include <sys/types.h>
     4  #include <sys/socket.h>
     5  #include <netinet/in.h>
     6  #include <arpa/inet.h>
     7  
     8  int main() {
     9  	int s;
    10  	struct sockaddr_in sin;
    11  
    12  	s = socket(AF_INET, SOCK_STREAM, 0);
    13  	if (s == -1) {
    14  		perror("socket");
    15  		return 1;
    16  	}
    17  
    18  	sin.sin_family = AF_INET;
    19  	sin.sin_addr.s_addr = INADDR_ANY;
    20  	sin.sin_port = htons(80);
    21  
    22  	if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
    23  		perror("bind");
    24  		return 1;
    25  	}
    26  
    27  	close(s);
    28  
    29  	return 0;
    30  }