@@ -117,41 +117,54 @@ void wifi_fpm_set_sleep_type (sleep_type_t type)
117
117
uint32_t global_ipv4_netfmt = 0 ; // global binding
118
118
119
119
netif netif0;
120
+ uint32_t global_source_address = INADDR_ANY;
120
121
121
122
bool wifi_get_ip_info (uint8 if_index, struct ip_info *info)
122
123
{
124
+ // emulate wifi_get_ip_info()
125
+ // ignore if_index
126
+ // use global option -i (host_interface) to select bound interface/address
127
+
123
128
struct ifaddrs * ifAddrStruct = NULL , * ifa = NULL ;
124
129
uint32_t ipv4 = lwip_htonl (0x7f000001 );
125
130
uint32_t mask = lwip_htonl (0xff000000 );
131
+ global_source_address = INADDR_ANY; // =0
126
132
127
133
if (getifaddrs (&ifAddrStruct) != 0 )
128
134
{
129
135
perror (" getifaddrs" );
130
136
exit (EXIT_FAILURE);
131
137
}
138
+ if (host_interface)
139
+ mockverbose (" host: looking for interface '%s':\n " , host_interface);
140
+ else
141
+ mockverbose (" host: looking the first for non-local IPv4 interface:\n " );
132
142
for (ifa = ifAddrStruct; ifa != NULL ; ifa = ifa->ifa_next )
133
143
{
144
+ mockverbose (" host: interface: %s" , ifa->ifa_name );
134
145
if ( ifa->ifa_addr
135
146
&& ifa->ifa_addr ->sa_family == AF_INET // ip_info is IPv4 only
136
147
)
137
148
{
138
- if (lwip_ntohl (*(uint32_t *)&((struct sockaddr_in *) ifa->ifa_netmask )->sin_addr ) != 0xff000000 )
149
+ auto test_ipv4 = lwip_ntohl (*(uint32_t *)&((struct sockaddr_in *)ifa->ifa_addr )->sin_addr );
150
+ mockverbose (" IPV4 (0x%08lx)" , test_ipv4);
151
+ if ((test_ipv4 & 0xff000000 ) == 0x7f000000 )
152
+ // 127./8
153
+ mockverbose (" (local, ignored)" );
154
+ else
139
155
{
140
- if (ipv4 == lwip_htonl (0x7f000001 ))
141
- {
142
- // take the first by default
143
- ipv4 = *(uint32_t *)&((struct sockaddr_in *)ifa->ifa_addr )->sin_addr ;
144
- mask = *(uint32_t *)&((struct sockaddr_in *)ifa->ifa_netmask )->sin_addr ;
145
- }
146
- if (host_interface && strcmp (ifa->ifa_name , host_interface) == 0 )
156
+ if (!host_interface || (host_interface && strcmp (ifa->ifa_name , host_interface) == 0 ))
147
157
{
148
- // .. or the one specified by user on cmdline
158
+ // use the first non-local interface, or, if specified, the one selected by user on cmdline
149
159
ipv4 = *(uint32_t *)&((struct sockaddr_in *)ifa->ifa_addr )->sin_addr ;
150
160
mask = *(uint32_t *)&((struct sockaddr_in *)ifa->ifa_netmask )->sin_addr ;
161
+ mockverbose (" (selected)\n " );
162
+ global_source_address = ntohl (ipv4);
151
163
break ;
152
164
}
153
165
}
154
166
}
167
+ mockverbose (" \n " );
155
168
}
156
169
if (ifAddrStruct != NULL )
157
170
freeifaddrs (ifAddrStruct);
0 commit comments