Back to index

php5  5.3.10
Functions
sockets.c File Reference
#include <stdio.h>
#include <fcntl.h>
#include "php.h"

Go to the source code of this file.

Functions

PHPAPI int socketpair (int domain, int type, int protocol, SOCKET sock[2])

Function Documentation

PHPAPI int socketpair ( int  domain,
int  type,
int  protocol,
SOCKET  sock[2] 
)

Definition at line 31 of file sockets.c.

{
       struct sockaddr_in address;
       SOCKET redirect;
       int size = sizeof(address);

       if(domain != AF_INET) {
              WSASetLastError(WSAENOPROTOOPT);
              return -1;
       }


       sock[0]                            = socket(domain, type, protocol);
       address.sin_addr.s_addr            = INADDR_ANY;
       address.sin_family          = AF_INET;
       address.sin_port            = 0;

       bind(sock[0], (struct sockaddr*)&address, sizeof(address));

       if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
       }

       listen(sock[0], 2);
       sock[1] = socket(domain, type, protocol); 
       address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

       connect(sock[1], (struct sockaddr*)&address, sizeof(address));
       redirect = accept(sock[0],(struct sockaddr*)&address, &size);

       closesocket(sock[0]);
       sock[0] = redirect;

       if(sock[0] == INVALID_SOCKET ) {
              closesocket(sock[0]);
              closesocket(sock[1]);
              WSASetLastError(WSAECONNABORTED);
              return -1;
       }
       
       return 0;
}

Here is the caller graph for this function: