comparison dbutil.c @ 500:d588e3ea557a agent-client

propagate from branch 'au.asn.ucc.matt.dropbear' (head 4fb35083f0f46ea667e7043e7d4314aecd3df46c) to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 833d0adef6cdbf43ea75283524c665e70b0ee1ee)
author Matt Johnston <matt@ucc.asn.au>
date Tue, 23 Sep 2008 16:05:04 +0000
parents b956d6151600 c1e9c81d1d27
children cf376c696dfc
comparison
equal deleted inserted replaced
499:f3ca5ebc319a 500:d588e3ea557a
293 293
294 TRACE(("leave dropbear_listen: success, %d socks bound", nsock)) 294 TRACE(("leave dropbear_listen: success, %d socks bound", nsock))
295 return nsock; 295 return nsock;
296 } 296 }
297 297
298 /* Connect to a given unix socket. The socket is not non-blocking */
299 #ifdef ENABLE_CONNECT_UNIX
300 int connect_unix(const char* addr)
301 {
302 struct sockaddr_un egdsock;
303 int fd = -1;
304
305 memset((void*)&egdsock, 0x0, sizeof(egdsock));
306 egdsock.sun_family = AF_UNIX;
307 strlcpy(egdsock.sun_path, addr, sizeof(egdsock.sun_path));
308
309 fd = socket(PF_UNIX, SOCK_STREAM, 0);
310
311 return fd;
312 }
313 #endif
314
298 /* Connect via TCP to a host. Connection will try ipv4 or ipv6, will 315 /* Connect via TCP to a host. Connection will try ipv4 or ipv6, will
299 * return immediately if nonblocking is set. On failure, if errstring 316 * return immediately if nonblocking is set. On failure, if errstring
300 * wasn't null, it will be a newly malloced error message */ 317 * wasn't null, it will be a newly malloced error message */
301 318
302 /* TODO: maxfd */ 319 /* TODO: maxfd */
339 err = errno; 356 err = errno;
340 continue; 357 continue;
341 } 358 }
342 359
343 if (nonblocking) { 360 if (nonblocking) {
344 if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { 361 setnonblocking(sock);
345 close(sock);
346 sock = -1;
347 if (errstring != NULL && *errstring == NULL) {
348 *errstring = m_strdup("Failed non-blocking");
349 }
350 TRACE(("Failed non-blocking: %s", strerror(errno)))
351 continue;
352 }
353 } 362 }
354 363
355 if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { 364 if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) {
356 if (errno == EINPROGRESS && nonblocking) { 365 if (errno == EINPROGRESS && nonblocking) {
357 TRACE(("Connect in progress")) 366 TRACE(("Connect in progress"))