}
static void
-ip_address_to_port_repr (const ip_address *addr, unsigned short port, char *buf,
+ip_address_to_port_repr (const ip_address *addr, int port, char *buf,
size_t buflen)
{
unsigned char *ptr;
ptr = ADDRESS_IPV4_DATA (addr);
snprintf (buf, buflen, "%d,%d,%d,%d,%d,%d", ptr[0], ptr[1],
- ptr[2], ptr[3], (unsigned) (port & 0xff00) >> 8, port & 0xff);
+ ptr[2], ptr[3], (port & 0xff00) >> 8, port & 0xff);
buf[buflen - 1] = '\0';
}
server. Use acceptport after RETR, to get the socket of data
connection. */
uerr_t
-ftp_port (struct rbuf *rbuf)
+ftp_port (struct rbuf *rbuf, int *local_sock)
{
uerr_t err;
char *request, *respline;
ip_address addr;
int nwritten;
- unsigned short port;
+ int port;
/* Must contain the argument of PORT (of the form a,b,c,d,e,f). */
char bytes[6 * 4 + 1];
port = 0;
/* Bind the port. */
- err = bindport (&addr, &port);
+ err = bindport (&addr, &port, local_sock);
if (err != BINDOK)
return err;
if (nwritten < 0)
{
xfree (request);
- closeport (-1);
+ CLOSE (*local_sock);
return WRITEFAILED;
}
xfree (request);
if (err != FTPOK)
{
xfree (respline);
- closeport (-1);
+ CLOSE (*local_sock);
return err;
}
if (*respline != '2')
{
xfree (respline);
- closeport (-1);
+ CLOSE (*local_sock);
return FTPPORTERR;
}
xfree (respline);
#ifdef ENABLE_IPV6
static void
-ip_address_to_lprt_repr (const ip_address *addr, unsigned short port, char *buf,
+ip_address_to_lprt_repr (const ip_address *addr, int port, char *buf,
size_t buflen)
{
unsigned char *ptr;
ptr = ADDRESS_IPV4_DATA (addr);
snprintf (buf, buflen, "%d,%d,%d,%d,%d,%d,%d,%d,%d", 4, 4,
ptr[0], ptr[1], ptr[2], ptr[3], 2,
- (unsigned) (port & 0xff00) >> 8, port & 0xff);
+ (port & 0xff00) >> 8, port & 0xff);
buf[buflen - 1] = '\0';
break;
case IPV6_ADDRESS:
snprintf (buf, buflen, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
6, 16, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7],
ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15], 2,
- (unsigned) (port & 0xff00) >> 8, port & 0xff);
+ (port & 0xff00) >> 8, port & 0xff);
buf[buflen - 1] = '\0';
break;
}
server. Use acceptport after RETR, to get the socket of data
connection. */
uerr_t
-ftp_lprt (struct rbuf *rbuf)
+ftp_lprt (struct rbuf *rbuf, int *local_sock)
{
uerr_t err;
char *request, *respline;
ip_address addr;
int nwritten;
- unsigned short port;
+ int port;
/* Must contain the argument of LPRT (of the form af,n,h1,h2,...,hn,p1,p2). */
char bytes[21 * 4 + 1];
port = 0;
/* Bind the port. */
- err = bindport (&addr, &port);
+ err = bindport (&addr, &port, local_sock);
if (err != BINDOK)
return err;
if (nwritten < 0)
{
xfree (request);
- closeport (-1);
+ CLOSE (*local_sock);
return WRITEFAILED;
}
xfree (request);
if (err != FTPOK)
{
xfree (respline);
- closeport (-1);
+ CLOSE (*local_sock);
return err;
}
if (*respline != '2')
{
xfree (respline);
- closeport (-1);
+ CLOSE (*local_sock);
return FTPPORTERR;
}
xfree (respline);
}
static void
-ip_address_to_eprt_repr (const ip_address *addr, unsigned short port, char *buf,
+ip_address_to_eprt_repr (const ip_address *addr, int port, char *buf,
size_t buflen)
{
int afnum;
server. Use acceptport after RETR, to get the socket of data
connection. */
uerr_t
-ftp_eprt (struct rbuf *rbuf)
+ftp_eprt (struct rbuf *rbuf, int *local_sock)
{
uerr_t err;
char *request, *respline;
ip_address addr;
int nwritten;
- unsigned short port;
+ int port;
/* Must contain the argument of EPRT (of the form |af|addr|port|).
* 4 chars for the | separators, ENABLE_IPV6_ADDRSTRLEN chars for addr
* 1 char for af (1-2) and 5 chars for port (0-65535) */
port = 0;
/* Bind the port. */
- err = bindport (&addr, &port);
+ err = bindport (&addr, &port, local_sock);
if (err != BINDOK)
return err;
if (nwritten < 0)
{
xfree (request);
- closeport (-1);
+ CLOSE (*local_sock);
return WRITEFAILED;
}
xfree (request);
if (err != FTPOK)
{
xfree (respline);
- closeport (-1);
+ CLOSE (*local_sock);
return err;
}
if (*respline != '2')
{
xfree (respline);
- closeport (-1);
+ CLOSE (*local_sock);
return FTPPORTERR;
}
xfree (respline);
transfer. Reads the response from server and parses it. Reads the
host and port addresses and returns them. */
uerr_t
-ftp_pasv (struct rbuf *rbuf, ip_address *addr, unsigned short *port)
+ftp_pasv (struct rbuf *rbuf, ip_address *addr, int *port)
{
char *request, *respline, *s;
int nwritten, i;
transfer. Reads the response from server and parses it. Reads the
host and port addresses and returns them. */
uerr_t
-ftp_lpsv (struct rbuf *rbuf, ip_address *addr, unsigned short *port)
+ftp_lpsv (struct rbuf *rbuf, ip_address *addr, int *port)
{
char *request, *respline, *s;
int nwritten, i, af, addrlen, portlen;
transfer. Reads the response from server and parses it. Reads the
host and port addresses and returns them. */
uerr_t
-ftp_epsv (struct rbuf *rbuf, ip_address *addr, unsigned short *port)
+ftp_epsv (struct rbuf *rbuf, ip_address *ip, int *port)
{
char *request, *respline, *start, delim, *s;
int nwritten, i;
uerr_t err;
- unsigned short tport;
+ int tport;
socklen_t addrlen;
struct sockaddr_storage ss;
struct sockaddr *sa = (struct sockaddr *)&ss;
assert (rbuf != NULL);
assert (rbuf_initialized_p(rbuf));
- assert (addr != NULL);
+ assert (ip != NULL);
assert (port != NULL);
addrlen = sizeof (ss);
assert (sa->sa_family == AF_INET || sa->sa_family == AF_INET6);
- sockaddr_get_address (sa, NULL, addr);
+ sockaddr_get_data (sa, ip, NULL);
/* Form the request. */
/* EPSV 1 means that we ask for IPv4 and EPSV 2 means that we ask for IPv6. */