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.
12 #include "config.h" /* configuration options for current OS */
15 #ifdef HAVE_SYS_TYPES_H
16 #include <sys/types.h>
19 #include <sys/param.h>
20 #include <sys/socket.h>
22 #ifdef HAVE_SYS_SELECT_H
23 #include <sys/select.h>
26 #ifndef HAVE_ADDRINFO_STRUCT
32 #include <machine/endian.h> /* required before tcp.h, for BYTE_ORDER */
34 #include <netinet/tcp.h> /* TCP_NODELAY */
35 #include <netdb.h> /* getservbyname(), gethostbyname() */
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
44 /* Older resolvers do not have gethostbyname2() */
45 #ifndef HAVE_GETHOSTBYNAME2
46 #define gethostbyname2(host,family) gethostbyname((host))
49 /* This avoids a warning with glibc compilation */
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 */
71 extern int chunkwrite
;
73 extern int connectudp
;
78 extern char foreignip
[];
79 extern int foreignport
;
81 extern int ignorewerr
;
88 extern char localip
[];
95 extern int pauseclose
;
97 extern int pauselisten
;
100 extern int reuseport
;
103 extern int recvdstaddr
;
104 extern int rcvbuflen
;
105 extern int sndbuflen
;
106 extern long rcvtimeo
;
107 extern long sndtimeo
;
112 extern int sourcesink
;
113 extern int sroute_cnt
;
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)
128 #define INET_NTOA(foo) inet_ntoa(foo)
131 /* function prototypes */
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
*);
139 void pattern(char *, int);
140 int servopen(char *, char *);
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);