static void t_passive(transfer * const tr, ir_uint16 remoteport) { char *msg; ir_uint32 netval; SIGNEDSOCK int addrlen; int retval; updatecontext(); bzero ((char *) &(tr->con.remote), sizeof(tr->con.remote)); tr->con.clientsocket = socket(tr->con.family, SOCK_STREAM, 0); if (tr->con.clientsocket < 0) { t_closeconn(tr, "Socket Error", errno); return; } if (tr->con.family == AF_INET ) { addrlen = sizeof(struct sockaddr_in); tr->con.remote.sin.sin_family = AF_INET; tr->con.remote.sin.sin_port = htons(remoteport); netval = atoul(tr->con.remoteaddr); tr->con.remote.sin.sin_addr.s_addr = htonl(netval); } else { addrlen = sizeof(struct sockaddr_in6); tr->con.remote.sin6.sin6_family = AF_INET6; tr->con.remote.sin6.sin6_port = htons(remoteport); retval = inet_pton(AF_INET6, tr->con.remoteaddr, &(tr->con.remote.sin6.sin6_addr)); if (retval < 0) outerror(OUTERROR_TYPE_WARN_LOUD, "Invalid IP: %s", tr->con.remoteaddr); } if (t_check_ip_access(tr)) return; if (bind_irc_vhost(tr->con.family, tr->con.clientsocket) != 0) { t_closeconn(tr, "Couldn't Bind Virtual Host, Sorry", errno); return; } if (set_socket_nonblocking(tr->con.clientsocket, 1) < 0 ) { outerror(OUTERROR_TYPE_WARN, "Couldn't Set Non-Blocking"); } if (gdata.debug > 0) { msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &(tr->con.remote.sa)); ioutput(OUT_S|OUT_L|OUT_D, COLOR_MAGENTA, "DCC SEND passive sent to %s on %s, connecting to %s", tr->nick, gnetwork->name, msg); mydelete(msg); } alarm(CTIMEOUT); retval = connect(tr->con.clientsocket, &(tr->con.remote.sa), addrlen); if ( (retval < 0) && !((errno == EINPROGRESS) || (errno == EAGAIN)) ) { t_closeconn(tr, "Couldn't Connect", errno); alarm(0); return; } alarm(0); tr->tr_status = TRANSFER_STATUS_CONNECTING; }
void t_setup_send(transfer * const t) { char *msg; SIGNEDSOCK int addrlen; updatecontext(); t->tr_status = TRANSFER_STATUS_SENDING; if (gdata.debug > 0) { ioutput(OUT_S, COLOR_YELLOW, "clientsock = %d", t->con.clientsocket); } if (t->xpack->file_fd == FD_UNUSED) { t->xpack->file_fd = open(t->xpack->file, O_RDONLY | ADDED_OPEN_FLAGS); if (t->xpack->file_fd < 0) { int errno2 = errno; t->xpack->file_fd = FD_UNUSED; outerror(OUTERROR_TYPE_WARN_LOUD,"Cant Access Offered File '%s': %s",t->xpack->file,strerror(errno)); t_closeconn(t, "File Error, Report the Problem to the Owner", errno2); return; } t->xpack->file_fd_location = 0; if (gdata.mirc_dcc64) if (t->xpack->st_size > 0xFFFFFFFFL) t->mirc_dcc64 = 1; } t->bytessent = t->startresume; ir_setsockopt(t->con.clientsocket); t->con.lastcontact = gdata.curtime; t->con.connecttime = gdata.curtime; t->connecttimems = gdata.curtimems; t->lastspeed = t->xpack->minspeed; t->lastspeedamt = t->startresume; addrlen = (t->con.family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6); if ((getpeername(t->con.clientsocket, &(t->con.remote.sa), &(addrlen))) < 0) outerror(OUTERROR_TYPE_WARN, "Couldn't get Remote IP: %s", strerror(errno)); if (t_check_ip_access(t)) return; if (t->con.family == AF_INET) { t->remoteip = ntohl(t->con.remote.sin.sin_addr.s_addr); } if ((getsockname(t->con.clientsocket, &(t->con.local.sa), &(addrlen))) < 0) outerror(OUTERROR_TYPE_WARN, "Couldn't get Local IP: %s", strerror(errno)); msg = mymalloc(maxtextlength); my_getnameinfo(msg, maxtextlength -1, &(t->con.remote.sa)); mydelete(t->con.remoteaddr); t->con.remoteaddr = mystrdup(msg); my_getnameinfo(msg, maxtextlength -1, &(t->con.local.sa)); t->con.localaddr = mystrdup(msg); mydelete(msg); ioutput(OUT_S|OUT_L|OUT_D, COLOR_YELLOW, "XDCC [%02i:%s on %s]: Connection established (%s -> %s)", t->id, t->nick, gdata.networks[ t->net ].name, t->con.remoteaddr, t->con.localaddr); }