+#ifdef INET6
+uerr_t
+ftp_eprt (struct rbuf *rbuf)
+{
+ uerr_t err;
+
+ char *request, *respline;
+ ip_address in_addr;
+ unsigned short port;
+
+ char ipv6 [8 * (4 * 3 + 3) + 8];
+ char *bytes;
+
+ /* Setting port to 0 lets the system choose a free port. */
+ port = 0;
+ err = bindport (&port, ip_default_family);
+ if (err != BINDOK) /* Bind the port. */
+ return err;
+
+ /* Get the address of this side of the connection. */
+ if (!conaddr (RBUF_FD (rbuf), &in_addr))
+ /* Huh? This is not BINDERR! */
+ return BINDERR;
+ inet_ntop (AF_INET6, &in_addr, ipv6, sizeof (ipv6));
+
+ /* Construct the argument of EPRT (of the form |2|IPv6.ascii|PORT.ascii|). */
+ bytes = alloca (3 + strlen (ipv6) + 1 + numdigit (port) + 1 + 1);
+ sprintf (bytes, "|2|%s|%u|", ipv6, port);
+ /* Send PORT request. */
+ request = ftp_request ("EPRT", bytes);
+ if (0 > iwrite (RBUF_FD (rbuf), request, strlen (request)))
+ {
+ closeport (port);
+ xfree (request);
+ return WRITEFAILED;
+ }
+ xfree (request);
+ /* Get appropriate response. */
+ err = ftp_response (rbuf, &respline);
+ if (err != FTPOK)
+ {
+ closeport (port);
+ xfree (respline);
+ return err;
+ }
+ if (*respline != '2')
+ {
+ closeport (port);
+ xfree (respline);
+ return FTPPORTERR;
+ }
+ xfree (respline);
+ return FTPOK;
+}
+#endif
+