~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/sockets/php_sockets_win.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   +----------------------------------------------------------------------+
 
3
   | PHP Version 5                                                        |
 
4
   +----------------------------------------------------------------------+
 
5
   | Copyright (c) 1997-2004 The PHP Group                                |
 
6
   +----------------------------------------------------------------------+
 
7
   | This source file is subject to version 3.0 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_0.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: php_sockets_win.c,v 1.11 2004/01/08 08:17:27 andi Exp $ */
 
23
 
 
24
 
 
25
#ifdef PHP_WIN32
 
26
 
 
27
#include <stdio.h>
 
28
#include <fcntl.h>
 
29
 
 
30
#include "php.h"
 
31
#include "php_sockets.h"
 
32
#include "php_sockets_win.h"
 
33
 
 
34
int socketpair(int domain, int type, int protocol, SOCKET sock[2]) {
 
35
        struct sockaddr_in address;
 
36
        SOCKET redirect;
 
37
        int size = sizeof(address);
 
38
 
 
39
        if(domain != AF_INET) {
 
40
                set_errno(WSAENOPROTOOPT);
 
41
                return -1;
 
42
        }
 
43
 
 
44
 
 
45
        sock[0] = socket(domain, type, protocol);
 
46
        address.sin_addr.s_addr = INADDR_ANY;
 
47
        address.sin_family              = AF_INET;
 
48
        address.sin_port                = 0;
 
49
 
 
50
        bind(sock[0], (struct sockaddr*)&address, sizeof(address));
 
51
        if(getsockname(sock[0], (struct sockaddr *)&address, &size) != 0) {
 
52
 
 
53
    }
 
54
 
 
55
        listen(sock[0], 2);
 
56
        sock[1] = socket(domain, type, protocol);       
 
57
        address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 
58
 
 
59
        connect(sock[1], (struct sockaddr*)&address, sizeof(address));
 
60
        redirect = accept(sock[0],(struct sockaddr*)&address, &size);
 
61
 
 
62
        close(sock[0]);
 
63
        sock[0] = redirect;
 
64
 
 
65
        if(sock[0] == INVALID_SOCKET ) {
 
66
                close(sock[0]);
 
67
                close(sock[1]);
 
68
                set_errno(WSAECONNABORTED);
 
69
                return -1;
 
70
        }
 
71
        
 
72
        return 0;
 
73
}
 
74
 
 
75
int inet_aton(const char *cp, struct in_addr *inp) {
 
76
  inp->s_addr = inet_addr(cp);
 
77
 
 
78
  if (inp->s_addr == INADDR_NONE) {
 
79
          return 0;
 
80
  }
 
81
 
 
82
  return 1;
 
83
}
 
84
 
 
85
int fcntl(int fd, int cmd, ...) {
 
86
        va_list va;
 
87
        int retval, io, mode;
 
88
        
 
89
        va_start(va, cmd);
 
90
 
 
91
        switch(cmd) {
 
92
                case F_GETFL:
 
93
                case F_SETFD:
 
94
                case F_GETFD:
 
95
                default:
 
96
                        retval = -1;
 
97
                        break;
 
98
 
 
99
                case F_SETFL:
 
100
                        io = va_arg(va, int);
 
101
                        mode = io == O_NONBLOCK ? 1 : 0;
 
102
                        retval = ioctlsocket(fd, io, &mode);
 
103
                        break;
 
104
        }
 
105
 
 
106
        va_end(va);
 
107
        return retval;
 
108
}
 
109
#endif