Annotation of embedaddon/php/win32/sockets.c, revision 1.1.1.1
1.1 misho 1: /*
2: +----------------------------------------------------------------------+
3: | PHP Version 5 |
4: +----------------------------------------------------------------------+
5: | Copyright (c) 1997-2012 The PHP Group |
6: +----------------------------------------------------------------------+
7: | This source file is subject to version 3.01 of the PHP license, |
8: | that is bundled with this package in the file LICENSE, and is |
9: | available through the world-wide-web at the following url: |
10: | http://www.php.net/license/3_01.txt |
11: | If you did not receive a copy of the PHP license and are unable to |
12: | obtain it through the world-wide-web, please send a note to |
13: | license@php.net so we can mail you a copy immediately. |
14: +----------------------------------------------------------------------+
15: | Authors: Chris Vandomelen <chrisv@b0rked.dhs.org> |
16: | Sterling Hughes <sterling@php.net> |
17: | |
18: | WinSock: Daniel Beulshausen <daniel@php4win.de> |
19: +----------------------------------------------------------------------+
20: */
21:
22: /* $Id: sockets.c 321634 2012-01-01 13:15:04Z felipe $ */
23:
24: /* Code originally from ext/sockets */
25:
26: #include <stdio.h>
27: #include <fcntl.h>
28:
29: #include "php.h"
30:
31: PHPAPI int socketpair(int domain, int type, int protocol, SOCKET sock[2])
32: {
33: struct sockaddr_in address;
34: SOCKET redirect;
35: int size = sizeof(address);
36:
37: if(domain != AF_INET) {
38: WSASetLastError(WSAENOPROTOOPT);
39: return -1;
40: }
41:
42:
43: sock[0] = socket(domain, type, protocol);
44: address.sin_addr.s_addr = INADDR_ANY;
45: address.sin_family = AF_INET;
46: address.sin_port = 0;
47:
48: bind(sock[0], (struct sockaddr*)&address, sizeof(address));
49:
50: if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
51: }
52:
53: listen(sock[0], 2);
54: sock[1] = socket(domain, type, protocol);
55: address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
56:
57: connect(sock[1], (struct sockaddr*)&address, sizeof(address));
58: redirect = accept(sock[0],(struct sockaddr*)&address, &size);
59:
60: closesocket(sock[0]);
61: sock[0] = redirect;
62:
63: if(sock[0] == INVALID_SOCKET ) {
64: closesocket(sock[0]);
65: closesocket(sock[1]);
66: WSASetLastError(WSAECONNABORTED);
67: return -1;
68: }
69:
70: return 0;
71: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>