ACL_SOCKET acl_accept(ACL_SOCKET sock, char *buf, size_t size, int* sock_type) { #ifdef ACL_WINDOWS struct { union { struct sockaddr_in in; } sa; } addr; #else struct { union { struct sockaddr_in in; struct sockaddr_un un; struct sockaddr sa; } sa; } addr; #endif socklen_t len = sizeof(addr); struct sockaddr *sa = (struct sockaddr*) &addr; ACL_SOCKET fd; memset(&addr, 0, sizeof(addr)); fd = acl_sane_accept(sock, sa, &len); if (fd == ACL_SOCKET_INVALID) return fd; if (sock_type != NULL) *sock_type = sa->sa_family; if (buf != NULL && size > 0) { size_t n; #ifndef ACL_WINDOWS if (sa->sa_family == AF_UNIX) snprintf(buf, size, "%s", addr.sa.un.sun_path); #endif if (sa->sa_family != AF_INET) return fd; if (acl_inet_ntoa(addr.sa.in.sin_addr, buf, size) == NULL) return fd; n = strlen(buf); if (n >= size) return fd; snprintf(buf + n, size - n, ":%u", (unsigned short) ntohs(addr.sa.in.sin_port)); buf[size - 1] = 0; } return fd; }
ACL_SOCKET acl_inet_accept_ex(ACL_SOCKET listen_fd, char *ipbuf, size_t size) { struct sockaddr_in client_addr; socklen_t addr_len; ACL_SOCKET fd; memset(&client_addr, 0, sizeof(client_addr)); addr_len = sizeof(client_addr); /* when client_addr not null and protocol is AF_INET, acl_sane_accept * will set nodelay on the accepted socket, 2008.9.4, zsx */ fd = acl_sane_accept(listen_fd, (struct sockaddr *)&client_addr, &addr_len); if (fd == ACL_SOCKET_INVALID) return fd; if (ipbuf != NULL && size > 0 && acl_getpeername(fd, ipbuf, size) < 0) ipbuf[0] = 0; return fd; }
ACL_SOCKET acl_unix_accept(ACL_SOCKET fd) { return (acl_sane_accept(fd, (struct sockaddr *) 0, (socklen_t *) 0)); }