Skip to content

Commit

Permalink
removes support for getpeername, indeed does not make sense for so low
Browse files Browse the repository at this point in the history
level sockets..
  • Loading branch information
devnexen committed Jan 11, 2025
1 parent c1d5dd6 commit 4d46e89
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
22 changes: 0 additions & 22 deletions ext/sockets/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,6 @@ PHP_FUNCTION(socket_getpeername)
struct sockaddr_in *sin;
#ifdef HAVE_IPV6
struct sockaddr_in6 *sin6;
#endif
#ifdef AF_PACKET
struct sockaddr_ll *sll;
#endif
char addrbuf[INET6_ADDRSTRLEN];
struct sockaddr_un *s_un;
Expand Down Expand Up @@ -1136,25 +1133,6 @@ PHP_FUNCTION(socket_getpeername)
ZEND_TRY_ASSIGN_REF_STRING(arg2, s_un->sun_path);
RETURN_TRUE;
break;
#ifdef AF_PACKET
case AF_PACKET:
sll = (struct sockaddr_ll *) sa;
char ifrname[IFNAMSIZ];

if (UNEXPECTED(!if_indextoname(sll->sll_ifindex, ifrname))) {
zend_throw_error(NULL, "invalid interface index");
RETURN_THROWS();
}

ZEND_TRY_ASSIGN_REF_STRING(arg2, ifrname);

if (arg3 != NULL) {
ZEND_TRY_ASSIGN_REF_LONG(arg3, sll->sll_ifindex);
}
RETURN_TRUE;
break;
#endif


default:
zend_argument_value_error(1, "must be one of AF_UNIX, AF_INET, or AF_INET6");
Expand Down
4 changes: 4 additions & 0 deletions ext/sockets/tests/socket_afpacket.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ if (!function_exists("posix_getuid") || posix_getuid() != 0) {
var_dump($s_conn);
var_dump($istr);
var_dump($iindex);

socket_getpeername($s_c, $istr2, $iindex2);
socket_close($s_c);
?>
--EXPECTF--
bool(true)
bool(true)
string(2) "lo"
int(%i)

Warning: socket_getpeername(): unable to retrieve peer name [95]: Operation not supported in %s on line %d

0 comments on commit 4d46e89

Please sign in to comment.