PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket() { PROsfd osfd; osfd = _PR_MD_SOCKET(AF_INET6, SOCK_STREAM, 0); if (osfd != -1) { _PR_MD_CLOSE_SOCKET(osfd); return PR_TRUE; } return PR_FALSE; }
PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto) { PRInt32 osfd; int one = 1; PRFileDesc *fd; if (!_pr_initialized) _PR_ImplicitInitialization(); if (AF_INET != domain #if defined(_PR_INET6) && AF_INET6 != domain #endif ) { PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0); return NULL; } osfd = _PR_MD_SOCKET(domain, type, proto); if (osfd == -1) { return 0; } #ifdef HAVE_SOCKET_KEEPALIVE /* "Keep-alive" packets are specific to TCP. */ if (domain == AF_INET && type == SOCK_STREAM) { if (setsockopt(osfd, (int)SOL_SOCKET, SO_KEEPALIVE, (const void *) &one, sizeof(one) ) < 0) { _PR_MD_CLOSE_SOCKET(osfd); return 0; } } #endif if (type == SOCK_STREAM) fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods()); else fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods()); /* * Make the sockets non-blocking */ if (fd != NULL) _PR_MD_MAKE_NONBLOCK(fd); else _PR_MD_CLOSE_SOCKET(osfd); return fd; }
PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto) { PROsfd osfd; PRFileDesc *fd; PRInt32 tmp_domain = domain; if (!_pr_initialized) _PR_ImplicitInitialization(); if (PR_AF_INET != domain && PR_AF_INET6 != domain #if defined(XP_UNIX) || defined(XP_OS2) && PR_AF_LOCAL != domain #endif ) { PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0); return NULL; } #if defined(_PR_INET6_PROBE) if (PR_AF_INET6 == domain) domain = _pr_ipv6_is_present() ? AF_INET6 : AF_INET; #elif defined(_PR_INET6) if (PR_AF_INET6 == domain) domain = AF_INET6; #else if (PR_AF_INET6 == domain) domain = AF_INET; #endif /* _PR_INET6 */ osfd = _PR_MD_SOCKET(domain, type, proto); if (osfd == -1) { return 0; } if (type == SOCK_STREAM) fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods()); else fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods()); /* * Make the sockets non-blocking */ if (fd != NULL) { _PR_MD_MAKE_NONBLOCK(fd); _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE); #ifdef _PR_NEED_SECRET_AF fd->secret->af = domain; #endif #if defined(_PR_INET6_PROBE) || !defined(_PR_INET6) /* * For platforms with no support for IPv6 * create layered socket for IPv4-mapped IPv6 addresses */ if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) { if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) { PR_Close(fd); fd = NULL; } } #endif } else _PR_MD_CLOSE_SOCKET(osfd); return fd; }