/* * bbftpc/getdatasock.c * Copyright (C) 1999, 2000, 2001, 2002 IN2P3, CNRS * bbftp@in2p3.fr * http://doc.in2p3.fr/bbftp * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /**************************************************************************** getdatasock.c v 0.0.0 2000/01/11 v 1.6.0 2000/03/24 - Set Receive buffer to TCPWINSIZE for the get option v 1.7.1 2000/04/04 - Variable cleaning (detected on IRIX) v 1.8.7 2000/05/28 - Change headers v 1.8.9 2000/08/08 - Add timestamp v 1.9.0 2000/08/21 - Use configure to help portage v 2.0.0 2000/03/19 - Use protocol version 2 v 2.0.1 2001/04/19 - Correct indentation - Port to IRIX *****************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include extern int debug ; extern int timestamp ; extern int *myports ; extern int *mysockets ; extern int warning ; extern int transferoption ; extern int sendwinsize ; extern int recvwinsize ; extern struct sockaddr_in myctladdr ; extern int pasvport_min ; extern int pasvport_max ; int getdatasock(int nbsock, int *errcode) { int i ; int tcpwinsize ; int on = 1 ; #if defined(SUNOS) || defined(_HPUX_SOURCE) || defined(IRIX) int addrlen ; #else size_t addrlen ; #endif struct linger li ; struct sockaddr_in sck ; int *mysockfree ; int *myportfree; int port ; /* Declaring the variables need to change the value of the TOS */ int tos_value, tos_len; int qbss_value = 0x20; tos_len = sizeof(tos_value); mysockfree = mysockets ; myportfree = myports ; sck = myctladdr ; for (i=0 ; i= 0) break; } if (port>pasvport_max) { printmessage(stderr,CASE_ERROR,95,timestamp,"Cannot bind on data socket : %s\n",strerror(errno)); *errcode = 95 ; return -1 ; } } else { if ( bind(*mysockfree, (struct sockaddr *) &sck ,sizeof(sck)) < 0) { printmessage(stderr,CASE_ERROR,95,timestamp,"Cannot bind on data socket : %s\n",strerror(errno)); *errcode = 95 ; return -1 ; } } addrlen = sizeof(sck) ; if (getsockname(*mysockfree,(struct sockaddr *)&sck, &addrlen) < 0) { printmessage(stderr,CASE_ERROR,96,timestamp,"Cannot getsockname on data socket : %s\n",strerror(errno)); *errcode = 96 ; return -1 ; } if (listen(*mysockfree, 1) < 0) { printmessage(stderr,CASE_ERROR,97,timestamp,"Cannot listen on data socket : %s\n",strerror(errno)); *errcode = 97 ; return -1 ; } *myportfree++ = sck.sin_port ; if ( debug ) printmessage(stdout,CASE_NORMAL,0,timestamp,"Listen on port %d\n", ntohs(sck.sin_port)) ; mysockfree++ ; } return 0 ; }