Mercurial > gftp.yaz
comparison lib/rfc959.c @ 944:5b681cba67b2
2008-01-24 Brian Masney <masneyb@gftp.org>
* lib/gftp.h lib/rfc959.c lib/protocols.c lib/misc.c - don't store
the structure from getaddrinfo()/gethostbyname() in the
gftp_request structure. Instead, store the address of the current
server in a separate pointer.
author | masneyb |
---|---|
date | Thu, 24 Jan 2008 23:31:26 +0000 |
parents | 4ab11f70a7f4 |
children | 9a6571938f89 |
comparison
equal
deleted
inserted
replaced
943:ca75331d0f82 | 944:5b681cba67b2 |
---|---|
765 | 765 |
766 gftp_lookup_request_option (request, "ignore_pasv_address", | 766 gftp_lookup_request_option (request, "ignore_pasv_address", |
767 &ignore_pasv_address); | 767 &ignore_pasv_address); |
768 if (ignore_pasv_address) | 768 if (ignore_pasv_address) |
769 { | 769 { |
770 #if defined (HAVE_GETADDRINFO) | 770 memcpy (&data_addr.sin_addr, request->remote_addr, |
771 memcpy (&data_addr.sin_addr, | 771 request->remote_addr_len); |
772 &((struct sockaddr_in *) request->current_hostp->ai_addr)->sin_addr, | |
773 sizeof (data_addr.sin_addr)); | |
774 #else | |
775 memcpy (&data_addr.sin_addr, request->hostp->h_addr_list[request->curhost], | |
776 request->hostp->h_length); | |
777 #endif | |
778 | 772 |
779 pos = (char *) &data_addr.sin_addr; | 773 pos = (char *) &data_addr.sin_addr; |
780 request->logging_function (gftp_logging_error, request, | 774 request->logging_function (gftp_logging_error, request, |
781 _("Ignoring IP address in PASV response, connecting to %d.%d.%d.%d:%d\n"), | 775 _("Ignoring IP address in PASV response, connecting to %d.%d.%d.%d:%d\n"), |
782 pos[0] & 0xff, pos[1] & 0xff, pos[2] & 0xff, pos[3] & 0xff, | 776 pos[0] & 0xff, pos[1] & 0xff, pos[2] & 0xff, pos[3] & 0xff, |
869 rfc959_ipv6_data_connection_new (gftp_request * request) | 863 rfc959_ipv6_data_connection_new (gftp_request * request) |
870 { | 864 { |
871 struct sockaddr_in6 data_addr; | 865 struct sockaddr_in6 data_addr; |
872 char *pos, buf[64], *command; | 866 char *pos, buf[64], *command; |
873 intptr_t passive_transfer; | 867 intptr_t passive_transfer; |
874 socklen_t data_addr_len; | |
875 rfc959_parms * parms; | 868 rfc959_parms * parms; |
876 unsigned int port; | 869 unsigned int port; |
877 int resp; | 870 int resp; |
878 | 871 |
879 parms = request->protocol_data; | 872 parms = request->protocol_data; |
893 g_strerror (errno)); | 886 g_strerror (errno)); |
894 | 887 |
895 return (GFTP_ERETRYABLE); | 888 return (GFTP_ERETRYABLE); |
896 } | 889 } |
897 | 890 |
898 data_addr_len = sizeof (data_addr); | |
899 /* This condition shouldn't happen. We better check anyway... */ | 891 /* This condition shouldn't happen. We better check anyway... */ |
900 if (data_addr_len != request->current_hostp->ai_addrlen) | 892 if (sizeof (data_addr) != request->remote_addr_len) |
901 { | 893 { |
902 request->logging_function (gftp_logging_error, request, | 894 request->logging_function (gftp_logging_error, request, |
903 _("Error: It doesn't look like we are connected via IPv6. Aborting connection.\n")); | 895 _("Error: It doesn't look like we are connected via IPv6. Aborting connection.\n")); |
904 gftp_disconnect (request); | 896 gftp_disconnect (request); |
905 return (GFTP_EFATAL); | 897 return (GFTP_EFATAL); |
906 } | 898 } |
907 | 899 |
908 memset (&data_addr, 0, data_addr_len); | 900 memset (&data_addr, 0, sizeof (data_addr)); |
909 data_addr.sin6_family = AF_INET6; | 901 data_addr.sin6_family = AF_INET6; |
910 | 902 |
911 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer); | 903 gftp_lookup_request_option (request, "passive_transfer", &passive_transfer); |
912 if (passive_transfer) | 904 if (passive_transfer) |
913 { | 905 { |
941 request->last_ftp_response); | 933 request->last_ftp_response); |
942 gftp_disconnect (request); | 934 gftp_disconnect (request); |
943 return (GFTP_EFATAL); | 935 return (GFTP_EFATAL); |
944 } | 936 } |
945 | 937 |
946 memcpy (&data_addr, request->current_hostp->ai_addr, data_addr_len); | 938 memcpy (&data_addr, request->remote_addr, request->remote_addr_len); |
947 data_addr.sin6_port = htons (port); | 939 data_addr.sin6_port = htons (port); |
948 | 940 |
949 if (connect (parms->data_connection, (struct sockaddr *) &data_addr, | 941 if (connect (parms->data_connection, (struct sockaddr *) &data_addr, |
950 data_addr_len) == -1) | 942 request->remote_addr_len) == -1) |
951 { | 943 { |
952 request->logging_function (gftp_logging_error, request, | 944 request->logging_function (gftp_logging_error, request, |
953 _("Cannot create a data connection: %s\n"), | 945 _("Cannot create a data connection: %s\n"), |
954 g_strerror (errno)); | 946 g_strerror (errno)); |
955 gftp_disconnect (request); | 947 gftp_disconnect (request); |
956 return (GFTP_ERETRYABLE); | 948 return (GFTP_ERETRYABLE); |
957 } | 949 } |
958 } | 950 } |
959 else | 951 else |
960 { | 952 { |
961 memcpy (&data_addr, request->current_hostp->ai_addr, data_addr_len); | 953 memcpy (&data_addr, request->remote_addr, request->remote_addr_len); |
962 data_addr.sin6_port = 0; | 954 data_addr.sin6_port = 0; |
963 | 955 |
964 if (bind (parms->data_connection, (struct sockaddr *) &data_addr, | 956 if (bind (parms->data_connection, (struct sockaddr *) &data_addr, |
965 data_addr_len) == -1) | 957 request->remote_addr_len) == -1) |
966 { | 958 { |
967 request->logging_function (gftp_logging_error, request, | 959 request->logging_function (gftp_logging_error, request, |
968 _("Cannot bind a port: %s\n"), | 960 _("Cannot bind a port: %s\n"), |
969 g_strerror (errno)); | 961 g_strerror (errno)); |
970 gftp_disconnect (request); | 962 gftp_disconnect (request); |
971 return (GFTP_ERETRYABLE); | 963 return (GFTP_ERETRYABLE); |
972 } | 964 } |
973 | 965 |
974 if (getsockname (parms->data_connection, (struct sockaddr *) &data_addr, | 966 if (getsockname (parms->data_connection, (struct sockaddr *) &data_addr, |
975 &data_addr_len) == -1) | 967 &request->remote_addr_len) == -1) |
976 { | 968 { |
977 request->logging_function (gftp_logging_error, request, | 969 request->logging_function (gftp_logging_error, request, |
978 _("Cannot get socket name: %s\n"), | 970 _("Cannot get socket name: %s\n"), |
979 g_strerror (errno)); | 971 g_strerror (errno)); |
980 gftp_disconnect (request); | 972 gftp_disconnect (request); |
1485 rsize++; | 1477 rsize++; |
1486 } | 1478 } |
1487 | 1479 |
1488 if (rsize != size) | 1480 if (rsize != size) |
1489 { | 1481 { |
1490 tempstr = g_malloc (rsize); | 1482 tempstr = g_malloc0 (rsize); |
1491 | 1483 |
1492 for (i = 0, j = 0; i < size; i++) | 1484 for (i = 0, j = 0; i < size; i++) |
1493 { | 1485 { |
1494 if (i > 0 && buf[i] == '\n' && buf[i - 1] != '\r') | 1486 if (i > 0 && buf[i] == '\n' && buf[i - 1] != '\r') |
1495 tempstr[j++] = '\r'; | 1487 tempstr[j++] = '\r'; |