Req #72733 [Csd]: It would be nice to have something like getaddrinfo.
| From: | email at davekok dot nl | Date: | Tue, 25 Oct 2016 13:16:14 +0000 |
| Subject: | Req #72733 [Csd]: It would be nice to have something like getaddrinfo. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-204995@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72733&edit=1
ID: 72733
User updated by: email at davekok dot nl
Reported by: email at davekok dot nl
Summary: It would be nice to have something like getaddrinfo.
Status: Closed
Type: Feature/Change Request
Package: Sockets related
Operating System: Any
-PHP Version: 7.0.9
+PHP Version: 7.2
Block user comment: N
Private report: N
New Comment:
Btw, missing from the implementation is a way to set that the socket port should be reusable. Any
change that can be added somehow. Perhaps a second parameter to socket_addrinfo_bind containing an
array of socket options? As far as I know the SO_REUSEADDR has to be set before bind is called.
Previous Comments:
------------------------------------------------------------------------
[2016-10-10 11:17:38] krakjoe@php.net
Automatic comment on behalf of dave@mudsite.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7373ce914914e9a434216554a7e29aa4d1775d97
Log: Fix #72733: Expose getaddrinfo C function, and supporting connect/bind
------------------------------------------------------------------------
[2016-09-02 18:13:41] cmb@php.net
Automatic comment on behalf of dave@mudsite.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7373ce914914e9a434216554a7e29aa4d1775d97
Log: Fix #72733: Expose getaddrinfo C function, and supporting connect/bind
------------------------------------------------------------------------
[2016-08-12 08:09:43] email at davekok dot nl
I love this final version. Having $info['ai_addr'] be a resource is excellent. However I
suspect someone if not me will request to add a function that can take this resource and return the
IP address and port. Properly something to consider. Otherwise I am really happy with this version.
------------------------------------------------------------------------
[2016-08-11 03:15:57] dave at mudsite dot com
I see what you're looking for. I've gone ahead and did a 3rd attempt at this guy with the
use of:
$addrinfo = socket_getaddrinfo('127.0.0.1', 2000, array(
'ai_family' => AF_INET,
'ai_socktype' => SOCK_STREAM,
));
echo "Server: Starting\n";
$info = reset($addrinfo);
$sock = socket_create($info['ai_family'], $info['ai_socktype'],
$info['ai_protocol']);
if ($sock) {
socket_bind($sock, $info['ai_addr']) or die("Could not bind");
socket_listen($sock) or die("Could not listen");
$info['ai_addr'] here is a resource of the underlying sockaddr structure. I foresee this
implementation a bit more contentious to advocate. Due to the fact that socket_connect, and
socket_bind change signatures from
socket_(connect/bind) (resource $sock, string $address[, int port])
to being
socket_(connect/bind) (resource $sock, mixed $arg[, int port])
where $arg can be string address where 3rd argument is used
or
where $args is resource of sockaddr and 3rd arg is ignored
I'll make sure to document all this for the RFC and see what everyone has to say about it.
------------------------------------------------------------------------
[2016-08-10 11:44:22] email at davekok dot nl
If at all possible I still like the array approach. As this allows the PHP programmer access to the
information within the addrinfo struct. Could socket_create, socket_bind and socket_listen not be
modified to also allow an array? I have no problem with having to also specify the socket resource
separately. Hiding this in a addrinfo resource seems wrong somehow.
If a resource is used instead of an array. Information functions to retrieve the information within
would be very much appreciated.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=72733
--
Edit this bug report at https://bugs.php.net/bug.php?id=72733&edit=1