44
44
# include <Ws2tcpip.h>
45
45
# include <iphlpapi.h>
46
46
#else
47
+ # ifdef HAVE_SYS_IOCTL_H
48
+ # include <sys/ioctl.h>
49
+ # endif
47
50
# include <netdb.h>
48
51
#endif
49
52
53
+ #ifndef PHP_WIN32
54
+ static zend_result net_get_mtu (char * ifname , zend_long * mtu )
55
+ {
56
+ #ifdef SIOCGIFMTU
57
+ struct ifreq ifr = {0 };
58
+ zend_result status = FAILURE ;
59
+ int local = socket (AF_UNIX , SOCK_DGRAM , 0 );
60
+ if (local == -1 ) {
61
+ return FAILURE ;
62
+ }
63
+
64
+ strlcpy (ifr .ifr_name , ifname , IFNAMSIZ );
65
+ if (ioctl (local , SIOCGIFMTU , & ifr ) < 0 ) {
66
+ goto end ;
67
+ }
68
+
69
+
70
+ * mtu = (zend_long )ifr .ifr_mtu ;
71
+ status = SUCCESS ;
72
+ end :
73
+ close (local );
74
+ return status ;
75
+ #else
76
+ return FAILURE ;
77
+ #endif
78
+ }
79
+ #endif
80
+
50
81
PHPAPI zend_string * php_inet_ntop (const struct sockaddr * addr ) {
51
82
socklen_t addrlen = sizeof (struct sockaddr_in );
52
83
@@ -274,7 +305,7 @@ PHP_FUNCTION(net_get_interfaces) {
274
305
array_init (return_value );
275
306
for (p = addrs ; p ; p = p -> ifa_next ) {
276
307
zval * iface = zend_hash_str_find (Z_ARR_P (return_value ), p -> ifa_name , strlen (p -> ifa_name ));
277
- zval * unicast , * status ;
308
+ zval * unicast , * status , * mtu ;
278
309
279
310
if (!iface ) {
280
311
zval newif ;
@@ -298,6 +329,13 @@ PHP_FUNCTION(net_get_interfaces) {
298
329
if (!status ) {
299
330
add_assoc_bool (iface , "up" , ((p -> ifa_flags & IFF_UP ) != 0 ));
300
331
}
332
+ mtu = zend_hash_str_find (Z_ARR_P (iface ), "mtu" , sizeof ("mtu" ) - 1 );
333
+ if (!mtu ) {
334
+ zend_long val ;
335
+ if (net_get_mtu (p -> ifa_name , & val ) == SUCCESS ) {
336
+ add_assoc_long (iface , "mtu" , val );
337
+ }
338
+ }
301
339
}
302
340
303
341
freeifaddrs (addrs );
0 commit comments