Coverage Report

Created: 2025-12-31 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/php-src/main/php_network.h
Line
Count
Source
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright (c) The PHP Group                                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to version 3.01 of the PHP license,      |
6
   | that is bundled with this package in the file LICENSE, and is        |
7
   | available through the world-wide-web at the following url:           |
8
   | https://www.php.net/license/3_01.txt                                 |
9
   | If you did not receive a copy of the PHP license and are unable to   |
10
   | obtain it through the world-wide-web, please send a note to          |
11
   | license@php.net so we can mail you a copy immediately.               |
12
   +----------------------------------------------------------------------+
13
   | Author: Stig Venaas <venaas@uninett.no>                              |
14
   +----------------------------------------------------------------------+
15
 */
16
17
#ifndef _PHP_NETWORK_H
18
#define _PHP_NETWORK_H
19
20
#include <php.h>
21
22
#ifndef PHP_WIN32
23
# undef closesocket
24
0
# define closesocket close
25
# include <netinet/tcp.h>
26
#endif
27
28
#ifndef HAVE_SHUTDOWN
29
#undef shutdown
30
#define shutdown(s,n) /* nothing */
31
#endif
32
33
#ifdef PHP_WIN32
34
# ifdef EWOULDBLOCK
35
#  undef EWOULDBLOCK
36
# endif
37
# ifdef EINPROGRESS
38
#  undef EINPROGRESS
39
# endif
40
# define EWOULDBLOCK WSAEWOULDBLOCK
41
# define EINPROGRESS  WSAEWOULDBLOCK
42
# define fsync _commit
43
# define ftruncate(a, b) chsize(a, b)
44
#endif /* defined(PHP_WIN32) */
45
46
#ifndef EWOULDBLOCK
47
# define EWOULDBLOCK EAGAIN
48
#endif
49
50
/* This is a workaround for GCC bug 69602: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602 */
51
#if EAGAIN != EWOULDBLOCK
52
# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN || err == EWOULDBLOCK)
53
#else
54
0
# define PHP_IS_TRANSIENT_ERROR(err) (err == EAGAIN)
55
#endif
56
57
#ifdef PHP_WIN32
58
#define php_socket_errno() WSAGetLastError()
59
#else
60
0
#define php_socket_errno() errno
61
#endif
62
63
/* like strerror, but caller must efree the returned string,
64
 * unless buf is not NULL.
65
 * Also works sensibly for win32 */
66
BEGIN_EXTERN_C()
67
#ifdef PHP_WIN32
68
char *php_socket_strerror_s(long err, char *buf, size_t bufsize);
69
#else
70
677
#define php_socket_strerror_s php_socket_strerror
71
#endif
72
PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize);
73
PHPAPI zend_string *php_socket_error_str(long err);
74
END_EXTERN_C()
75
76
#ifdef HAVE_NETINET_IN_H
77
# include <netinet/in.h>
78
#endif
79
80
#ifdef HAVE_SYS_SOCKET_H
81
#include <sys/socket.h>
82
#endif
83
84
#ifdef HAVE_GETHOSTBYNAME_R
85
#include <netdb.h>
86
#endif
87
88
/* These are here, rather than with the win32 counterparts above,
89
 * since <sys/socket.h> defines them. */
90
#ifndef SHUT_RD
91
# define SHUT_RD 0
92
# define SHUT_WR 1
93
# define SHUT_RDWR 2
94
#endif
95
96
#ifdef HAVE_SYS_TIME_H
97
#include <sys/time.h>
98
#endif
99
100
#include <stddef.h>
101
102
#ifdef PHP_WIN32
103
typedef SOCKET php_socket_t;
104
#define PHP_SOCKET_FMT "%" PRIxPTR
105
#else
106
typedef int php_socket_t;
107
#define PHP_SOCKET_FMT "%d"
108
#endif
109
110
#ifdef PHP_WIN32
111
# define SOCK_ERR INVALID_SOCKET
112
# define SOCK_CONN_ERR SOCKET_ERROR
113
# define SOCK_RECV_ERR SOCKET_ERROR
114
#else
115
0
# define SOCK_ERR -1
116
0
# define SOCK_CONN_ERR -1
117
# define SOCK_RECV_ERR -1
118
#endif
119
120
0
#define STREAM_SOCKOP_NONE                (1 << 0)
121
0
#define STREAM_SOCKOP_SO_REUSEPORT        (1 << 1)
122
0
#define STREAM_SOCKOP_SO_BROADCAST        (1 << 2)
123
0
#define STREAM_SOCKOP_IPV6_V6ONLY         (1 << 3)
124
0
#define STREAM_SOCKOP_IPV6_V6ONLY_ENABLED (1 << 4)
125
0
#define STREAM_SOCKOP_TCP_NODELAY         (1 << 5)
126
0
#define STREAM_SOCKOP_SO_REUSEADDR        (1 << 6)
127
0
#define STREAM_SOCKOP_SO_KEEPALIVE        (1 << 7)
128
129
/* uncomment this to debug poll(2) emulation on systems that have poll(2) */
130
/* #define PHP_USE_POLL_2_EMULATION 1 */
131
132
#if defined(HAVE_POLL)
133
# if defined(HAVE_POLL_H)
134
#  include <poll.h>
135
# elif defined(HAVE_SYS_POLL_H)
136
#  include <sys/poll.h>
137
# endif
138
typedef struct pollfd php_pollfd;
139
#else
140
typedef struct _php_pollfd {
141
  php_socket_t fd;
142
  short events;
143
  short revents;
144
} php_pollfd;
145
146
PHPAPI int php_poll2(php_pollfd *ufds, unsigned int nfds, int timeout);
147
148
#ifndef POLLIN
149
# define POLLIN      0x0001    /* There is data to read */
150
# define POLLPRI     0x0002    /* There is urgent data to read */
151
# define POLLOUT     0x0004    /* Writing now will not block */
152
# define POLLERR     0x0008    /* Error condition */
153
# define POLLHUP     0x0010    /* Hung up */
154
# define POLLNVAL    0x0020    /* Invalid request: fd not open */
155
#endif
156
157
# ifndef PHP_USE_POLL_2_EMULATION
158
#  define PHP_USE_POLL_2_EMULATION 1
159
# endif
160
#endif
161
162
0
#define PHP_POLLREADABLE  (POLLIN|POLLERR|POLLHUP)
163
164
#ifndef PHP_USE_POLL_2_EMULATION
165
0
# define php_poll2(ufds, nfds, timeout)   poll(ufds, nfds, timeout)
166
#endif
167
168
/* timeval-to-timeout (for poll(2)) */
169
static inline int php_tvtoto(struct timeval *timeouttv)
170
0
{
171
0
  if (timeouttv && timeouttv->tv_sec >= 0 && timeouttv->tv_sec <= ((INT_MAX - 1000) / 1000)) {
172
0
    return (timeouttv->tv_sec * 1000) + (timeouttv->tv_usec / 1000);
173
0
  }
174
0
  return -1;
175
0
}
Unexecuted instantiation: exif.c:php_tvtoto
Unexecuted instantiation: hash.c:php_tvtoto
Unexecuted instantiation: spl_directory.c:php_tvtoto
Unexecuted instantiation: basic_functions.c:php_tvtoto
Unexecuted instantiation: dir.c:php_tvtoto
Unexecuted instantiation: dns.c:php_tvtoto
Unexecuted instantiation: exec.c:php_tvtoto
Unexecuted instantiation: file.c:php_tvtoto
Unexecuted instantiation: filters.c:php_tvtoto
Unexecuted instantiation: fsock.c:php_tvtoto
Unexecuted instantiation: ftp_fopen_wrapper.c:php_tvtoto
Unexecuted instantiation: head.c:php_tvtoto
Unexecuted instantiation: html.c:php_tvtoto
Unexecuted instantiation: http_fopen_wrapper.c:php_tvtoto
Unexecuted instantiation: image.c:php_tvtoto
Unexecuted instantiation: net.c:php_tvtoto
Unexecuted instantiation: php_fopen_wrapper.c:php_tvtoto
Unexecuted instantiation: proc_open.c:php_tvtoto
Unexecuted instantiation: streamsfuncs.c:php_tvtoto
Unexecuted instantiation: string.c:php_tvtoto
Unexecuted instantiation: url.c:php_tvtoto
Unexecuted instantiation: user_filters.c:php_tvtoto
Unexecuted instantiation: fopen_wrappers.c:php_tvtoto
Unexecuted instantiation: main.c:php_tvtoto
Unexecuted instantiation: network.c:php_tvtoto
Unexecuted instantiation: php_variables.c:php_tvtoto
Unexecuted instantiation: cast.c:php_tvtoto
Unexecuted instantiation: filter.c:php_tvtoto
Unexecuted instantiation: plain_wrapper.c:php_tvtoto
Unexecuted instantiation: streams.c:php_tvtoto
Unexecuted instantiation: transports.c:php_tvtoto
Unexecuted instantiation: userspace.c:php_tvtoto
Unexecuted instantiation: xp_socket.c:php_tvtoto
Unexecuted instantiation: internal_functions_cli.c:php_tvtoto
176
177
/* hybrid select(2)/poll(2) for a single descriptor.
178
 * timeouttv follows same rules as select(2), but is reduced to millisecond accuracy.
179
 * Returns 0 on timeout, -1 on error, or the event mask (ala poll(2)).
180
 */
181
static inline int php_pollfd_for(php_socket_t fd, int events, struct timeval *timeouttv)
182
0
{
183
0
  php_pollfd p;
184
0
  int n;
185
186
0
  p.fd = fd;
187
0
  p.events = events;
188
0
  p.revents = 0;
189
190
0
  n = php_poll2(&p, 1, php_tvtoto(timeouttv));
191
192
0
  if (n > 0) {
193
0
    return p.revents;
194
0
  }
195
196
0
  return n;
197
0
}
Unexecuted instantiation: exif.c:php_pollfd_for
Unexecuted instantiation: hash.c:php_pollfd_for
Unexecuted instantiation: spl_directory.c:php_pollfd_for
Unexecuted instantiation: basic_functions.c:php_pollfd_for
Unexecuted instantiation: dir.c:php_pollfd_for
Unexecuted instantiation: dns.c:php_pollfd_for
Unexecuted instantiation: exec.c:php_pollfd_for
Unexecuted instantiation: file.c:php_pollfd_for
Unexecuted instantiation: filters.c:php_pollfd_for
Unexecuted instantiation: fsock.c:php_pollfd_for
Unexecuted instantiation: ftp_fopen_wrapper.c:php_pollfd_for
Unexecuted instantiation: head.c:php_pollfd_for
Unexecuted instantiation: html.c:php_pollfd_for
Unexecuted instantiation: http_fopen_wrapper.c:php_pollfd_for
Unexecuted instantiation: image.c:php_pollfd_for
Unexecuted instantiation: net.c:php_pollfd_for
Unexecuted instantiation: php_fopen_wrapper.c:php_pollfd_for
Unexecuted instantiation: proc_open.c:php_pollfd_for
Unexecuted instantiation: streamsfuncs.c:php_pollfd_for
Unexecuted instantiation: string.c:php_pollfd_for
Unexecuted instantiation: url.c:php_pollfd_for
Unexecuted instantiation: user_filters.c:php_pollfd_for
Unexecuted instantiation: fopen_wrappers.c:php_pollfd_for
Unexecuted instantiation: main.c:php_pollfd_for
Unexecuted instantiation: network.c:php_pollfd_for
Unexecuted instantiation: php_variables.c:php_pollfd_for
Unexecuted instantiation: cast.c:php_pollfd_for
Unexecuted instantiation: filter.c:php_pollfd_for
Unexecuted instantiation: plain_wrapper.c:php_pollfd_for
Unexecuted instantiation: streams.c:php_pollfd_for
Unexecuted instantiation: transports.c:php_pollfd_for
Unexecuted instantiation: userspace.c:php_pollfd_for
Unexecuted instantiation: xp_socket.c:php_pollfd_for
Unexecuted instantiation: internal_functions_cli.c:php_pollfd_for
198
199
static inline int php_pollfd_for_ms(php_socket_t fd, int events, int timeout)
200
0
{
201
0
  php_pollfd p;
202
0
  int n;
203
0
204
0
  p.fd = fd;
205
0
  p.events = events;
206
0
  p.revents = 0;
207
0
208
0
  n = php_poll2(&p, 1, timeout);
209
0
210
0
  if (n > 0) {
211
0
    return p.revents;
212
0
  }
213
0
214
0
  return n;
215
0
}
Unexecuted instantiation: exif.c:php_pollfd_for_ms
Unexecuted instantiation: hash.c:php_pollfd_for_ms
Unexecuted instantiation: spl_directory.c:php_pollfd_for_ms
Unexecuted instantiation: basic_functions.c:php_pollfd_for_ms
Unexecuted instantiation: dir.c:php_pollfd_for_ms
Unexecuted instantiation: dns.c:php_pollfd_for_ms
Unexecuted instantiation: exec.c:php_pollfd_for_ms
Unexecuted instantiation: file.c:php_pollfd_for_ms
Unexecuted instantiation: filters.c:php_pollfd_for_ms
Unexecuted instantiation: fsock.c:php_pollfd_for_ms
Unexecuted instantiation: ftp_fopen_wrapper.c:php_pollfd_for_ms
Unexecuted instantiation: head.c:php_pollfd_for_ms
Unexecuted instantiation: html.c:php_pollfd_for_ms
Unexecuted instantiation: http_fopen_wrapper.c:php_pollfd_for_ms
Unexecuted instantiation: image.c:php_pollfd_for_ms
Unexecuted instantiation: net.c:php_pollfd_for_ms
Unexecuted instantiation: php_fopen_wrapper.c:php_pollfd_for_ms
Unexecuted instantiation: proc_open.c:php_pollfd_for_ms
Unexecuted instantiation: streamsfuncs.c:php_pollfd_for_ms
Unexecuted instantiation: string.c:php_pollfd_for_ms
Unexecuted instantiation: url.c:php_pollfd_for_ms
Unexecuted instantiation: user_filters.c:php_pollfd_for_ms
Unexecuted instantiation: fopen_wrappers.c:php_pollfd_for_ms
Unexecuted instantiation: main.c:php_pollfd_for_ms
Unexecuted instantiation: network.c:php_pollfd_for_ms
Unexecuted instantiation: php_variables.c:php_pollfd_for_ms
Unexecuted instantiation: cast.c:php_pollfd_for_ms
Unexecuted instantiation: filter.c:php_pollfd_for_ms
Unexecuted instantiation: plain_wrapper.c:php_pollfd_for_ms
Unexecuted instantiation: streams.c:php_pollfd_for_ms
Unexecuted instantiation: transports.c:php_pollfd_for_ms
Unexecuted instantiation: userspace.c:php_pollfd_for_ms
Unexecuted instantiation: xp_socket.c:php_pollfd_for_ms
Unexecuted instantiation: internal_functions_cli.c:php_pollfd_for_ms
216
217
/* emit warning and suggestion for unsafe select(2) usage */
218
PHPAPI void _php_emit_fd_setsize_warning(int max_fd);
219
220
static inline bool _php_check_fd_setsize(php_socket_t *max_fd, int setsize)
221
0
{
222
#ifdef PHP_WIN32
223
  (void)(max_fd); // Unused
224
  if (setsize + 1 >= FD_SETSIZE) {
225
    _php_emit_fd_setsize_warning(setsize);
226
    return false;
227
  }
228
#else
229
0
  (void)(setsize); // Unused
230
0
  if (*max_fd >= FD_SETSIZE) {
231
0
    _php_emit_fd_setsize_warning(*max_fd);
232
0
    *max_fd = FD_SETSIZE - 1;
233
0
    return false;
234
0
  }
235
0
#endif
236
0
  return true;
237
0
}
Unexecuted instantiation: exif.c:_php_check_fd_setsize
Unexecuted instantiation: hash.c:_php_check_fd_setsize
Unexecuted instantiation: spl_directory.c:_php_check_fd_setsize
Unexecuted instantiation: basic_functions.c:_php_check_fd_setsize
Unexecuted instantiation: dir.c:_php_check_fd_setsize
Unexecuted instantiation: dns.c:_php_check_fd_setsize
Unexecuted instantiation: exec.c:_php_check_fd_setsize
Unexecuted instantiation: file.c:_php_check_fd_setsize
Unexecuted instantiation: filters.c:_php_check_fd_setsize
Unexecuted instantiation: fsock.c:_php_check_fd_setsize
Unexecuted instantiation: ftp_fopen_wrapper.c:_php_check_fd_setsize
Unexecuted instantiation: head.c:_php_check_fd_setsize
Unexecuted instantiation: html.c:_php_check_fd_setsize
Unexecuted instantiation: http_fopen_wrapper.c:_php_check_fd_setsize
Unexecuted instantiation: image.c:_php_check_fd_setsize
Unexecuted instantiation: net.c:_php_check_fd_setsize
Unexecuted instantiation: php_fopen_wrapper.c:_php_check_fd_setsize
Unexecuted instantiation: proc_open.c:_php_check_fd_setsize
Unexecuted instantiation: streamsfuncs.c:_php_check_fd_setsize
Unexecuted instantiation: string.c:_php_check_fd_setsize
Unexecuted instantiation: url.c:_php_check_fd_setsize
Unexecuted instantiation: user_filters.c:_php_check_fd_setsize
Unexecuted instantiation: fopen_wrappers.c:_php_check_fd_setsize
Unexecuted instantiation: main.c:_php_check_fd_setsize
Unexecuted instantiation: network.c:_php_check_fd_setsize
Unexecuted instantiation: php_variables.c:_php_check_fd_setsize
Unexecuted instantiation: cast.c:_php_check_fd_setsize
Unexecuted instantiation: filter.c:_php_check_fd_setsize
Unexecuted instantiation: plain_wrapper.c:_php_check_fd_setsize
Unexecuted instantiation: streams.c:_php_check_fd_setsize
Unexecuted instantiation: transports.c:_php_check_fd_setsize
Unexecuted instantiation: userspace.c:_php_check_fd_setsize
Unexecuted instantiation: xp_socket.c:_php_check_fd_setsize
Unexecuted instantiation: internal_functions_cli.c:_php_check_fd_setsize
238
239
#ifdef PHP_WIN32
240
/* it is safe to FD_SET too many fd's under win32; the macro will simply ignore
241
 * descriptors that go beyond the default FD_SETSIZE */
242
# define PHP_SAFE_FD_SET(fd, set) FD_SET(fd, set)
243
# define PHP_SAFE_FD_CLR(fd, set) FD_CLR(fd, set)
244
# define PHP_SAFE_FD_ISSET(fd, set) FD_ISSET(fd, set)
245
# define PHP_SAFE_MAX_FD(m, n)    _php_check_fd_setsize(&m, n)
246
#else
247
0
# define PHP_SAFE_FD_SET(fd, set) do { if (fd < FD_SETSIZE) FD_SET(fd, set); } while(0)
248
# define PHP_SAFE_FD_CLR(fd, set) do { if (fd < FD_SETSIZE) FD_CLR(fd, set); } while(0)
249
0
# define PHP_SAFE_FD_ISSET(fd, set) ((fd < FD_SETSIZE) && FD_ISSET(fd, set))
250
0
# define PHP_SAFE_MAX_FD(m, n)    _php_check_fd_setsize(&m, n)
251
#endif
252
253
254
14
#define PHP_SOCK_CHUNK_SIZE 8192
255
256
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
257
typedef struct sockaddr_storage php_sockaddr_storage;
258
#else
259
typedef struct {
260
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
261
    unsigned char ss_len;
262
    unsigned char ss_family;
263
#else
264
        unsigned short ss_family;
265
#endif
266
        char info[126];
267
} php_sockaddr_storage;
268
#endif
269
270
0
#define PHP_SOCKVAL_TCP_NODELAY   (1 << 0)
271
0
#define PHP_SOCKVAL_TCP_KEEPIDLE  (1 << 1)
272
0
#define PHP_SOCKVAL_TCP_KEEPCNT   (1 << 2)
273
0
#define PHP_SOCKVAL_TCP_KEEPINTVL (1 << 3)
274
275
0
#define PHP_SOCKVAL_IS_SET(sockvals, opt) ((sockvals)->mask & (opt))
276
277
typedef struct {
278
  unsigned int mask;
279
  int tcp_nodelay;
280
  struct {
281
    int keepidle;
282
    int keepcnt;
283
    int keepintvl;
284
  } keepalive;
285
} php_sockvals;
286
287
BEGIN_EXTERN_C()
288
PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string);
289
PHPAPI void php_network_freeaddresses(struct sockaddr **sal);
290
291
PHPAPI php_socket_t php_network_connect_socket_to_host_ex(const char *host, unsigned short port,
292
    int socktype, int asynchronous, struct timeval *timeout, zend_string **error_string,
293
    int *error_code, const char *bindto, unsigned short bindport, long sockopts, php_sockvals *sockvals
294
    );
295
296
PHPAPI php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port,
297
    int socktype, int asynchronous, struct timeval *timeout, zend_string **error_string,
298
    int *error_code, const char *bindto, unsigned short bindport, long sockopts
299
    );
300
301
PHPAPI int php_network_connect_socket(php_socket_t sockfd,
302
    const struct sockaddr *addr,
303
    socklen_t addrlen,
304
    int asynchronous,
305
    struct timeval *timeout,
306
    zend_string **error_string,
307
    int *error_code);
308
309
#define php_connect_nonb(sock, addr, addrlen, timeout) \
310
  php_network_connect_socket((sock), (addr), (addrlen), 0, (timeout), NULL, NULL)
311
312
PHPAPI php_socket_t php_network_bind_socket_to_local_addr_ex(const char *host, unsigned port,
313
    int socktype, long sockopts, php_sockvals *sockvals, zend_string **error_string, int *error_code
314
    );
315
316
PHPAPI php_socket_t php_network_bind_socket_to_local_addr(const char *host, unsigned port,
317
    int socktype, long sockopts, zend_string **error_string, int *error_code
318
    );
319
320
PHPAPI php_socket_t php_network_accept_incoming_ex(php_socket_t srvsock,
321
    zend_string **textaddr,
322
    struct sockaddr **addr,
323
    socklen_t *addrlen,
324
    struct timeval *timeout,
325
    zend_string **error_string,
326
    int *error_code,
327
    php_sockvals *sockvals
328
    );
329
330
PHPAPI php_socket_t php_network_accept_incoming(php_socket_t srvsock,
331
    zend_string **textaddr,
332
    struct sockaddr **addr,
333
    socklen_t *addrlen,
334
    struct timeval *timeout,
335
    zend_string **error_string,
336
    int *error_code,
337
    int tcp_nodelay
338
    );
339
340
PHPAPI int php_network_get_sock_name(php_socket_t sock,
341
    zend_string **textaddr,
342
    struct sockaddr **addr,
343
    socklen_t *addrlen
344
    );
345
346
PHPAPI int php_network_get_peer_name(php_socket_t sock,
347
    zend_string **textaddr,
348
    struct sockaddr **addr,
349
    socklen_t *addrlen
350
    );
351
352
PHPAPI void php_any_addr(int family, php_sockaddr_storage *addr, unsigned short port);
353
PHPAPI socklen_t php_sockaddr_size(php_sockaddr_storage *addr);
354
END_EXTERN_C()
355
356
struct _php_netstream_data_t  {
357
  php_socket_t socket;
358
  bool is_blocked;
359
  bool timeout_event;
360
  struct timeval timeout;
361
  size_t ownsize;
362
};
363
typedef struct _php_netstream_data_t php_netstream_data_t;
364
PHPAPI extern const php_stream_ops php_stream_socket_ops;
365
extern const php_stream_ops php_stream_generic_socket_ops;
366
#define PHP_STREAM_IS_SOCKET  (&php_stream_socket_ops)
367
368
BEGIN_EXTERN_C()
369
PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const char *persistent_id STREAMS_DC );
370
/* open a connection to a host using php_hostconnect and return a stream */
371
PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port,
372
    int socktype, struct timeval *timeout, const char *persistent_id STREAMS_DC);
373
PHPAPI void php_network_populate_name_from_sockaddr(
374
    /* input address */
375
    struct sockaddr *sa, socklen_t sl,
376
    /* output readable address */
377
    zend_string **textaddr,
378
    /* output address */
379
    struct sockaddr **addr,
380
    socklen_t *addrlen
381
    );
382
383
PHPAPI zend_result php_network_parse_network_address_with_port(const char *addr,
384
    size_t addrlen, struct sockaddr *sa, socklen_t *sl);
385
386
PHPAPI struct hostent*  php_network_gethostbyname(const char *name);
387
388
PHPAPI zend_result php_set_sock_blocking(php_socket_t socketd, bool block);
389
END_EXTERN_C()
390
391
0
#define php_stream_sock_open_from_socket(socket, persistent)  _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_CC)
392
0
#define php_stream_sock_open_host(host, port, socktype, timeout, persistent)  _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_CC)
393
394
/* {{{ memory debug */
395
#define php_stream_sock_open_from_socket_rel(socket, persistent)  _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_REL_CC)
396
#define php_stream_sock_open_host_rel(host, port, socktype, timeout, persistent)  _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_REL_CC)
397
#define php_stream_sock_open_unix_rel(path, pathlen, persistent, timeval) _php_stream_sock_open_unix((path), (pathlen), (persistent), (timeval) STREAMS_REL_CC)
398
399
/* }}} */
400
401
#ifndef MAXFQDNLEN
402
0
#define MAXFQDNLEN 255
403
#endif
404
405
#endif /* _PHP_NETWORK_H */