@@ -63,6 +63,28 @@ static const char *_php_source_op_to_string(enum source_op sop);
63
63
static int _php_source_op_to_ipv4_op (enum source_op sop );
64
64
#endif
65
65
66
+ int php_string_to_if_index (const char * val , unsigned * out TSRMLS_DC )
67
+ {
68
+ #if HAVE_IF_NAMETOINDEX
69
+ unsigned int ind ;
70
+
71
+ ind = if_nametoindex (val );
72
+ if (ind == 0 ) {
73
+ php_error_docref (NULL TSRMLS_CC , E_WARNING ,
74
+ "no interface with name \"%s\" could be found" , val );
75
+ return FAILURE ;
76
+ } else {
77
+ * out = ind ;
78
+ return SUCCESS ;
79
+ }
80
+ #else
81
+ php_error_docref (NULL TSRMLS_CC , E_WARNING ,
82
+ "this platform does not support looking up an interface by "
83
+ "name, an integer interface index must be supplied instead" );
84
+ return FAILURE ;
85
+ #endif
86
+ }
87
+
66
88
static int php_get_if_index_from_zval (zval * val , unsigned * out TSRMLS_DC )
67
89
{
68
90
int ret ;
@@ -78,31 +100,17 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out TSRMLS_DC)
78
100
ret = SUCCESS ;
79
101
}
80
102
} else {
81
- #if HAVE_IF_NAMETOINDEX
82
- unsigned int ind ;
83
103
zval_add_ref (& val );
84
104
convert_to_string_ex (& val );
85
- ind = if_nametoindex (Z_STRVAL_P (val ));
86
- if (ind == 0 ) {
87
- php_error_docref (NULL TSRMLS_CC , E_WARNING ,
88
- "no interface with name \"%s\" could be found" , Z_STRVAL_P (val ));
89
- ret = FAILURE ;
90
- } else {
91
- * out = ind ;
92
- ret = SUCCESS ;
93
- }
105
+ ret = php_string_to_if_index (Z_STRVAL_P (val ), out TSRMLS_CC );
94
106
zval_ptr_dtor (& val );
95
- #else
96
- php_error_docref (NULL TSRMLS_CC , E_WARNING ,
97
- "this platform does not support looking up an interface by "
98
- "name, an integer interface index must be supplied instead" );
99
- ret = FAILURE ;
100
- #endif
101
107
}
102
108
103
109
return ret ;
104
110
}
105
111
112
+
113
+
106
114
static int php_get_if_index_from_array (const HashTable * ht , const char * key ,
107
115
php_socket * sock , unsigned int * if_index TSRMLS_DC )
108
116
{
0 commit comments