]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/lukemftp/lukemftp.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / lukemftp / lukemftp.h
1 /* $Id: lukemftp.h,v 1.43 2002/06/10 08:13:01 lukem Exp $ */
2
3 #define FTP_PRODUCT     "lukemftp"
4 #define FTP_VERSION     "1.6-beta2"
5
6 #include "config.h"
7
8 #include <sys/types.h>
9 #include <sys/param.h>
10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
12 #include <sys/stat.h>
13 #include <sys/wait.h>
14
15 #include <netinet/in.h>
16 #include <netinet/in_systm.h>
17 #include <netinet/ip.h>
18
19 #include <arpa/ftp.h>
20 #include <arpa/inet.h>
21
22 #include <ctype.h>
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <limits.h>
26 #include <netdb.h>
27 #include <pwd.h>
28 #include <setjmp.h>
29 #include <signal.h>
30 #include <stdarg.h>
31 #include <stddef.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <termios.h>
36 #include <unistd.h>
37
38 #if HAVE_POLL
39 # if HAVE_POLL_H
40 #  include <poll.h>
41 # elif HAVE_SYS_POLL_H
42 #  include <sys/poll.h>
43 # endif
44 #elif HAVE_SELECT
45 # define USE_SELECT
46 #else
47 # error "no poll() or select() found"
48 #endif
49
50 #if HAVE_DIRENT_H
51 # include <dirent.h>
52 #else
53 # define dirent direct
54 # if HAVE_SYS_NDIR_H
55 #  include <sys/ndir.h>
56 # endif
57 # if HAVE_SYS_DIR_H
58 #  include <sys/dir.h>
59 # endif
60 # if HAVE_NDIR_H
61 #  include <ndir.h>
62 # endif
63 #endif
64
65 #if TIME_WITH_SYS_TIME
66 # include <sys/time.h>
67 # include <time.h>
68 #else
69 # if HAVE_SYS_TIME_H
70 #  include <sys/time.h>
71 # else
72 #  include <time.h>
73 # endif
74 #endif
75
76 #if HAVE_ERR_H
77 # include <err.h>
78 #endif
79
80 #if USE_GLOB_H          /* not set by configure; used by other build systems */
81 # include <glob.h>
82 #else
83 # include "ftpglob.h"
84 #endif
85
86 #if HAVE_PATHS_H
87 # include <paths.h>
88 #endif
89 #ifndef _PATH_BSHELL
90 #define _PATH_BSHELL    "/bin/sh"
91 #endif
92 #ifndef _PATH_TMP
93 #define _PATH_TMP       "/tmp/"
94 #endif
95
96 typedef struct _stringlist {
97         char    **sl_str;
98         size_t    sl_max;
99         size_t    sl_cur;
100 } StringList;
101
102 StringList *sl_init(void);
103 int      sl_add(StringList *, char *);
104 void     sl_free(StringList *, int);
105 char    *sl_find(StringList *, char *);
106
107 #if HAVE_TERMCAP_H
108 # include <termcap.h>
109 #else
110 int      tgetent(char *, const char *);
111 char    *tgetstr(const char *, char **);
112 int      tgetflag(const char *);
113 int      tgetnum(const char *);
114 char    *tgoto(const char *, int, int);
115 void     tputs(const char *, int, int (*)(int));
116 #endif
117
118 #if HAVE_UTIL_H
119 # include <util.h>
120 #endif
121
122 #if HAVE_LIBUTIL_H
123 # include <libutil.h>
124 #endif
125
126 #if HAVE_VIS_H
127 # include <vis.h>
128 #else
129 # include "ftpvis.h"
130 #endif
131
132 #if ! HAVE_IN_PORT_T
133 typedef unsigned short in_port_t;
134 #endif
135
136 #if ! HAVE_SA_FAMILY_T
137 typedef unsigned short sa_family_t;
138 #endif
139
140 #if ! HAVE_SOCKLEN_T
141 typedef unsigned int socklen_t;
142 #endif
143
144 #if HAVE_AF_INET6 && HAVE_SOCKADDR_IN6
145 # define INET6
146 #endif
147
148
149 #if ! HAVE_RFC2553_NETDB
150
151                                 /* RFC 2553 */
152 #undef  EAI_ADDRFAMILY
153 #define EAI_ADDRFAMILY   1      /* address family for hostname not supported */
154 #undef  EAI_AGAIN
155 #define EAI_AGAIN        2      /* temporary failure in name resolution */
156 #undef  EAI_BADFLAGS
157 #define EAI_BADFLAGS     3      /* invalid value for ai_flags */
158 #undef  EAI_FAIL
159 #define EAI_FAIL         4      /* non-recoverable failure in name resolution */
160 #undef  EAI_FAMILY
161 #define EAI_FAMILY       5      /* ai_family not supported */
162 #undef  EAI_MEMORY
163 #define EAI_MEMORY       6      /* memory allocation failure */
164 #undef  EAI_NODATA
165 #define EAI_NODATA       7      /* no address associated with hostname */
166 #undef  EAI_NONAME
167 #define EAI_NONAME       8      /* hostname nor servname provided, or not known */
168 #undef  EAI_SERVICE
169 #define EAI_SERVICE      9      /* servname not supported for ai_socktype */
170 #undef  EAI_SOCKTYPE
171 #define EAI_SOCKTYPE    10      /* ai_socktype not supported */
172 #undef  EAI_SYSTEM
173 #define EAI_SYSTEM      11      /* system error returned in errno */
174
175                                 /* KAME extensions? */
176 #undef  EAI_BADHINTS
177 #define EAI_BADHINTS    12
178 #undef  EAI_PROTOCOL
179 #define EAI_PROTOCOL    13
180 #undef  EAI_MAX
181 #define EAI_MAX         14
182
183                                 /* RFC 2553 */
184 #undef  NI_MAXHOST
185 #define NI_MAXHOST      1025
186 #undef  NI_MAXSERV
187 #define NI_MAXSERV      32
188
189 #undef  NI_NOFQDN
190 #define NI_NOFQDN       0x00000001
191 #undef  NI_NUMERICHOST
192 #define NI_NUMERICHOST  0x00000002
193 #undef  NI_NAMEREQD
194 #define NI_NAMEREQD     0x00000004
195 #undef  NI_NUMERICSERV
196 #define NI_NUMERICSERV  0x00000008
197 #undef  NI_DGRAM
198 #define NI_DGRAM        0x00000010
199
200                                 /* RFC 2553 */
201 #undef  AI_PASSIVE
202 #define AI_PASSIVE      0x00000001 /* get address to use bind() */
203 #undef  AI_CANONNAME
204 #define AI_CANONNAME    0x00000002 /* fill ai_canonname */
205
206                                 /* KAME extensions ? */
207 #undef  AI_NUMERICHOST
208 #define AI_NUMERICHOST  0x00000004 /* prevent name resolution */
209 #undef  AI_MASK
210 #define AI_MASK         (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
211
212                                 /* RFC 2553 */
213 #undef  AI_ALL
214 #define AI_ALL          0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */
215 #undef  AI_V4MAPPED_CFG
216 #define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */
217 #undef  AI_ADDRCONFIG
218 #define AI_ADDRCONFIG   0x00000400 /* only if any address is assigned */
219 #undef  AI_V4MAPPED
220 #define AI_V4MAPPED     0x00000800 /* accept IPv4-mapped IPv6 address */
221
222 #endif /* ! HAVE_RFC2553_NETDB */
223
224
225 #if ! HAVE_RFC2553_NETDB && ! HAVE_ADDRINFO
226
227 struct addrinfo {
228         int     ai_flags;       /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
229         int     ai_family;      /* PF_xxx */
230         int     ai_socktype;    /* SOCK_xxx */
231         int     ai_protocol;    /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
232         size_t  ai_addrlen;     /* length of ai_addr */
233         char    *ai_canonname;  /* canonical name for hostname */
234         struct sockaddr *ai_addr;       /* binary address */
235         struct addrinfo *ai_next;       /* next structure in linked list */
236 };
237
238 int     getaddrinfo(const char *, const char *,
239             const struct addrinfo *, struct addrinfo **);
240 int     getnameinfo(const struct sockaddr *, socklen_t, char *,
241             size_t, char *, size_t, int);
242 void    freeaddrinfo(struct addrinfo *);
243 char   *gai_strerror(int);
244
245 #endif /* ! HAVE_RFC2553_NETDB && ! HAVE_ADDRINFO */
246
247
248 #if ! HAVE_D_NAMLEN
249 # define DIRENT_MISSING_D_NAMLEN
250 #endif
251
252 #if ! HAVE_H_ERRNO_D
253 extern int      h_errno;
254 #endif
255 #define HAVE_H_ERRNO    1               /* XXX: an assumption for now... */
256
257 #if ! HAVE_FCLOSE_D
258 int     fclose(FILE *);
259 #endif
260
261 #if ! HAVE_GETPASS_D
262 char    *getpass(const char *);
263 #endif
264
265 #if ! HAVE_OPTARG_D
266 extern char    *optarg;
267 #endif
268
269 #if ! HAVE_OPTIND_D
270 extern int      optind;
271 #endif
272
273 #if ! HAVE_PCLOSE_D
274 int     pclose(FILE *);
275 #endif
276
277 #if ! HAVE_ERR
278 void    err(int, const char *, ...);
279 void    errx(int, const char *, ...);
280 void    warn(const char *, ...);
281 void    warnx(const char *, ...);
282 #endif
283
284 #if ! HAVE_FGETLN
285 char   *fgetln(FILE *, size_t *);
286 #endif
287
288 #if ! HAVE_FSEEKO
289 int     fseeko(FILE *, off_t, int);
290 #endif
291
292 #if ! HAVE_FPARSELN
293 # define FPARSELN_UNESCESC      0x01
294 # define FPARSELN_UNESCCONT     0x02
295 # define FPARSELN_UNESCCOMM     0x04
296 # define FPARSELN_UNESCREST     0x08
297 # define FPARSELN_UNESCALL      0x0f
298 char   *fparseln(FILE *, size_t *, size_t *, const char[3], int);
299 #endif
300
301 #if ! HAVE_INET_NTOP
302 const char *inet_ntop(int, const void *, char *, size_t);
303 #endif
304
305 #if ! HAVE_INET_PTON
306 int inet_pton(int, const char *, void *);
307 #endif
308
309 #if ! HAVE_MKSTEMP
310 int     mkstemp(char *);
311 #endif
312
313 #if ! HAVE_SETPROGNAME
314 const char *getprogname(void);
315 void    setprogname(const char *);
316 #endif
317
318 #if ! HAVE_SNPRINTF
319 int     snprintf(char *, size_t, const char *, ...);
320 #endif
321
322 #if ! HAVE_STRDUP
323 char   *strdup(const char *);
324 #endif
325
326 #if ! HAVE_STRERROR
327 char   *strerror(int);
328 #endif
329
330 #if ! HAVE_STRPTIME || ! HAVE_STRPTIME_D
331 char   *strptime(const char *, const char *, struct tm *);
332 #endif
333
334 #if HAVE_QUAD_SUPPORT
335 # if ! HAVE_STRTOLL && HAVE_LONG_LONG
336 long long strtoll(const char *, char **, int);
337 #  if ! defined(QUAD_MIN)
338 #   define QUAD_MIN     (-0x7fffffffffffffffL-1)
339 #  endif
340 #  if ! defined(QUAD_MAX)
341 #   define QUAD_MAX     (0x7fffffffffffffffL)
342 #  endif
343 # endif
344 #else   /* ! HAVE_QUAD_SUPPORT */
345 # define NO_LONG_LONG   1
346 #endif  /* ! HAVE_QUAD_SUPPORT */
347
348 #if ! HAVE_TIMEGM
349 time_t  timegm(struct tm *);
350 #endif
351
352 #if ! HAVE_HSTRERROR
353 char   *strerror(int);
354 #endif
355
356 #if ! HAVE_STRLCAT
357 size_t  strlcat(char *, const char *, size_t);
358 #endif
359
360 #if ! HAVE_STRLCPY
361 size_t  strlcpy(char *, const char *, size_t);
362 #endif
363
364 #if ! HAVE_STRSEP
365 char   *strsep(char **stringp, const char *delim);
366 #endif
367
368 #if ! HAVE_MEMMOVE
369 # define memmove(a,b,c) bcopy((b),(a),(c))
370         /* XXX: add others #defines for borken systems? */
371 #endif
372
373 #if HAVE_GETPASSPHRASE
374 # define getpass getpassphrase
375 #endif
376
377 #if ! defined(MIN)
378 # define MIN(a, b)      ((a) < (b) ? (a) : (b))
379 #endif
380 #if ! defined(MAX)
381 # define MAX(a, b)      ((a) < (b) ? (b) : (a))
382 #endif
383
384 #if ! defined(timersub)
385 # define timersub(tvp, uvp, vvp)                                        \
386         do {                                                            \
387                 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;          \
388                 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;       \
389                 if ((vvp)->tv_usec < 0) {                               \
390                         (vvp)->tv_sec--;                                \
391                         (vvp)->tv_usec += 1000000;                      \
392                 }                                                       \
393         } while (0)
394 #endif
395
396 #if ! defined(S_ISLNK)
397 # define S_ISLNK(m)     ((m & S_IFMT) == S_IFLNK)
398 #endif
399
400 #define EPOCH_YEAR      1970
401 #define SECSPERHOUR     3600
402 #define SECSPERDAY      86400
403 #define TM_YEAR_BASE    1900