29 struct sockaddr_in address;
31 int size =
sizeof(address);
34 WSASetLastError(WSAENOPROTOOPT);
38 sock[1] = redirect = INVALID_SOCKET;
40 sock[0] = socket(domain,
type, protocol);
41 if (INVALID_SOCKET == sock[0]) {
45 address.sin_addr.s_addr = INADDR_ANY;
49 if (bind(sock[0], (
struct sockaddr *) &address,
sizeof(address)) != 0) {
53 if (getsockname(sock[0], (
struct sockaddr *) &address, &
size) != 0) {
57 if (listen(sock[0], 2) != 0) {
62 sock[1] = socket(domain,
type, protocol);
64 sock[1] = WSASocket(domain,
type, protocol,
NULL, 0, 0);
67 if (INVALID_SOCKET == sock[1]) {
71 address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
72 if (connect(sock[1], (
struct sockaddr *) &address,
sizeof(address)) != 0) {
76 redirect = accept(sock[0], (
struct sockaddr *) &address, &
size);
77 if (INVALID_SOCKET == redirect) {
90 WSASetLastError(WSAECONNABORTED);