348{
352 int oerrno;
353 volatile int sockfd = -1;
354 volatile int sock2fd = -1;
356 char **volatile curaddr;
358 char *volatile fhost;
359 unsigned int fport;
360#ifndef NO_SIGNALS
364 int sj;
365#endif
366 const char *firstLine, *secondLine, *srvr;
367
370#ifdef NO_SIGNALS
372#endif
373
377 } else {
380 }
381 if (fport == 0)
383
384
385
386
390
391
392 fport = (
unsigned int)
htons((
unsigned short) fport);
393
395
397
399
400
401
406 }
408 cip->
servCtlAddr.sin_addr.s_addr = ip_address.s_addr;
409 } else {
411
412 }
413
414
415
416
417
418
419
421
422
423
424
425
430 }
431
432
433
434
435
436
438
439#ifdef NO_SIGNALS
441
446 sockfd = -1;
447 }
448#else
453 }
454
455 vcip = cip;
456
457#ifdef HAVE_SIGSETJMP
459#else
460 sj =
setjmp(gCancelConnectJmp);
461#endif
462
463 if (sj != 0) {
464
470 }
475 }
else if (
gGotSig == SIGALRM) {
479 } else {
482 }
484 } else {
490 }
492 }
493
498 sockfd = -1;
499 }
500#endif
501 } else {
502
503
504
510 }
511
512
513
514
516
517
518
519
520
521
523
524#ifdef NO_SIGNALS
526
528 break;
532 sockfd = -1;
533#else
534
539 }
540
541 vcip = cip;
542#ifdef HAVE_SIGSETJMP
544#else
545 sj =
setjmp(gCancelConnectJmp);
546#endif
547
548 if (sj != 0) {
549
555 }
560 }
else if (
gGotSig == SIGALRM) {
564 } else {
567 }
569 } else {
575 }
577 }
578
580 break;
584 sockfd = -1;
585#endif
586 }
587 }
588
590
591
592
593
594
596#ifdef ENETDOWN
598#elif defined(WSAENETDOWN)
600#endif
601#ifdef ENETUNREACH
603#elif defined(WSAENETUNREACH)
605#endif
606#ifdef ECONNABORTED
608#elif defined(WSAECONNABORTED)
610#endif
611#ifdef ETIMEDOUT
613#elif defined(WSAETIMEDOUT)
615#endif
616#ifdef EHOSTDOWN
618#elif defined(WSAEHOSTDOWN)
620#endif
621#ifdef ECONNRESET
623#elif defined(WSAECONNRESET)
625#endif
626 Error(cip,
kDoPerror,
"Could not connect to %s -- try again later.\n", fhost);
628 break;
629#ifdef ECONNREFUSED
631#elif defined(WSAECONNREFUSED)
633#endif
636 break;
637 default:
640 }
642 }
643
644
647
648#ifdef SO_OOBINLINE
649
650
651
653#endif
656
657#if defined(IP_TOS) && defined(IPTOS_LOWDELAY)
658
659
660
662#endif
663
664#ifdef NO_SIGNALS
670
676 }
677#else
678 if ((sock2fd =
dup(sockfd)) < 0) {
681 Error(cip,
kDoPerror,
"Could not duplicate a file descriptor.\n");
683 }
684
685
686
687
693 }
694
702 }
703
706
707
708
709
710
711#ifdef HAVE_SETLINEBUF
712 setlinebuf(cip->
cin);
713 setlinebuf(cip->
cout);
714#else
717#endif
718#endif
719
720#ifdef HAVE_INET_NTOP
723#else
725#endif
728 else
730
731
738 }
739
743 }
751
752 if (
strstr(firstLine,
"Version wu-") !=
NULL) {
754 srvr = "wu-ftpd";
755 }
else if (
strstr(firstLine,
"NcFTPd") !=
NULL) {
757 srvr = "NcFTPd Server";
758 }
else if (
STRNEQ(
"ProFTPD", firstLine, 7)) {
760 srvr = "ProFTPD";
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)) {
769 srvr = "WFTPD";
770 }
else if (
STRNEQ(
"Serv-U FTP", firstLine, 10)) {
772 srvr = "Serv-U FTP-Server";
773 }
else if (
strstr(firstLine,
"VFTPD") !=
NULL) {
775 srvr = "VFTPD";
776 }
else if (
STRNEQ(
"FTP-Max", firstLine, 7)) {
778 srvr = "FTP-Max";
779 }
else if (
strstr(firstLine,
"Roxen") !=
NULL) {
781 srvr = "Roxen";
782 }
else if (
strstr(firstLine,
"WS_FTP") !=
NULL) {
784 srvr = "WS_FTP Server";
785 }
else if ((secondLine !=
NULL) && (
strstr(secondLine,
"WarFTP") !=
NULL)) {
787 srvr = "WarFTPd";
788 }
789
791 PrintF(cip,
"Remote server is running %s.\n", srvr);
792
793
796 }
797
799
800
801
802
808 }
814
816 if (sockfd > 0)
818 if (sock2fd > 0)
825}
int SConnect(int sfd, const struct sockaddr_in *const addr, int tlen)
char * strstr(char *String1, char *String2)
int SetTypeOfService(const FTPCIPtr, int, int)
int SetInlineOutOfBandData(const FTPCIPtr, int)
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
static int GetSocketAddress(const FTPCIPtr cip, int sockfd, struct sockaddr_in *saddr)
char gLibNcFTPVersion[64]
int SetLinger(const FTPCIPtr cip, int sockfd, int onoff)
static struct hostent * GetHostEntry(char *host, struct in_addr *ip_address)
int SetKeepAlive(const FTPCIPtr cip, int sockfd)
int SetSockBufSize(int sockfd, size_t rsize, size_t ssize)
void PrintF(const FTPCIPtr cip, const char *const fmt,...)
int InitSReadlineInfo(SReadlineInfo *, int, char *, size_t, int, int)
int sigsetjmp(sigjmp_buf buf, int savesigs)
#define kFirewallNotInUse
#define kServerTypeWS_FTP
#define kServerTypeNcFTPd
#define kServerTypeWuFTPd
void DoneWithResponse(const FTPCIPtr, ResponsePtr)
#define kServerTypeNetWareFTP
#define kServerTypeFTP_Max
#define kServerTypeServ_U
int GetResponse(const FTPCIPtr, ResponsePtr)
#define kServerTypeProFTPD
#define kServerTypeMicrosoftFTP
#define LIBNCFTP_USE_VAR(a)
ResponsePtr InitResponse(void)
#define kServerTypeWarFTPd
#define kServerTypeUnknown
#define kErrConnectRetryableErr
#define kErrNewStreamSocket
#define kErrConnectMiscErr
#define kErrConnectRefused
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
struct sockaddr_in ourCtlAddr
unsigned int firewallPort
size_t ctrlSocketRBufSize
FTPConnectMessageProc onConnectMsgProc
size_t ctrlSocketSBufSize
const char *WSAAPI inet_ntop(int af, const void *src, char *dst, size_t cnt)
void fatal(const char *msg)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList