@@ -184,60 +184,54 @@ TEST_F(Testutil, separate_ip_addresses)
184184 char ip[64 ] = {0 };
185185 char subnet[64 ] = {0 };
186186
187- strncpy (s, " 32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15\0 " , 95 );
187+ // IP address representations formats are for IPv6 or IPv4 address, with and without mask, in dotted or colon (IPv6 only) notation
188+
189+ // IPv6 with a mask in dotted notation
190+ strncpy (s, " 32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15\0 " ,
191+ sizeof (" 32.1.20.187.1.112.139.245.251.136.232.110.123.51.230.138.0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15\0 " ));
188192 separate_ip_addresses (NULL , ip, sizeof (ip), subnet, sizeof (subnet));
189193
190194 separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
191195 EXPECT_STREQ (" 2001:14BB:170:8BF5:FB88:E86E:7B33:E68A" , ip);
192196 EXPECT_STREQ (" 001:203:405:607:809:A0B:C0D:E0F" , subnet);
193197
194- strncpy (s, " 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15\0 " , 95 );
198+ // IPv6 with mask in colon notation
199+ strncpy (s, " 32:1:20:187:1:112:139:1245 0:1:2:3:4:5:6:7\0 " , sizeof (" 32:1:20:187:1:112:139:1245 0:1:2:3:4:5:6:7\0 " ));
195200 separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
196- EXPECT_STREQ (" 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 " , ip);
197- EXPECT_STREQ (" 0:1:2:3:4:5:6:7:8:9:10:11:12:13:14:15 " , subnet);
201+ EXPECT_STREQ (" 32:1:20:187:1:112:139:1245 " , ip);
202+ EXPECT_STREQ (" 0:1:2:3:4:5:6:7" , subnet);
198203
199204 ip[0 ] = ' \0 ' ;
200205 subnet[0 ] = ' \0 ' ;
201- strncpy (s, " 1.2.3.4\0 " , 8 );
206+ // IPv6 without mask in dotted notation
207+ strncpy (s, " 0.2.3.4.5.6.7.8.90.100.11.12.13.14.15.16\0 " , sizeof (" 0.2.3.4.5.6.7.8.90.100.11.12.13.14.15.16\0 " ));
202208 separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
203- EXPECT_STREQ (" 1.2.3.4 " , ip);
209+ EXPECT_STREQ (" 002:304:506:708:5A64:B0C:D0E:F10 " , ip);
204210 EXPECT_STREQ (" " , subnet);
205211
206212 ip[0 ] = ' \0 ' ;
207213 subnet[0 ] = ' \0 ' ;
208- strncpy (s, " 1.2.3.4.5.6.7.8\0 " , 16 );
209- separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
210- EXPECT_STREQ (" 1.2.3.4" , ip);
211- EXPECT_STREQ (" 5.6.7.8" , subnet);
212-
213- ip[0 ] = ' \0 ' ;
214- subnet[0 ] = ' \0 ' ;
215- strncpy (s, " 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16\0 " , 39 );
214+ // IPv6 without mask in colon notation
215+ strncpy (s, " 0032:1:20:187:0:112:139:245f\0 " , sizeof (" 0032:1:20:187:0:112:139:245f\0 " ));
216216 separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
217- EXPECT_STREQ (" 102:304:506:708:90A:B0C:D0E:F10 " , ip);
217+ EXPECT_STREQ (" 0032:1:20:187:0:112:139:245f " , ip);
218218 EXPECT_STREQ (" " , subnet);
219219
220220 ip[0 ] = ' \0 ' ;
221221 subnet[0 ] = ' \0 ' ;
222- strncpy (s, " 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0 " , 57 );
222+ // IPv4 with mask
223+ strncpy (s, " 100.0.3.40.255.6.7.80\0 " , sizeof (" 100.0.3.40.255.6.7.80\0 " ));
223224 separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
224- EXPECT_STREQ (" 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138 " , ip);
225- EXPECT_STREQ (" " , subnet);
225+ EXPECT_STREQ (" 100.0.3.40 " , ip);
226+ EXPECT_STREQ (" 255.6.7.80 " , subnet);
226227
227228 ip[0 ] = ' \0 ' ;
228229 subnet[0 ] = ' \0 ' ;
229- strncpy (s, " 1.2.3.4 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138\0 " , 65 );
230+ // IPv4 without mask
231+ strncpy (s, " 1.255.3.0\0 " , sizeof (" 1.255.3.0\0 " ));
230232 separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
231- EXPECT_STREQ (" 1.2.3.4" , ip);
232- EXPECT_STREQ (" 32:1:20:187:1:112:139:245:251:136:232:110:123:51:230:138" , subnet);
233-
234- ip[0 ] = ' \0 ' ;
235- subnet[0 ] = ' \0 ' ;
236- strncpy (s, " 1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20\0 " , 51 );
237- separate_ip_addresses (s, ip, sizeof (ip), subnet, sizeof (subnet));
238- EXPECT_STREQ (" 1.2.3.4" , ip);
239- EXPECT_STREQ (" 506:708:90A:B0C:D0E:F10:1112:1314" , subnet);
240- EXPECT_STREQ (" 1.2.3.4 5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20" , s);
233+ EXPECT_STREQ (" 1.255.3.0" , ip);
234+ EXPECT_STREQ (" " , subnet);
241235}
242236
243237TEST_F (Testutil, get_dynamic_ip_port)
0 commit comments