102{
103 char buf[512];
104 char *t, *s;
105 unsigned char l[6];
106 uint32_t *a;
107 unsigned short *p;
108
109 snprintf (buf, 7, "PASV\r\n");
111 bzero (buf, sizeof (buf));
112 bzero (addr, sizeof (struct sockaddr_in));
113 if (
recv_line (soc, buf,
sizeof (buf) - 1) < 0)
114 return 1;
115
116 if (strncmp (buf, "227", 3) != 0)
117 return 1;
118
119 t = strchr (buf, '(');
120 if (t == NULL)
121 return 1;
122 t++;
123 s = strchr (t, ',');
124 if (s == NULL)
125 return 1;
126
127 s[0] = '\0';
128
129 l[0] = (unsigned char) atoi (t);
130 s++;
131 t = strchr (s, ',');
132 if (t == NULL)
133 return 1;
134 t[0] = 0;
135 l[1] = (unsigned char) atoi (s);
136 t++;
137 s = strchr (t, ',');
138 if (s == NULL)
139 return 1;
140 s[0] = 0;
141 l[2] = (unsigned char) atoi (t);
142 s++;
143 t = strchr (s, ',');
144 if (t == NULL)
145 return 1;
146 t[0] = 0;
147 l[3] = (unsigned char) atoi (s);
148 t++;
149 s = strchr (t, ',');
150 if (s == NULL)
151 return 1;
152 s[0] = 0;
153 l[4] = (unsigned char) atoi (t);
154 s++;
155 t = strchr (s, ')');
156 if (t == NULL)
157 return 1;
158 t[0] = 0;
159 l[5] = (unsigned char) atoi (s);
160 a = (uint32_t *) l;
161 p = (unsigned short *) (l + 4);
162
163 addr->sin_addr.s_addr = *a;
164 addr->sin_port = *p;
165 addr->sin_family = AF_INET;
166 return 0;
167}
int write_stream_connection(int fd, void *buf0, int n)
int recv_line(int soc, char *buf, size_t bufsiz)
Reads a text from the socket stream into the argument buffer, always.