Attachment 'zerosized_reply.c'
Download 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include <netinet/in.h>
7 #include <arpa/inet.h>
8 #include <assert.h>
9
10 int
11 main(int a, char **b)
12 {
13 struct sockaddr_in S;
14 int s,t,x;
15 s = socket(PF_INET, SOCK_STREAM, 0);
16 assert(s > 0);
17 memset(&S, '\0', sizeof(S));
18 S.sin_family = AF_INET;
19 S.sin_port = htons(80);
20 x = bind(s, (struct sockaddr *) &S, sizeof(S));
21 assert(x == 0);
22 x = listen(s, 10);
23 assert(x == 0);
24 while (1) {
25 struct sockaddr_in F;
26 int fl = sizeof(F);
27 t = accept(s, (struct sockaddr *) &F, &fl);
28 fprintf(stderr, "accpeted FD %d from %s:%d\n",
29 t, inet_ntoa(F.sin_addr), (int)ntohs(F.sin_port));
30 close(t);
31 fprintf(stderr, "closed FD %d\n", t);
32 }
33 return 0;
34 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.