vfs: check userland buffers before reading them.
[haiku.git] / src / tests / kits / net / sock / sock.h
blobc001c58dfc750453df034965626b418a83adfd52
1 /* -*- c-basic-offset: 8; -*-
3 * Copyright (c) 1993 W. Richard Stevens. All rights reserved.
4 * Permission to use or modify this software and its documentation only for
5 * educational purposes and without fee is hereby granted, provided that
6 * the above copyright notice appear in all copies. The author makes no
7 * representations about the suitability of this software for any purpose.
8 * It is provided "as is" without express or implied warranty.
9 */
12 #include "config.h" /* configuration options for current OS */
14 #include <stdio.h>
15 #ifdef HAVE_SYS_TYPES_H
16 #include <sys/types.h>
17 #endif
18 #include <errno.h>
19 #include <sys/param.h>
20 #include <sys/socket.h>
22 #ifdef HAVE_SYS_SELECT_H
23 #include <sys/select.h>
24 #endif
26 #ifndef HAVE_ADDRINFO_STRUCT
27 #include "addrinfo.h"
28 #endif
30 #include <sys/uio.h>
31 #ifdef __bsdi__
32 #include <machine/endian.h> /* required before tcp.h, for BYTE_ORDER */
33 #endif
34 #include <netinet/tcp.h> /* TCP_NODELAY */
35 #include <netdb.h> /* getservbyname(), gethostbyname() */
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 #include <string.h>
39 #include <stdlib.h>
40 #include <unistd.h>
44 /* Older resolvers do not have gethostbyname2() */
45 #ifndef HAVE_GETHOSTBYNAME2
46 #define gethostbyname2(host,family) gethostbyname((host))
47 #endif
49 /* This avoids a warning with glibc compilation */
50 #ifndef errno
51 extern int errno;
52 #endif
55 /* Miscellaneous constants */
56 #define MAXLINE 4096 /* max text line length */
57 #define MAXSOCKADDR 128 /* max socket address structure size */
58 #define BUFFSIZE 8192 /* buffer size for reads and writes */
60 /* stdin and stdout file descriptors */
61 #define STDIN_FILENO 0
62 #define STDOUT_FILENO 1
64 #define min(a,b) ((a) < (b) ? (a) : (b))
65 #define max(a,b) ((a) > (b) ? (a) : (b))
67 /* declare global variables */
68 extern int bindport;
69 extern int broadcast;
70 extern int cbreak;
71 extern int chunkwrite;
72 extern int client;
73 extern int connectudp;
74 extern int crlf;
75 extern int debug;
76 extern int dofork;
77 extern int dontroute;
78 extern char foreignip[];
79 extern int foreignport;
80 extern int halfclose;
81 extern int ignorewerr;
82 extern int iptos;
83 extern int ipttl;
84 extern char joinip[];
85 extern int keepalive;
86 extern long linger;
87 extern int listenq;
88 extern char localip[];
89 extern int maxseg;
90 extern int mcastttl;
91 extern int msgpeek;
92 extern int nodelay;
93 extern int nbuf;
94 extern int onesbcast;
95 extern int pauseclose;
96 extern int pauseinit;
97 extern int pauselisten;
98 extern int pauserw;
99 extern int reuseaddr;
100 extern int reuseport;
101 extern int readlen;
102 extern int writelen;
103 extern int recvdstaddr;
104 extern int rcvbuflen;
105 extern int sndbuflen;
106 extern long rcvtimeo;
107 extern long sndtimeo;
108 extern char *rbuf;
109 extern char *wbuf;
110 extern int server;
111 extern int sigio;
112 extern int sourcesink;
113 extern int sroute_cnt;
114 extern int udp;
115 extern int urgwrite;
116 extern int verbose;
117 extern int usewritev;
119 extern struct sockaddr_in cliaddr, servaddr;
121 /* Earlier versions of gcc under SunOS 4.x have problems passing arguments
122 that are structs (as opposed to pointers to structs). This shows up
123 with inet_ntoa, whose argument is a "struct in_addr". */
125 #if defined(sun) && defined(__GNUC__) && defined(GCC_STRUCT_PROBLEM)
126 #define INET_NTOA(foo) inet_ntoa(&foo)
127 #else
128 #define INET_NTOA(foo) inet_ntoa(foo)
129 #endif
131 /* function prototypes */
132 void buffers(int);
133 int cliopen(char *, char *);
134 int crlf_add(char *, int, const char *, int);
135 int crlf_strip(char *, int, const char *, int);
136 void join_mcast(int, struct sockaddr_in *);
137 void loop_tcp(int);
138 void loop_udp(int);
139 void pattern(char *, int);
140 int servopen(char *, char *);
141 void sink_tcp(int);
142 void sink_udp(int);
143 void source_tcp(int);
144 void source_udp(int);
145 void sroute_doopt(int, char *);
146 void sroute_set(int);
147 void sleep_us(unsigned int);
148 void sockopts(int, int);
149 ssize_t dowrite(int, const void *, size_t);
151 void TELL_WAIT(void);
152 void TELL_PARENT(pid_t);
153 void WAIT_PARENT(void);
154 void TELL_CHILD(pid_t);
155 void WAIT_CHILD(void);
157 void err_dump(const char *, ...);
158 void err_msg(const char *, ...);
159 void err_quit(const char *, ...);
160 void err_ret(const char *, ...);
161 void err_sys(const char *, ...);
163 ssize_t writen(int, const void *, size_t);