1/* $NetBSD: tnftp.h,v 1.31 2007/08/06 01:54:38 lukem Exp $ */ 2 3#define FTP_PRODUCT PACKAGE_NAME 4#define FTP_VERSION PACKAGE_VERSION 5 6#include "config.h" 7 8#include <stdio.h> 9#include <ctype.h> 10#include <errno.h> 11 12#if defined(HAVE_SYS_TYPES_H) 13# include <sys/types.h> 14#endif 15#if defined(STDC_HEADERS) 16# include <stdarg.h> 17# include <stdlib.h> 18# include <string.h> 19#endif 20#if defined(HAVE_LIBGEN_H) 21# include <libgen.h> 22#endif 23#if defined(HAVE_UNISTD_H) 24# include <unistd.h> 25#endif 26#if defined(HAVE_POLL_H) 27# include <poll.h> 28#elif defined(HAVE_SYS_POLL_H) 29# include <sys/poll.h> 30#endif 31#if defined(HAVE_SYS_SOCKET_H) 32# include <sys/socket.h> 33#endif 34#if defined(HAVE_NETINET_IN_H) 35# include <netinet/in.h> 36#endif 37#if defined(HAVE_NETINET_IN_SYSTM_H) 38# include <netinet/in_systm.h> 39#endif 40#if defined(HAVE_NETINET_IP_H) 41# include <netinet/ip.h> 42#endif 43#if defined(HAVE_NETDB_H) 44# if HAVE_DECL_AI_NUMERICHOST 45# include <netdb.h> 46# else /* !HAVE_DECL_AI_NUMERICHOST */ 47# define getaddrinfo non_rfc2553_getaddrinfo 48# include <netdb.h> 49# undef getaddrinfo 50# endif /* !HAVE_DECL_AI_NUMERICHOST */ 51#endif 52#if defined(HAVE_ARPA_INET_H) 53# include <arpa/inet.h> 54#endif 55#if defined(HAVE_DIRENT_H) 56# include <dirent.h> 57#else 58# define dirent direct 59# if defined(HAVE_SYS_NDIR_H) 60# include <sys/ndir.h> 61# endif 62# if defined(HAVE_SYS_DIR_H) 63# include <sys/dir.h> 64# endif 65# if defined(HAVE_NDIR_H) 66# include <ndir.h> 67# endif 68#endif 69 70#if defined(HAVE_SYS_IOCTL_H) 71# include <sys/ioctl.h> 72#endif 73#if defined(HAVE_SYS_PARAM_H) 74# include <sys/param.h> 75#endif 76#if defined(HAVE_SYS_STAT_H) 77# include <sys/stat.h> 78#endif 79#if defined(HAVE_SYS_SYSLIMITS_H) 80# include <sys/syslimits.h> 81#endif 82#if defined(HAVE_SYS_WAIT_H) 83# include <sys/wait.h> 84#endif 85 86#if defined(HAVE_ARPA_FTP_H) 87# include <arpa/ftp.h> 88#endif 89 90#if defined(HAVE_FCNTL_H) 91# include <fcntl.h> 92#endif 93#if defined(HAVE_LIMITS_H) 94# include <limits.h> 95#endif 96#if defined(HAVE_PWD_H) 97# include <pwd.h> 98#endif 99#if defined(HAVE_SETJMP_H) 100# include <setjmp.h> 101#endif 102#if defined(HAVE_SIGNAL_H) 103# include <signal.h> 104#endif 105#if defined(HAVE_STDDEF_H) 106# include <stddef.h> 107#endif 108#if defined(HAVE_TERMIOS_H) 109# include <termios.h> 110#endif 111 112#if defined(HAVE_POLL) 113/* we use poll */ 114#elif defined(HAVE_SELECT) 115/* we use select */ 116#else /* !defined(HAVE_POLL) && !defined(HAVE_SELECT) */ 117# error "no poll() or select() found" 118#endif 119#if !defined(POLLIN) 120# define POLLIN 0x0001 121#endif 122#if !defined(POLLOUT) 123# define POLLOUT 0x0004 124#endif 125#if !defined(POLLRDNORM) 126# define POLLRDNORM 0x0040 127#endif 128#if !defined(POLLWRNORM) 129# define POLLWRNORM POLLOUT 130#endif 131#if !defined(POLLRDBAND) 132# define POLLRDBAND 0x0080 133#endif 134#if !defined(INFTIM) 135# define INFTIM -1 136#endif 137#if !defined(HAVE_STRUCT_POLLFD) 138struct pollfd { 139 int fd; 140 short events; 141 short revents; 142}; 143#endif 144 145#if defined(TIME_WITH_SYS_TIME) 146# include <sys/time.h> 147# include <time.h> 148#else 149# if defined(HAVE_SYS_TIME_H) 150# include <sys/time.h> 151# else 152# include <time.h> 153# endif 154#endif 155 156#if defined(HAVE_ERR_H) 157# include <err.h> 158#endif 159 160#if defined(USE_GLOB_H) /* not set by configure; used by other build systems */ 161# include <glob.h> 162#else 163# include "ftpglob.h" 164#endif 165 166#if defined(HAVE_PATHS_H) 167# include <paths.h> 168#endif 169#if !defined(_PATH_BSHELL) 170# define _PATH_BSHELL "/bin/sh" 171#endif 172#if !defined(_PATH_TMP) 173# define _PATH_TMP "/tmp/" 174#endif 175 176typedef struct _stringlist { 177 char **sl_str; 178 size_t sl_max; 179 size_t sl_cur; 180} StringList; 181 182StringList *sl_init(void); 183int sl_add(StringList *, char *); 184void sl_free(StringList *, int); 185char *sl_find(StringList *, char *); 186 187#if defined(HAVE_TERMCAP_H) 188# include <termcap.h> 189#else 190int tgetent(char *, const char *); 191char *tgetstr(const char *, char **); 192int tgetflag(const char *); 193int tgetnum(const char *); 194char *tgoto(const char *, int, int); 195void tputs(const char *, int, int (*)(int)); 196#endif /* !HAVE_TERMCAP_H */ 197 198#if defined(HAVE_VIS_H) && defined(HAVE_STRVIS) && defined(HAVE_STRUNVIS) 199# include <vis.h> 200#else 201# include "ftpvis.h" 202#endif 203 204#if !defined(HAVE_IN_PORT_T) 205typedef unsigned short in_port_t; 206#endif 207 208#if !defined(HAVE_SA_FAMILY_T) 209typedef unsigned short sa_family_t; 210#endif 211 212#if !defined(HAVE_SOCKLEN_T) 213typedef unsigned int socklen_t; 214#endif 215 216#if HAVE_DECL_AF_INET6 \ 217 && defined(HAVE_STRUCT_SOCKADDR_IN6) \ 218 && HAVE_DECL_NS_IN6ADDRSZ 219# define INET6 220#endif 221 222#if !HAVE_DECL_AI_NUMERICHOST 223 224 /* RFC 2553 */ 225#undef EAI_ADDRFAMILY 226#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 227#undef EAI_AGAIN 228#define EAI_AGAIN 2 /* temporary failure in name resolution */ 229#undef EAI_BADFLAGS 230#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 231#undef EAI_FAIL 232#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 233#undef EAI_FAMILY 234#define EAI_FAMILY 5 /* ai_family not supported */ 235#undef EAI_MEMORY 236#define EAI_MEMORY 6 /* memory allocation failure */ 237#undef EAI_NODATA 238#define EAI_NODATA 7 /* no address associated with hostname */ 239#undef EAI_NONAME 240#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 241#undef EAI_SERVICE 242#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 243#undef EAI_SOCKTYPE 244#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 245#undef EAI_SYSTEM 246#define EAI_SYSTEM 11 /* system error returned in errno */ 247 248 /* KAME extensions? */ 249#undef EAI_BADHINTS 250#define EAI_BADHINTS 12 251#undef EAI_PROTOCOL 252#define EAI_PROTOCOL 13 253#undef EAI_MAX 254#define EAI_MAX 14 255 256 /* RFC 2553 */ 257#undef NI_MAXHOST 258#define NI_MAXHOST 1025 259#undef NI_MAXSERV 260#define NI_MAXSERV 32 261 262#undef NI_NOFQDN 263#define NI_NOFQDN 0x00000001 264#undef NI_NUMERICHOST 265#define NI_NUMERICHOST 0x00000002 266#undef NI_NAMEREQD 267#define NI_NAMEREQD 0x00000004 268#undef NI_NUMERICSERV 269#define NI_NUMERICSERV 0x00000008 270#undef NI_DGRAM 271#define NI_DGRAM 0x00000010 272 273 /* RFC 2553 */ 274#undef AI_PASSIVE 275#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 276#undef AI_CANONNAME 277#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 278 279 /* KAME extensions ? */ 280#undef AI_NUMERICHOST 281#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 282#undef AI_MASK 283#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 284 285 /* RFC 2553 */ 286#undef AI_ALL 287#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 288#undef AI_V4MAPPED_CFG 289#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 290#undef AI_ADDRCONFIG 291#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 292#undef AI_V4MAPPED 293#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 294 295#endif /* !HAVE_DECL_AI_NUMERICHOST */ 296 297 298#if !HAVE_DECL_AI_NUMERICHOST && !defined(HAVE_STRUCT_ADDRINFO) \ 299 && !defined(USE_SOCKS) 300 301struct addrinfo { 302 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 303 int ai_family; /* PF_xxx */ 304 int ai_socktype; /* SOCK_xxx */ 305 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 306 socklen_t ai_addrlen; /* length of ai_addr */ 307 char *ai_canonname; /* canonical name for hostname */ 308 struct sockaddr *ai_addr; /* binary address */ 309 struct addrinfo *ai_next; /* next structure in linked list */ 310}; 311 312int getaddrinfo(const char *, const char *, 313 const struct addrinfo *, struct addrinfo **); 314int getnameinfo(const struct sockaddr *, socklen_t, 315 char *, size_t, char *, size_t, int); 316void freeaddrinfo(struct addrinfo *); 317const char *gai_strerror(int); 318 319#endif /* !HAVE_DECL_AI_NUMERICHOST && !defined(HAVE_STRUCT_ADDRINFO) \ 320 && !defined(USE_SOCKS) */ 321 322#if !defined(HAVE_STRUCT_DIRENT_D_NAMLEN) 323# define DIRENT_MISSING_D_NAMLEN 324#endif 325 326#if !HAVE_DECL_H_ERRNO 327extern int h_errno; 328#endif 329#define HAVE_H_ERRNO 1 /* XXX: an assumption for now... */ 330 331#if !HAVE_DECL_FCLOSE 332int fclose(FILE *); 333#endif 334 335#if !HAVE_DECL_GETPASS 336char *getpass(const char *); 337#endif 338 339#if !HAVE_DECL_OPTARG 340extern char *optarg; 341#endif 342 343#if !HAVE_DECL_OPTIND 344extern int optind; 345#endif 346 347#if !HAVE_DECL_PCLOSE 348int pclose(FILE *); 349#endif 350 351#if !HAVE_DECL_DIRNAME 352char *dirname(char *); 353#endif 354 355#if !defined(HAVE_ERR) 356void err(int, const char *, ...); 357void errx(int, const char *, ...); 358void warn(const char *, ...); 359void warnx(const char *, ...); 360#endif 361 362#if !defined(HAVE_FGETLN) 363char *fgetln(FILE *, size_t *); 364#endif 365 366#if !defined(HAVE_FSEEKO) 367int fseeko(FILE *, off_t, int); 368#endif 369 370#if !defined(HAVE_INET_NTOP) 371const char *inet_ntop(int, const void *, char *, socklen_t); 372#endif 373 374#if !defined(HAVE_INET_PTON) 375int inet_pton(int, const char *, void *); 376#endif 377 378#if !defined(HAVE_MKSTEMP) 379int mkstemp(char *); 380#endif 381 382#if !defined(HAVE_SETPROGNAME) 383const char *getprogname(void); 384void setprogname(const char *); 385#endif 386 387#if !defined(HAVE_SNPRINTF) 388int snprintf(char *, size_t, const char *, ...); 389#endif 390 391#if !defined(HAVE_STRDUP) 392char *strdup(const char *); 393#endif 394 395#if !defined(HAVE_STRERROR) 396char *strerror(int); 397#endif 398 399#if !defined(HAVE_STRPTIME) || !HAVE_DECL_STRPTIME 400char *strptime(const char *, const char *, struct tm *); 401#endif 402 403#if defined(HAVE_PRINTF_LONG_LONG) && defined(HAVE_LONG_LONG_INT) 404# if !defined(HAVE_STRTOLL) 405long long strtoll(const char *, char **, int); 406# endif 407# if !defined(LLONG_MIN) 408# define LLONG_MIN (-0x7fffffffffffffffLL-1) 409# endif 410# if !defined(LLONG_MAX) 411# define LLONG_MAX (0x7fffffffffffffffLL) 412# endif 413#else /* !(defined(HAVE_PRINTF_LONG_LONG) && defined(HAVE_LONG_LONG_INT)) */ 414# define NO_LONG_LONG 1 415#endif /* !(defined(HAVE_PRINTF_LONG_LONG) && defined(HAVE_LONG_LONG_INT)) */ 416 417#if !defined(HAVE_TIMEGM) 418time_t timegm(struct tm *); 419#endif 420 421#if !defined(HAVE_STRLCAT) 422size_t strlcat(char *, const char *, size_t); 423#endif 424 425#if !defined(HAVE_STRLCPY) 426size_t strlcpy(char *, const char *, size_t); 427#endif 428 429#if !defined(HAVE_STRSEP) 430char *strsep(char **stringp, const char *delim); 431#endif 432 433#if !defined(HAVE_UTIMES) 434int utimes(const char *, const struct timeval *); 435#endif 436 437#if !defined(HAVE_MEMMOVE) 438# define memmove(a,b,c) bcopy((b),(a),(c)) 439 /* XXX: add others #defines for borken systems? */ 440#endif 441 442#if defined(HAVE_GETPASSPHRASE) 443# define getpass getpassphrase 444#endif 445 446#if !defined(MIN) 447# define MIN(a, b) ((a) < (b) ? (a) : (b)) 448#endif 449#if !defined(MAX) 450# define MAX(a, b) ((a) < (b) ? (b) : (a)) 451#endif 452 453#if !defined(timersub) 454# define timersub(tvp, uvp, vvp) \ 455 do { \ 456 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ 457 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ 458 if ((vvp)->tv_usec < 0) { \ 459 (vvp)->tv_sec--; \ 460 (vvp)->tv_usec += 1000000; \ 461 } \ 462 } while (0) 463#endif 464 465#if !defined(S_ISLNK) 466# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) 467#endif 468 469#define EPOCH_YEAR 1970 470#define SECSPERHOUR 3600 471#define SECSPERDAY 86400 472#define TM_YEAR_BASE 1900 473 474#if defined(USE_SOCKS) /* (Dante) SOCKS5 */ 475#define connect Rconnect 476#define bind Rbind 477#define getsockname Rgetsockname 478#define getpeername Rgetpeername 479#define accept Raccept 480#define rresvport Rrresvport 481#define bindresvport Rbindresvport 482#define gethostbyname Rgethostbyname 483#define gethostbyname2 Rgethostbyname2 484#define sendto Rsendto 485#define recvfrom Rrecvfrom 486#define recvfrom Rrecvfrom 487#define write Rwrite 488#define writev Rwritev 489#define send Rsend 490#define sendmsg Rsendmsg 491#define read Rread 492#define readv Rreadv 493#define recv Rrecv 494#define recvmsg Rrecvmsg 495#define getaddrinfo Rgetaddrinfo 496#define getipnodebyname Rgetipnodebyname 497#endif /* defined(USE_SOCKS) */ 498