1 #include <stdio.h> 2 #include <string.h> 3 4 #include <sys/socket.h> 5 #include <netinet/in.h> 6 #include <arpa/inet.h> 7 #include <fcntl.h> 8 9 10 int main(int argc, char **argv) 11 { 12 int sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); 13 if (sock < 0) { 14 printf("Failed! Socket could not be created.\n"); 15 return -1; 16 } 17 int flags = fcntl(sock, F_GETFD); 18 int ret = 0; 19 if ((flags & FD_CLOEXEC) == 0) { 20 printf("Failed! Descriptor flag not found.\n"); 21 ret = -1; 22 } 23 close(sock); 24 25 printf("Test complete.\n"); 26 27 return ret; 28 } 29 30