8 #define _libncftp_ftp_c_ 21 static jmp_buf gCancelConnectJmp;
28 static char gCopyright[] =
"@(#) LibNcFTP Copyright 1995-2000, by Mike Gleason. All rights reserved.";
36 # define accept Raccept 37 # define connect Rconnect 38 # define getsockname Rgetsockname 39 # define listen Rlisten 71 if (ip_address !=
NULL)
114 if ((
cp !=
NULL) && (
cp[1] !=
'\0')) {
121 for (curAlias = hp->
h_aliases; *curAlias !=
NULL; curAlias++) {
123 if ((
cp !=
NULL) && (
cp[1] !=
'\0')) {
139 # if defined(HAVE_RES_INIT) && defined(HAVE__RES_DEFDNAME) 142 if ((_res.defdname !=
NULL) && (_res.defdname[0] !=
'\0')) {
154 fp =
fopen(
"/etc/resolv.conf",
"r");
163 if (
strcmp(tok,
"domain") == 0) {
318 Error(cip,
kDoPerror,
"Could not set out of band inline mode.\n");
332 CancelConnect(
int signum)
335 #ifdef HAVE_SIGSETJMP 353 volatile int sockfd = -1;
354 volatile int sock2fd = -1;
356 char **
volatile curaddr;
358 char *
volatile fhost;
366 const char *firstLine, *secondLine, *srvr;
392 fport = (
unsigned int)
htons((
unsigned short) fport);
457 #ifdef HAVE_SIGSETJMP 460 sj =
setjmp(gCancelConnectJmp);
475 }
else if (
gGotSig == SIGALRM) {
542 #ifdef HAVE_SIGSETJMP 545 sj =
setjmp(gCancelConnectJmp);
560 }
else if (
gGotSig == SIGALRM) {
598 #elif defined(WSAENETDOWN) 603 #elif defined(WSAENETUNREACH) 608 #elif defined(WSAECONNABORTED) 613 #elif defined(WSAETIMEDOUT) 618 #elif defined(WSAEHOSTDOWN) 623 #elif defined(WSAECONNRESET) 626 Error(cip,
kDoPerror,
"Could not connect to %s -- try again later.\n", fhost);
631 #elif defined(WSAECONNREFUSED) 657 #if defined(IP_TOS) && defined(IPTOS_LOWDELAY) 678 if ((sock2fd =
dup(sockfd)) < 0) {
681 Error(cip,
kDoPerror,
"Could not duplicate a file descriptor.\n");
711 #ifdef HAVE_SETLINEBUF 712 setlinebuf(cip->
cin);
713 setlinebuf(cip->
cout);
720 #ifdef HAVE_INET_NTOP 752 if (
strstr(firstLine,
"Version wu-") !=
NULL) {
755 }
else if (
strstr(firstLine,
"NcFTPd") !=
NULL) {
757 srvr =
"NcFTPd Server";
758 }
else if (
STRNEQ(
"ProFTPD", firstLine, 7)) {
761 }
else if (
strstr(firstLine,
"Microsoft FTP Service") !=
NULL) {
763 srvr =
"Microsoft FTP Service";
764 }
else if (
strstr(firstLine,
"(NetWare ") !=
NULL) {
766 srvr =
"NetWare FTP Service";
767 }
else if (
STRNEQ(
"WFTPD", firstLine, 5)) {
770 }
else if (
STRNEQ(
"Serv-U FTP", firstLine, 10)) {
772 srvr =
"Serv-U FTP-Server";
773 }
else if (
strstr(firstLine,
"VFTPD") !=
NULL) {
776 }
else if (
STRNEQ(
"FTP-Max", firstLine, 7)) {
779 }
else if (
strstr(firstLine,
"Roxen") !=
NULL) {
782 }
else if (
strstr(firstLine,
"WS_FTP") !=
NULL) {
784 srvr =
"WS_FTP Server";
785 }
else if ((secondLine !=
NULL) && (
strstr(secondLine,
"WarFTP") !=
NULL)) {
791 PrintF(cip,
"Remote server is running %s.\n", srvr);
869 #ifdef PRINTF_LONG_LONG 874 result =
RCmd(cip, rp,
"REST %ld", (
long) restartPt);
915 #define UC(x) (int) (((int) x) & 0xff) 920 result =
RCmd(cip, rp,
"PORT %d,%d,%d,%d,%d,%d",
983 &
i[0], &
i[1], &
i[2], &
i[3], &
i[4], &
i[5]) != 6) {
988 for (
j=0, *weird = 0;
j<6;
j++) {
993 if ((
i[
j] < 0) || (
i[
j] > 255))
995 n[
j] = (
unsigned char) (
i[
j] & 0xff);
1016 unsigned short port;
1019 if (((
int) ephemLo == 0) || ((
int) ephemLo >= (
int) ephemHi)) {
1028 rangesize = (
int) ((
int) ephemHi - (
int) ephemLo);
1030 for (
i=0;
i<10;
i++) {
1031 port = (
unsigned short) (((
int)
rand() % rangesize) + (
int) ephemLo);
1089 #ifdef HAVE_LIBSOCKS 1147 #ifdef HAVE_LIBSOCKS 1191 #elif defined(WSAECONNREFUSED) 1194 Error(cip,
kDontPerror,
"Server sent back a bogus port number.\nI will fall back to PORT instead of PASV mode.\n");
1230 #if defined(IP_TOS) && defined(IPTOS_THROUGHPUT) 1255 unsigned short remoteDataPort;
1256 unsigned short remoteCtrlPort;
1279 if (newSocket < 0) {
1289 if ((
int) remoteDataPort != ((
int) remoteCtrlPort - 1)) {
1290 Error(cip,
kDontPerror,
"Data connection did not originate on correct port!\n");
1296 Error(cip,
kDontPerror,
"Data connection did not originate from remote server!\n");
void DisposeSReadlineInfo(SReadlineInfo *)
#define kServerTypeWarFTPd
#define kServerTypeWuFTPd
#define kErrBindDataSocket
#define kServerTypeWS_FTP
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
#define kErrAcceptDataSocket
#define kCommandAvailable
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
int RCmd(const FTPCIPtr, ResponsePtr, const char *,...)
int SetStartOffset(const FTPCIPtr cip, longest_int restartPt)
#define kServerTypeNcFTPd
ACPI_SIZE strlen(const char *String)
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
int InitSReadlineInfo(SReadlineInfo *, int, char *, size_t, int, int)
void CloseDataConnection(const FTPCIPtr cip)
char * strstr(char *String1, char *String2)
void CloseControlConnection(const FTPCIPtr cip)
#define kServerTypeServ_U
void DoneWithResponse(const FTPCIPtr, ResponsePtr)
#define kErrSetStartPoint
#define STRNCPY(dst, src, n)
void SendTelnetInterrupt(const FTPCIPtr cip)
#define kErrSetTypeOfService
static int GetSocketAddress(const FTPCIPtr cip, int sockfd, struct sockaddr_in *saddr)
#define kFirewallNotInUse
#define LIBNCFTP_USE_VAR(a)
INT WSAAPI connect(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
int SConnect(int sfd, const struct sockaddr_in *const addr, int tlen)
struct sockaddr_in ourCtlAddr
size_t dataSocketSBufSize
char * Strncat(char *const, const char *const, const size_t)
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
#define kServerTypeNetWareFTP
#define kErrPassiveModeFailed
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define UNIMPLEMENTED_CMD(a)
_Check_return_ int __cdecl rand(void)
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
int GetOurHostName(char *host, size_t siz)
#define kErrServerSentBogusPortNumber
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
FTPConnectMessageProc onConnectMsgProc
static struct hostent * GetHostEntry(char *host, struct in_addr *ip_address)
#define kServerTypeMicrosoftFTP
#define kServerTypeUnknown
size_t ctrlSocketSBufSize
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define kErrConnectRefused
#define kFallBackToSendPortMode
int longjmp(jmp_buf buf, int retval)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
void siglongjmp(sigjmp_buf buf, int val)
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
int OpenDataConnection(const FTPCIPtr cip, int mode)
_CRTIMP int __cdecl getpid(void)
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
int sigsetjmp(sigjmp_buf buf, int savesigs)
int SetTypeOfService(const FTPCIPtr, int, int)
#define kErrConnectDataSocket
int SClose(int sfd, int tlen)
static int Passive(const FTPCIPtr cip, struct sockaddr_in *saddr, int *weird)
#define kClosedFileDescriptor
#define memcpy(s1, s2, n)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
int AcceptDataConnection(const FTPCIPtr cip)
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
size_t dataSocketRBufSize
#define kCommandNotAvailable
int OpenControlConnection(const FTPCIPtr cip, char *host, unsigned int port)
int SetSockBufSize(int sockfd, size_t rsize, size_t ssize)
#define kErrConnectMiscErr
int GetResponse(const FTPCIPtr, ResponsePtr)
struct sockaddr_in servDataAddr
struct sockaddr_in ourDataAddr
void PrintF(const FTPCIPtr cip, const char *const fmt,...)
int SetKeepAlive(const FTPCIPtr cip, int sockfd)
void fatal(const char *msg)
int SetInlineOutOfBandData(const FTPCIPtr, int)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
size_t ctrlSocketRBufSize
struct sockaddr_in servCtlAddr
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
char gLibNcFTPVersion[64]
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
char * Strncpy(char *const, const char *const, const size_t)
static int SendPort(const FTPCIPtr cip, struct sockaddr_in *saddr)
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
void HangupOnServer(const FTPCIPtr cip)
#define kErrNewStreamSocket
unsigned int firewallPort
static int BindToEphemeralPortNumber(int sockfd, struct sockaddr_in *addrp, int ephemLo, int ephemHi)
char * strtok(char *String, const char *Delimiters)
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
int SetLinger(const FTPCIPtr cip, int sockfd, int onoff)
char * strchr(const char *String, int ch)
_Check_return_ _CRTIMP int __cdecl dup(_In_ int _FileHandle)
int strcmp(const char *String1, const char *String2)
const char *WSAAPI inet_ntop(int af, const void *src, char *dst, size_t cnt)
#define kErrListenDataSocket
static const char * onoff(int bool)
#define kErrConnectRetryableErr
GLboolean GLboolean GLboolean GLboolean a
ResponsePtr InitResponse(void)
#define kErrSetOutOfBandInline
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
#define kServerTypeProFTPD
#define kServerTypeFTP_Max
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *