diff options
author | Jakub Sławiński | 2005-08-05 21:45:31 +0200 |
---|---|---|
committer | Joshua Judson Rosen | 2014-07-17 21:14:59 +0200 |
commit | 43e8714797d40bcf63efab428dcd25f9caf1d52b (patch) | |
tree | 796974a873a97f2a44f872f3dd3587508e35aa64 /src/client_reverse_udp.c | |
parent | v0.7.1 (diff) | |
download | apf-43e8714797d40bcf63efab428dcd25f9caf1d52b.tar.gz |
v0.7.2
- Added: http proxy basic authorization
- Fixed: logging initialization after some value checking
- Fixed: auto-reconnect failure when --nossl option is set
- Added: auto-reconnect when afserver is not reachable on start
- Added: auto-reconnect after normal afserver quit
- Added: per user statistics: idle time, amount of downloaded/uploaded bytes
and current download/upload rate
- Added: support for https proxies
- Added: possibility to bind sockets on different interfaces
- Fixed: receiving incomplete headers from afclient
- Fixed: close user connections by afclient
Diffstat (limited to 'src/client_reverse_udp.c')
-rw-r--r-- | src/client_reverse_udp.c | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/src/client_reverse_udp.c b/src/client_reverse_udp.c index 8c78386..c0a1ef4 100644 --- a/src/client_reverse_udp.c +++ b/src/client_reverse_udp.c @@ -24,11 +24,13 @@ #include <stdlib.h> -void -initialize_client_reverse_udp(int* usernum, clifd* master, char* name, char* manage, char ipfam) +int +initialize_client_reverse_udp(int* usernum, SslFd* master, char* name, char* manage, char ipfam, + char wanttoexit) { + int tmp; (*usernum) = 1; - if (ip_connect(&(master->commfd), name, manage, ipfam)) { + if (ip_connect(&tmp, name, manage, ipfam)) { #ifdef AF_INET6 aflog(LOG_T_INIT, LOG_I_CRIT, "tcp_connect_%s error for %s, %s", @@ -37,13 +39,21 @@ initialize_client_reverse_udp(int* usernum, clifd* master, char* name, char* man aflog(LOG_T_INIT, LOG_I_CRIT, "tcp_connect error for %s, %s", name, manage); #endif - exit(1); + if (wanttoexit) { + exit(1); + } + else { + return 1; + } + } - master->ssl = NULL; + SslFd_set_fd(master, tmp); + SslFd_set_ssl(master, NULL); + return 0; } void -client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* despor, char type, +client_reverse_udp(ConnectUser** contable, SslFd* master, char* desnam, char* despor, char type, unsigned char* buff, int buflength) { char ipfam; @@ -61,7 +71,7 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de ipfam |= 0x04; } #endif - if (ip_listen(&(contable[0].connfd), desnam, despor, &addrlen, ipfam)) { + if (ip_listen(&temp, desnam, despor, &addrlen, ipfam)) { #ifdef AF_INET6 aflog(LOG_T_INIT, LOG_I_DEBUG, "udp_listen_%s error for %s, %s", @@ -72,18 +82,20 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de #endif exit(1); } + ConnectUser_set_connFd(contable[0], temp); cliaddr = malloc(addrlen); FD_ZERO(&allset); - FD_SET(master->commfd, &allset); - maxfdp1 = master->commfd + 1; - maxfdp1 = (maxfdp1>contable[0].connfd+1) ? maxfdp1 : contable[0].connfd+1; - FD_SET(contable[0].connfd, &allset); + FD_SET(SslFd_get_fd(master), &allset); + maxfdp1 = SslFd_get_fd(master) + 1; + maxfdp1 = (maxfdp1 > (ConnectUser_get_connFd(contable[0]) + 1)) ? + maxfdp1 : (ConnectUser_get_connFd(contable[0]) + 1); + FD_SET(ConnectUser_get_connFd(contable[0]), &allset); aflog(LOG_T_CLIENT, LOG_I_INFO, "CLIENT STARTED mode: udp reverse"); for ( ; ; ) { len = 4; - if (getsockopt(master->commfd, SOL_SOCKET, SO_SNDBUF, &temp, &len) != -1) { + if (getsockopt(SslFd_get_fd(master), SOL_SOCKET, SO_SNDBUF, &temp, &len) != -1) { if (temp != buflength) { buflength = temp; aflog(LOG_T_CLIENT, LOG_I_WARNING, @@ -98,13 +110,13 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de aflog(LOG_T_MAIN, LOG_I_DEBUG, "after select..."); - if (FD_ISSET(contable[0].connfd, &rset)) { /* FD_ISSET CONTABLE[0].CONNFD RSET*/ - n = recvfrom(contable[0].connfd, &buff[5], 8091, 0, cliaddr, &len); + if (FD_ISSET(ConnectUser_get_connFd(contable[0]), &rset)) { /* FD_ISSET CONTABLE[0].CONNFD RSET*/ + n = recvfrom(ConnectUser_get_connFd(contable[0]), &buff[5], 8091, 0, cliaddr, &len); #ifdef HAVE_LINUX_SOCKIOS_H # ifdef SIOCOUTQ aflog(LOG_T_MAIN, LOG_I_DDEBUG, "SIOCOUTQ is defined"); - if (ioctl(master->commfd, SIOCOUTQ, ¬sent)) { + if (ioctl(SslFd_get_fd(master), SIOCOUTQ, ¬sent)) { aflog(LOG_T_CLIENT, LOG_I_CRIT, "ioctl error -> exiting..."); exit(1); @@ -115,7 +127,7 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de # else aflog(LOG_T_MAIN< LOG_I_DDEBUG, "TIOCOUTQ is defined"); - if (ioctl(master->commfd, TIOCOUTQ, ¬sent)) { + if (ioctl(SslFd_get_fd(master), TIOCOUTQ, ¬sent)) { aflog(LOG_T_CLIENT, LOG_I_CRIT, "ioctl error -> exiting..."); exit(1); @@ -146,15 +158,15 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de buff[2] = AF_S_MESSAGE; buff[3] = n >> 8; buff[4] = n; - writen(master->commfd, buff, n + 5); + writen(SslFd_get_fd(master), buff, n + 5); } #ifdef HAVE_LINUX_SOCKIOS_H } #endif } /* - FD_ISSET CONTABLE[0].CONNFD RSET */ - if (FD_ISSET(master->commfd, &rset)) { /* FD_ISSET MASTER.COMMFD RSET */ - n = readn(master->commfd, buff, 5); + if (FD_ISSET(SslFd_get_fd(master), &rset)) { /* FD_ISSET MASTER.COMMFD RSET */ + n = readn(SslFd_get_fd(master), buff, 5); if (n == 5) { if ((buff[0] != AF_S_MESSAGE) || (buff[1] != AF_S_LOGIN) || (buff[2] != AF_S_MESSAGE)) { aflog(LOG_T_CLIENT, LOG_I_CRIT, @@ -164,7 +176,7 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de length = buff[3]; length = length << 8; length += buff[4]; /* this is length of message */ - n = readn(master->commfd, buff, length); + n = readn(SslFd_get_fd(master), buff, length); } else { n = 0; @@ -176,7 +188,7 @@ client_reverse_udp(ConnectuserT* contable, clifd* master, char* desnam, char* de } aflog(LOG_T_CLIENT, LOG_I_INFO, "Sending %d bytes to user (TO:%s)", n, sock_ntop(cliaddr, addrlen, NULL, NULL, 0)); - sendto(contable[0].connfd, buff, n, 0, cliaddr, addrlen); + sendto(ConnectUser_get_connFd(contable[0]), buff, n, 0, cliaddr, addrlen); } /* - FD_ISSET MASTER.COMMFD RSET */ } exit(0); /* we shouldn't get here */ |