From 153c26df293b8d49d22ac1ad0737942d6cea8126 Mon Sep 17 00:00:00 2001 From: Sharif <54396379+developersharif@users.noreply.github.com> Date: Sat, 11 May 2024 23:49:01 +0600 Subject: [PATCH] Set default values for domain, type, and protocol in socket_create This commit modifies the `socket_create` function in the PHP Socket extension to set default values for the `domain`, `type`, and `protocol` parameters if the user doesn't provide any arguments. The default values are set as follows: - `domain`: Set to `AF_INET` (IPv4) on Windows systems, and `AF_UNIX` (Unix domain sockets) on non-Windows systems. - `type`: Set to `SOCK_STREAM` (TCP). - `protocol`: Set to `SOL_TCP`. If the user provides arguments to the `socket_create` function, those values will override the default values set by this commit. --- ext/sockets/sockets.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index 1de50d9f88788..6e6c47edd4c26 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1053,8 +1053,14 @@ PHP_FUNCTION(socket_getpeername) /* {{{ Creates an endpoint for communication in the domain specified by domain, of type specified by type */ PHP_FUNCTION(socket_create) { - zend_long domain, type, protocol; - php_socket *php_sock; + zend_long domain, type = SOCK_STREAM, protocol = SOL_TCP; + php_socket *php_sock; + + if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { + domain = AF_INET; + } else { + domain = AF_UNIX; + } if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &domain, &type, &protocol) == FAILURE) { RETURN_THROWS();