-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add net_get_interfaces() #2935
Add net_get_interfaces() #2935
Conversation
ext/standard/net.c
Outdated
# include <iphlpapi.h> | ||
#endif | ||
|
||
zend_string* php_inet_ntop(const struct sockaddr *addr) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing PHPAPI as you have declared in the header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally the first declaration is decisive, but would be cleaner to repeat same, yep.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @weltling stated, not needed at point of definition when the included declaration has it, but sure, hurts nothing to add it.
dwRetVal = GetAdaptersAddresses(family, flags, NULL, pAddresses, &outBufLen); | ||
|
||
if (NO_ERROR != dwRetVal) { | ||
/* TODO check GetLastError() */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think this is missing FREE(pAddresses) before the return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
(For any other readers) This implements FR #17400: https://bugs.php.net/bug.php?id=17400 |
@@ -22,13 +22,15 @@ AC_DEFINE("PHP_USE_PHP_CRYPT_R", 1); | |||
|
|||
CHECK_HEADER_ADD_INCLUDE("timelib_config.h", "CFLAGS_STANDARD", "ext/date/lib"); | |||
|
|||
ADD_FLAG("LIBS_STANDARD", "iphlpapi.lib"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@weltling tho we only use iphlpapi here, wouldn't you think its better put in toolset_setup_common_libs() in win32/confutils.js, ext/standard can't be disabled anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KalleZ would work as well, but shouldn't be necessary. $(LIBS)
is put for every binary unit, whereby iphlpapi.lib
is only required for standard. The linker will ignore it anyway, if there are no symbols used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PIP_ADAPTER_UNICAST_ADDRESS u = NULL; | ||
ULONG outBufLen = 0; | ||
DWORD dwRetVal = 0; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a ZEND_PARSE_PARAMETERS_NONE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch.
Per my comments on internals, just tested this on
|
@winks Ah, hrmm. Well, that's the implementation working, but the unittest failing because AF_INET is defined by the sockets extension which isn't always enabled. Nice catch. |
Committed to 7.3 as 7ca5a7d |
@sgolemon we do have STREAM_PF_INET which is either PF_INET or AF_INET depending on what constant was available at compile time in the core |
@sgolemon woulnd't it makes sense to expose a few constants from if.h to be able to analyse the "flags". Can even be nice to be able to filter according to it: |
so pr #2948 |
This function is buggy, undocumented, and several opportunities were missed. See: https://bugs.php.net/bug.php?id=79251 I see that no one noticed the obvious "unicast" array bug during the initial implementation despite one sample output above clearly showing the problem on this PR's thread. That is, AF_PACKET (17) and AF_LINK (18) families have MAC addresses, not IP addresses. As a result, the first entry in each interface's "unicast" array is missing its associated information. |
New function for enumerating network adapters on the local machine.
This favor's windows' format in the normalized output since it provides more info, and groups addresses on single interfaces together.
Output example for windows and linux here:
https://twitter.com/SaraMG/status/933821878510211072