Permalink
Browse files

scan_intf: handle empty line with a single space in ifconfig output

  • Loading branch information...
1 parent f39fea3 commit ec5ee1e8c72b82a5c9fd037b9d5c15b89057ad89 @nniclausse nniclausse committed Jul 4, 2011
Showing with 54 additions and 1 deletion.
  1. +43 −0 src/test/ifcfg.out
  2. +7 −0 src/test/ts_test_config.erl
  3. +4 −1 src/tsung/ts_ip_scan.erl
View
@@ -0,0 +1,43 @@
+eth0 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.183 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ RX packets:2853444 errors:0 dropped:0 overruns:0 frame:0
+ TX packets:1157524 errors:0 dropped:0 overruns:0 carrier:0
+ collisions:0 txqueuelen:1000
+ RX bytes:342116836 (326.2 MiB) TX bytes:147190992 (140.3 MiB)
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:0 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.184 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:1 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.185 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:2 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.186 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:3 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.187 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:4 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.188 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:5 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.189 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
+
+eth0:6 Link encap:Ethernet HWaddr 68:B5:99:79:71:5C
+ inet addr:192.168.76.190 Bcast:192.168.79.255 Mask:255.255.248.0
+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
+ Interrupt:122 Memory:fb000000-fb7fffff
@@ -146,6 +146,13 @@ ifalias_test() ->
Res=ts_ip_scan:get_intf_aliases("lo"),
?assertEqual([{127,0,0,1}],Res).
+ifalias2_test() ->
+ {ok, L}=ts_utils:file_to_list("src/test/ifcfg.out"),
+ Out=ts_ip_scan:get_intf_aliases(L,"eth0",[],[]),
+ Res=lists:foldl(fun(A,L) -> [{192,168,76,A}|L] end, [],lists:seq(183,190)),
+ ?assertEqual(Out,Res).
+
+
encode_test() ->
Encoded="ts_encoded_47myfilepath_47toto_47titi_58sdfsdf_45sdfsdf_44aa_47",
Str="/myfilepath/toto/titi:sdfsdf-sdfsdf,aa/",
View
@@ -169,8 +169,11 @@ get_intf_aliases([" inet addr:"++Line|Tail], Interface, Interface, Res)
get_intf_aliases(Tail, Interface, Interface, lists:append([IP],Res));
get_intf_aliases([" "++_Line|Tail], Interface, Current, Res) ->
get_intf_aliases(Tail, Interface, Current, Res);
+get_intf_aliases([" "|Tail], Interface, Old, Res) ->
+ get_intf_aliases(Tail, Interface, Old, Res);
get_intf_aliases([Line|Tail], Interface, Old, Res) ->
- ?DebugF("scan line : ~p~n",[Line]),
+ ?LOGF("scan line : ~p~n",[Line],?DEB),
+ %% ?DebugF("scan line : ~p~n",[Line]),
case string:str(Line,Interface) of
1 ->
[Current|_] =string:tokens(Line," "),

0 comments on commit ec5ee1e

Please sign in to comment.