1 #include <sys/types.h>
2 #include <sys/socket.h>
3
4 #include <arpa/inet.h>
5 #include <netinet/in.h>
6
7 #include <err.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 static void
usage(const char * cmd)13 usage(const char *cmd)
14 {
15 fprintf(stderr, "%s -n count\n", cmd);
16 exit(1);
17 }
18
19 int
main(int argc,char * argv[])20 main(int argc, char *argv[])
21 {
22 int i, opt, count;
23
24 count = 0;
25 while ((opt = getopt(argc, argv, "n:")) != -1) {
26 switch (opt) {
27 case 'n':
28 count = strtol(optarg, NULL, 10);
29 break;
30
31 default:
32 usage(argv[0]);
33 }
34 }
35 if (count == 0)
36 usage(argv[0]);
37
38 for (i = 0; i < count; ++i) {
39 int s;
40
41 s = socket(AF_INET, SOCK_DGRAM, 0);
42 if (s < 0)
43 err(2, "socket failed");
44 close(s);
45 }
46 printf("done\n");
47 exit(0);
48 }
49