Lines Matching refs:buf

91 proxy_read_line(int fd, char *buf, size_t bufsz)
98 if (atomicio(read, fd, buf + off, 1) != 1)
101 if (buf[off] == '\r')
103 if (buf[off] == '\n') {
104 buf[off] = '\0';
133 unsigned char buf[1024];
165 buf[0] = SOCKS_V5;
166 buf[1] = 1;
167 buf[2] = SOCKS_NOAUTH;
168 cnt = atomicio(vwrite, proxyfd, buf, 3);
172 cnt = atomicio(read, proxyfd, buf, 2);
176 if (buf[1] == SOCKS_NOMETHOD)
187 buf[0] = SOCKS_V5;
188 buf[1] = SOCKS_CONNECT;
189 buf[2] = 0;
190 buf[3] = SOCKS_DOMAIN;
191 buf[4] = hlen;
192 memcpy(buf + 5, host, hlen);
193 memcpy(buf + 5 + hlen, &serverport, sizeof serverport);
198 buf[0] = SOCKS_V5;
199 buf[1] = SOCKS_CONNECT;
200 buf[2] = 0;
201 buf[3] = SOCKS_IPV4;
202 memcpy(buf + 4, &in4->sin_addr, sizeof in4->sin_addr);
203 memcpy(buf + 8, &in4->sin_port, sizeof in4->sin_port);
208 buf[0] = SOCKS_V5;
209 buf[1] = SOCKS_CONNECT;
210 buf[2] = 0;
211 buf[3] = SOCKS_IPV6;
212 memcpy(buf + 4, &in6->sin6_addr, sizeof in6->sin6_addr);
213 memcpy(buf + 20, &in6->sin6_port,
221 cnt = atomicio(vwrite, proxyfd, buf, wlen);
225 cnt = atomicio(read, proxyfd, buf, 4);
228 if (buf[1] != 0)
229 errx(1, "connection failed, SOCKS error %d", buf[1]);
230 switch (buf[3]) {
232 cnt = atomicio(read, proxyfd, buf + 4, 6);
237 cnt = atomicio(read, proxyfd, buf + 4, 18);
250 buf[0] = SOCKS_V4;
251 buf[1] = SOCKS_CONNECT; /* connect */
252 memcpy(buf + 2, &in4->sin_port, sizeof in4->sin_port);
253 memcpy(buf + 4, &in4->sin_addr, sizeof in4->sin_addr);
254 buf[8] = 0; /* empty username */
257 cnt = atomicio(vwrite, proxyfd, buf, wlen);
261 cnt = atomicio(read, proxyfd, buf, 8);
264 if (buf[1] != 90)
265 errx(1, "connection failed, SOCKS error %d", buf[1]);
275 r = snprintf(buf, sizeof(buf),
279 r = snprintf(buf, sizeof(buf),
283 if (r == -1 || (size_t)r >= sizeof(buf))
285 r = strlen(buf);
287 cnt = atomicio(vwrite, proxyfd, buf, r);
295 r = snprintf(buf, sizeof(buf), "%s:%s",
297 if (r == -1 || (size_t)r >= sizeof(buf) ||
298 b64_ntop(buf, strlen(buf), resp,
301 r = snprintf(buf, sizeof(buf), "Proxy-Authorization: "
303 if (r == -1 || (size_t)r >= sizeof(buf))
305 r = strlen(buf);
306 if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r)
315 proxy_read_line(proxyfd, buf, sizeof(buf));
317 strncmp(buf, "HTTP/1.0 407 ", 12) == 0) {
324 } else if (strncmp(buf, "HTTP/1.0 200 ", 12) != 0 &&
325 strncmp(buf, "HTTP/1.1 200 ", 12) != 0)
326 errx(1, "Proxy error: \"%s\"", buf);
330 proxy_read_line(proxyfd, buf, sizeof(buf));
331 if (*buf == '\0')
334 if (*buf != '\0')