Lines Matching refs:buf

107 proxy_read_line(int fd, char *buf, size_t bufsz)
114 if (atomicio(read, fd, buf + off, 1) != 1)
117 if (buf[off] == '\r')
119 if (buf[off] == '\n') {
120 buf[off] = '\0';
125 * on *buf being zero in that case.
157 char buf[1024];
189 buf[0] = SOCKS_V5;
190 buf[1] = 1;
191 buf[2] = SOCKS_NOAUTH;
192 cnt = atomicio(vwrite, proxyfd, buf, 3);
196 cnt = atomicio(read, proxyfd, buf, 2);
200 if ((unsigned char)buf[1] == SOCKS_NOMETHOD)
211 buf[0] = SOCKS_V5;
212 buf[1] = SOCKS_CONNECT;
213 buf[2] = 0;
214 buf[3] = SOCKS_DOMAIN;
215 buf[4] = hlen;
216 (void) memcpy(buf + 5, host, hlen);
217 (void) memcpy(buf + 5 + hlen, &serverport,
223 buf[0] = SOCKS_V5;
224 buf[1] = SOCKS_CONNECT;
225 buf[2] = 0;
226 buf[3] = SOCKS_IPV4;
227 (void) memcpy(buf + 4, &in4->sin_addr,
229 (void) memcpy(buf + 8, &in4->sin_port,
236 buf[0] = SOCKS_V5;
237 buf[1] = SOCKS_CONNECT;
238 buf[2] = 0;
239 buf[3] = SOCKS_IPV6;
240 (void) memcpy(buf + 4, &in6->sin6_addr,
242 (void) memcpy(buf + 20, &in6->sin6_port,
251 cnt = atomicio(vwrite, proxyfd, buf, wlen);
260 cnt = atomicio(read, proxyfd, buf, 10);
263 if (buf[1] != 0)
264 errx(1, "connection failed, SOCKS error %d", buf[1]);
271 buf[0] = SOCKS_V4;
272 buf[1] = SOCKS_CONNECT; /* connect */
273 (void) memcpy(buf + 2, &in4->sin_port, sizeof (in4->sin_port));
274 (void) memcpy(buf + 4, &in4->sin_addr, sizeof (in4->sin_addr));
275 buf[8] = 0; /* empty username */
278 cnt = atomicio(vwrite, proxyfd, buf, wlen);
286 cnt = atomicio(read, proxyfd, buf, 8);
289 if (buf[1] != 90)
290 errx(1, "connection failed, SOCKS error %d", buf[1]);
300 r = snprintf(buf, sizeof (buf),
304 r = snprintf(buf, sizeof (buf),
308 if (r == -1 || (size_t)r >= sizeof (buf))
310 r = strlen(buf);
312 cnt = atomicio(vwrite, proxyfd, buf, r);
320 r = snprintf(buf, sizeof (buf), "%s:%s",
323 if (r == -1 || (size_t)r >= sizeof (buf) ||
324 b64_ntop((unsigned char *)buf, strlen(buf), resp,
327 r = snprintf(buf, sizeof (buf), "Proxy-Authorization: "
329 if (r == -1 || (size_t)r >= sizeof (buf))
331 r = strlen(buf);
332 if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r)
341 (void) proxy_read_line(proxyfd, buf, sizeof (buf));
343 strncmp(buf, HTTP_10_407, strlen(HTTP_10_407)) == 0) {
350 } else if (strncmp(buf, HTTP_10_200,
351 strlen(HTTP_10_200)) != 0 && strncmp(buf, HTTP_11_200,
353 errx(1, "Proxy error: \"%s\"", buf);
357 (void) proxy_read_line(proxyfd, buf, sizeof (buf));
358 if (*buf == '\0')
361 if (*buf != '\0')