2001-05-18 01:02:37 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2004-01-08 16:18:22 +08:00
|
|
|
| PHP Version 5 |
|
2001-05-18 01:02:37 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2013-01-01 16:37:09 +08:00
|
|
|
| Copyright (c) 1997-2013 The PHP Group |
|
2001-05-18 01:02:37 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2001-05-18 01:02:37 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2001-05-18 01:02:37 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
|
|
|
|
| Sterling Hughes <sterling@php.net> |
|
|
|
|
| |
|
|
|
|
| WinSock: Daniel Beulshausen <daniel@php4win.de> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2003-07-20 02:32:04 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-01-23 23:49:49 +08:00
|
|
|
/* Code originally from ext/sockets */
|
2001-05-18 01:02:37 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
|
2009-01-23 23:49:49 +08:00
|
|
|
PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
|
|
|
|
{
|
2001-05-18 01:02:37 +08:00
|
|
|
struct sockaddr_in address;
|
|
|
|
SOCKET redirect;
|
|
|
|
int size = sizeof(address);
|
|
|
|
|
|
|
|
if(domain != AF_INET) {
|
2009-01-23 23:49:49 +08:00
|
|
|
WSASetLastError(WSAENOPROTOOPT);
|
2001-05-18 01:02:37 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-23 23:49:49 +08:00
|
|
|
sock[0] = socket(domain, type, protocol);
|
|
|
|
address.sin_addr.s_addr = INADDR_ANY;
|
2001-05-18 01:02:37 +08:00
|
|
|
address.sin_family = AF_INET;
|
|
|
|
address.sin_port = 0;
|
|
|
|
|
|
|
|
bind(sock[0], (struct sockaddr*)&address, sizeof(address));
|
|
|
|
|
2009-01-23 23:49:49 +08:00
|
|
|
if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
|
|
|
|
}
|
2001-05-18 01:02:37 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-01-23 23:49:49 +08:00
|
|
|
closesocket(sock[0]);
|
2001-05-18 01:02:37 +08:00
|
|
|
sock[0] = redirect;
|
|
|
|
|
|
|
|
if(sock[0] == INVALID_SOCKET ) {
|
2009-01-23 23:49:49 +08:00
|
|
|
closesocket(sock[0]);
|
|
|
|
closesocket(sock[1]);
|
|
|
|
WSASetLastError(WSAECONNABORTED);
|
2001-05-18 01:02:37 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|