vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / at_srv.c
blob14bd089b51012b9609e810cad047b3656f687869
1 #include <stdio.h>
2 #include <kernel/OS.h>
3 #include <string.h>
4 #include <sys/time.h>
5 #include <errno.h>
7 #include "sys/socket.h"
8 #include "netinet/in.h"
9 #include "arpa/inet.h"
10 #include "sys/select.h"
12 // #include "ufunc.h"
14 #define PORT 7772
15 #define HELLO_MSG "Hello from the server\n"
16 #define RESPONSE_MSG "Hello from the client!\n"
18 int main(int argc, char **argv)
20 int sock = socket(AF_INET, SOCK_STREAM, 0);
21 struct sockaddr_in sin;
22 int salen = sizeof(sin);
23 int rv, on = 1;
24 int newsock;
25 char buffer[50];
27 // test_banner("Accept Test - Server");
29 memset(&sin, 0, sizeof(sin));
30 sin.sin_family = AF_INET;
31 sin.sin_port = htons(PORT);
32 sin.sin_len = salen;
33 sin.sin_addr.s_addr = htonl(INADDR_ANY); // LOOPBACK);
34 rv = bind(sock, (const struct sockaddr*)&sin, salen);
35 if (rv < 0)
36 perror("bind");
37 printf("Bound\n");
39 rv = listen(sock, 5);
40 if (rv < 0)
41 perror("listen");
42 printf("Listening\n");
44 newsock = accept(sock, (struct sockaddr*)&sin, &salen);
45 if (newsock < 0)
46 perror("accept");
47 printf("Accepted socket %d\n", newsock);
49 rv = write(newsock, HELLO_MSG, strlen(HELLO_MSG));
50 if (rv < 0)
51 perror("write");
52 printf("Written hello\n");
54 close(newsock);
55 close(sock);
57 return (0);