<commit_before># linux-lib.pl
# Active interface functions for all flavours of linux

# active_interfaces([include-no-ipv4-address])
# Returns a list of currently ifconfig'd interfaces
sub active_interfaces
{
local ($empty) = @_;
my @rv;
my $ethtool = &has_command("ethtool");

if (&has_command("ip")) {
	# Get status from new ip command
	&clean_language();
	&open_execute_command(IFC, "ip addr", 1, 1);
	my @lines;
	while(<IFC>) {
		s/\r|\n//g;
		if (/^\S+/) { push(@lines, $_); }
		else { $lines[$#lines] .= $_; }
		}
	close(IFC);
	&reset_environment();
	foreach my $l (@lines) {
		my %ifc;
		$l =~ /^\d+:\s+([^ \t\r\n\@]+):/ || next;
		$ifc{'name'} = $1;
		$ifc{'fullname'} = $1;
		if ($l =~ /\sinet\s+([0-9\.]+)\s+peer\s+([0-9\.]+)\/(\d+)(\s+brd\s+([0-9\.]+))?\s+scope\s+global(\s+dynamic)?\s+(\S+)/ && $7 eq $ifc{'name'}) {
			# Line like :
			# inet 172.16.17.32 peer 192.168.3.11/32 brd 172.16.17.32 scope global eth0
			$ifc{'address'} = $1;
			$ifc{'netmask'} = &prefix_to_mask("$3");
			}
		elsif ($l =~ /\sinet\s+([0-9\.]+)\/(\d+)(\s+brd\s+(\S+))?\s+scope\s+global(\s+dynamic)?\s+(\S+)/ && $6 eq $ifc{'name'}) {
			# Line like :
			# inet 172.16.17.32/24 brd 172.16.31.10 scope global br0
			$ifc{'address'} = $1;
			$ifc{'netmask'} = &prefix_to_mask("$2");
			}
		elsif ($l =~ /\sinet\s+([0-9\.]+)\s+peer\s+([0-9\.]+)\/(\d+)/) {
			# Line like :
			# inet 192.168.127.12 peer 172.16.31.10/32
			$ifc{'address'} = $1;
			$ifc{'netmask'} = &prefix_to_mask("$3");
			}
		elsif ($l =~ /\sinet\s+([0-9\.]+)\/(\d+)(\s+brd\s+(\S+))?\s+scope\s+host\s+(\S+)/ && $5 eq $ifc{'name'}) {
			# Line like :
			# inet 127.0.0.1/8 scope host lo
                        $ifc{'address'} = $1;
                        $ifc{'netmask'} = &prefix_to_mask("$3");
			}
		if ($l =~ /\sbrd\s+([0-9\.]+)/) {
			$ifc{'broadcast'} = $1;<commit_msg>Small fix to previous patch<commit_after># linux-lib.pl
# Active interface functions for all flavours of linux

# active_interfaces([include-no-ipv4-address])
# Returns a list of currently ifconfig'd interfaces
sub active_interfaces
{
local ($empty) = @_;
my @rv;
my $ethtool = &has_command("ethtool");

if (&has_command("ip")) {
	# Get status from new ip command
	&clean_language();
	&open_execute_command(IFC, "ip addr", 1, 1);
	my @lines;
	while(<IFC>) {
		s/\r|\n//g;
		if (/^\S+/) { push(@lines, $_); }
		else { $lines[$#lines] .= $_; }
		}
	close(IFC);
	&reset_environment();
	foreach my $l (@lines) {
		my %ifc;
		$l =~ /^\d+:\s+([^ \t\r\n\@]+):/ || next;
		$ifc{'name'} = $1;
		$ifc{'fullname'} = $1;
		if ($l =~ /\sinet\s+([0-9\.]+)\s+peer\s+([0-9\.]+)\/(\d+)(\s+brd\s+([0-9\.]+))?\s+scope\s+global(\s+dynamic)?\s+(\S+)/ && $7 eq $ifc{'name'}) {
			# Line like :
			# inet 172.16.17.32 peer 192.168.3.11/32 brd 172.16.17.32 scope global eth0
			$ifc{'address'} = $1;
			$ifc{'netmask'} = &prefix_to_mask("$3");
			}
		elsif ($l =~ /\sinet\s+([0-9\.]+)\/(\d+)(\s+brd\s+(\S+))?\s+scope\s+global(\s+dynamic)?\s+(\S+)/ && $6 eq $ifc{'name'}) {
			# Line like :
			# inet 172.16.17.32/24 brd 172.16.31.10 scope global br0
			$ifc{'address'} = $1;
			$ifc{'netmask'} = &prefix_to_mask("$2");
			}
		elsif ($l =~ /\sinet\s+([0-9\.]+)\s+peer\s+([0-9\.]+)\/(\d+)/) {
			# Line like :
			# inet 192.168.127.12 peer 172.16.31.10/32
			$ifc{'address'} = $1;
			$ifc{'netmask'} = &prefix_to_mask("$3");
			}
		elsif ($l =~ /\sinet\s+([0-9\.]+)\/(\d+)(\s+brd\s+(\S+))?\s+scope\s+host\s+(\S+)/ && $5 eq $ifc{'name'}) {
			# Line like :
			# inet 127.0.0.1/8 scope host lo
                        $ifc{'address'} = $1;
                        $ifc{'netmask'} = &prefix_to_mask("$2");
			}
		if ($l =~ /\sbrd\s+([0-9\.]+)/) {
			$ifc{'broadcast'} = $1;
{'fraction_non_alphanumeric': 0.2901469787697333, 'fraction_numerical': 0.061513336962438755, 'mean_word_length': 2.856243441762854, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 16, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3256930', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1693, 'n_words': 285}