static FILE *open_socket(len_and_sockaddr *lsa) { FILE *fp; /* glibc 2.4 seems to try seeking on it - ??! */ /* hopefully it understands what ESPIPE means... */ fp = fdopen(xconnect_stream(lsa), "r+"); if (fp == NULL) bb_perror_msg_and_die("fdopen"); return fp; }
static FILE *ftp_login(ftp_host_info_t *server) { printf("ftp_login++++++++++++++++++++\n"); FILE *control_stream; char buf[512]; /* Connect to the command socket */ control_stream = fdopen(xconnect_stream(server->lsa), "r+"); if (control_stream == NULL) { /* fdopen failed - extremely unlikely */ //bb_error_msg_and_die("ftp login"); printf("ftp login"); exit (-1); } printf("ftp_login++11111111111111111111++++++\n"); if (ftpcmd(NULL, NULL, control_stream, buf) != 220) { printf("ftp_die++\n"); //ftp_die(NULL, buf); } printf("ftp_login+++++++2222222222222222222++++\n"); /* Login to the server */ switch (ftpcmd("USER", server->user, control_stream, buf)) { case 230: printf("ftp_login++++230++++++\n"); break; case 331: printf("ftp_login+++++++331++++++++\n"); if (ftpcmd("PASS", server->password, control_stream, buf) != 230) { ftp_die("PASS", buf); printf("ftp_login+++ftp_die++++PAS+++++\n"); } break; default: printf("ftp_login++++++default+++++++\n"); ftp_die("USER", buf); } ftpcmd("TYPE I", NULL, control_stream, buf); printf("ftp_login==================\n"); return control_stream; }
static int xconnect_ftpdata(ftp_host_info_t *server, char *buf) { printf("xconnect_ftpdata++++++++++++++++++++++\n"); char *buf_ptr; unsigned short port_num; /* Response is "NNN garbageN1,N2,N3,N4,P1,P2[)garbage] * Server's IP is N1.N2.N3.N4 (we ignore it) * Server's port for data connection is P1*256+P2 */ buf_ptr = strrchr(buf, ')'); if (buf_ptr) *buf_ptr = '\0'; buf_ptr = strrchr(buf, ','); *buf_ptr = '\0'; port_num = xatoul_range(buf_ptr + 1, 0, 255); buf_ptr = strrchr(buf, ','); *buf_ptr = '\0'; port_num += xatoul_range(buf_ptr + 1, 0, 255) * 256; set_nport(server->lsa, htons(port_num)); printf("xconnect_ftpdata============\n"); return xconnect_stream(server->lsa); }
int xbind_connect(const len_and_sockaddr *lsa, const char *ip) { int fd; /*Start of MNT 2008-10-13 14:40 for 传输超时检测 by z65940*/ g_TimeoutCnt = ATP_CONNECT_TIMEOUT_D; // 每个命令的超时检测 /*End of MNT 2008-10-13 14:40 for by z65940*/ #if 0 /*Added by yehuisheng00183935@20110806 修改IPv6链路地址访问问题--使用链路地址时,必须指定参数"sin6_scope_id"*/ if ( AF_INET6 == lsa->u.sa.sa_family ) { if (IN6_IS_ADDR_LINKLOCAL(&(((struct sockaddr_in6 *)(&(lsa->u.sa)))->sin6_addr))) { ((struct sockaddr_in6 *)(&(lsa->u.sa)))->sin6_scope_id = if_nametoindex("br0"); } } /*Added by yehuisheng00183935@20110806 修改IPv6链路地址访问问题--使用链路地址时,必须指定参数"sin6_scope_id"*/ #endif if (NULL == ip) { // No bind, the same as xconnect_stream fd = xconnect_stream(lsa); /*Start of MNT 2008-10-13 14:40 for 传输超时检测 by z65940*/ g_TimeoutCnt = -1; /*End of MNT 2008-10-13 14:40 for by z65940*/ return fd; } // Bind to specified local interface //fd = create_and_bind_stream_or_die(ip, get_nport(&(lsa->u.sa))); fd = create_and_bind_stream_or_die(ip, 0); xconnect(fd, &(lsa->u.sa), lsa->len); /*Start of MNT 2008-10-13 14:40 for 传输超时检测 by z65940*/ g_TimeoutCnt = -1; /*End of MNT 2008-10-13 14:40 for by z65940*/ return fd; }
#if ENABLE_FEATURE_WGET_TIMEOUT static void alarm_handler(int sig UNUSED_PARAM) { /* This is theoretically unsafe (uses stdio and malloc in signal handler) */ if (G.connecting) bb_error_msg_and_die("download timed out"); } #endif static FILE *open_socket(len_and_sockaddr *lsa) { int fd; FILE *fp; IF_FEATURE_WGET_TIMEOUT(alarm(G.timeout_seconds); G.connecting = 1;) fd = xconnect_stream(lsa); IF_FEATURE_WGET_TIMEOUT(G.connecting = 0;) /* glibc 2.4 seems to try seeking on it - ??! */ /* hopefully it understands what ESPIPE means... */ fp = fdopen(fd, "r+"); if (fp == NULL) bb_perror_msg_and_die(bb_msg_memory_exhausted); return fp; } /* Returns '\n' if it was seen, else '\0'. Trims at first '\r' or '\n' */ /* FIXME: does not respect FEATURE_WGET_TIMEOUT and -T N: */ static char fgets_and_trim(FILE *fp) {