aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ftp.c14
-rw-r--r--lib/strequal.c26
2 files changed, 35 insertions, 5 deletions
diff --git a/lib/ftp.c b/lib/ftp.c
index 069b9d100..123f8dfcd 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -711,6 +711,7 @@ CURLcode _ftp(struct connectdata *conn)
int sslen;
char hbuf[NI_MAXHOST];
char *localaddr;
+ struct sockaddr *sa=(struct sockaddr *)&ss;
#ifdef NI_WITHSCOPEID
const int niflags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
#else
@@ -737,7 +738,10 @@ CURLcode _ftp(struct connectdata *conn)
return CURLE_FTP_PORT_FAILED;
memset(&hints, 0, sizeof(hints));
- hints.ai_family = ss.ss_family;
+ hints.ai_family = sa->sa_family;
+ /*hints.ai_family = ss.ss_family;
+ this way can be used if sockaddr_storage is properly defined, as glibc
+ 2.1.X doesn't do*/
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
if (getaddrinfo(hbuf, "0", &hints, &res))
@@ -770,7 +774,7 @@ CURLcode _ftp(struct connectdata *conn)
}
sslen = sizeof(ss);
- if (getsockname(portsock, (struct sockaddr *)&ss, &sslen) < 0) {
+ if (getsockname(portsock, sa, &sslen) < 0) {
failf(data, strerror(errno));
freeaddrinfo(res);
return CURLE_FTP_PORT_FAILED;
@@ -779,7 +783,7 @@ CURLcode _ftp(struct connectdata *conn)
for (modep = mode; modep && *modep; modep++) {
int lprtaf, eprtaf;
- switch (ss.ss_family) {
+ switch (sa->sa_family) {
case AF_INET:
ap = (char *)&((struct sockaddr_in *)&ss)->sin_addr;
alen = sizeof(((struct sockaddr_in *)&ss)->sin_addr);
@@ -809,7 +813,7 @@ CURLcode _ftp(struct connectdata *conn)
portmsgbuf, sizeof(portmsgbuf), tmp, sizeof(tmp), niflags))
continue;
/* do not transmit IPv6 scope identifier to the wire */
- if (ss.ss_family == AF_INET6) {
+ if (sa->sa_family == AF_INET6) {
char *q = strchr(portmsgbuf, '%');
if (q)
*q = '\0';
@@ -821,7 +825,7 @@ CURLcode _ftp(struct connectdata *conn)
if (strcmp(*modep, "LPRT") == 0 && lprtaf < 0)
continue;
- if (strcmp(*modep, "PORT") == 0 && ss.ss_family != AF_INET)
+ if (strcmp(*modep, "PORT") == 0 && sa->sa_family != AF_INET)
continue;
portmsgbuf[0] = '\0';
diff --git a/lib/strequal.c b/lib/strequal.c
index 82e991cda..97d1f9199 100644
--- a/lib/strequal.c
+++ b/lib/strequal.c
@@ -66,3 +66,29 @@ int Curl_strnequal(const char *first, const char *second, size_t max)
#endif
}
+#ifndef HAVE_STRLCAT
+/*
+ * The strlcat() function appends the NUL-terminated string src to the end
+ * of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-termi-
+ * nating the result.
+ *
+ * The strlcpy() and strlcat() functions return the total length of the
+ * string they tried to create. For strlcpy() that means the length of src.
+ * For strlcat() that means the initial length of dst plus the length of
+ * src. While this may seem somewhat confusing it was done to make trunca-
+ * tion detection simple.
+ */
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+ size_t len = strlen(dst);
+ size_t orglen = len;
+ int index=0;
+
+ while(src[index] && (len < (size-1)) ) {
+ dst[len++] = src[index++];
+ }
+ dst[len]=0;
+
+ return orglen + strlen(src);
+}
+#endif