[yast-devel] Re: [yast-commit] r64487 - in /branches/SuSE-Code-11-SP2-Branch/dns-server: VERSION package/yast2-dns-server.changes src/dialog-main.ycp
On Mon, Jun 20, 2011 at 01:47:39PM -0000, locilka@svn2.opensuse.org wrote:
Author: locilka Date: Mon Jun 20 15:47:37 2011 New Revision: 64487
URL: http://svn.opensuse.org/viewcvs/yast?rev=64487&view=rev Log: - Automatically changing entered forwarder to a localhost IP if the server would forward to itself (non-local IP) (BNC #676676). - 2.17.16
Modified: branches/SuSE-Code-11-SP2-Branch/dns-server/src/dialog-main.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP2-Branch/dns-server/src/dialog-main.ycp?rev=64487&r1=64486&r2=64487&view=diff ============================================================================== --- branches/SuSE-Code-11-SP2-Branch/dns-server/src/dialog-main.ycp (original) +++ branches/SuSE-Code-11-SP2-Branch/dns-server/src/dialog-main.ycp Mon Jun 20 15:47:37 2011 @@ -428,6 +428,66 @@ }
/** + * Returns list of IPs currently used by the system. + * + * @param boolean whether local addresses should be returned as well (the default is false) + */ +list <string> CurrentlyUsedIPs (boolean including_local) { + string cmd = "ip addr show | grep 'inet\\(6\\)\\?' | sed 's/^[ \\t]\\+inet\\(6\\)\\?[ \\t]\\+\\([^\\/]\\+\\)\\/.*$/\\2/'";
BTW the -E/--extended-regexp flag makes it easier: grep -E 'inet6?' | ... And what I learned today, sed has -r/--regexp-extended (don't you love consistent tools?)
+ map cmd_ret = (map) SCR::Execute (.target.bash_output, cmd); + + if (cmd_ret == nil || cmd_ret["exit"]:-1 != 0) { + y2error ("Cannot get list of used IPs: %1", cmd_ret); + return nil; + } + + list <string> used_ips = splitstring (cmd_ret["stdout"]:"", "\n"); + used_ips = filter (string used_ip, used_ips, ``(used_ip != nil && used_ip != ""));
list <string> used_ips = String::NewlineItems(cmd_ret["stdout"]:""); Everyone raise your mouse cursor if you've ever reimplemented this function ;-)
+ + // Filtering out all local IPs + if (including_local != true) { + used_ips = filter (string used_ip, used_ips, ``( + !regexpmatch(used_ip, "127\.0\.0\..*") && used_ip != "::1" + )); + } + + return used_ips; +} -- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner
Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dne 20.6.2011 17:26, Martin Vidner napsal(a):
On Mon, Jun 20, 2011 at 01:47:39PM -0000, locilka@svn2.opensuse.org wrote:
/** + * Returns list of IPs currently used by the system. + * + * @param boolean whether local addresses should be returned as well (the default is false) + */ +list <string> CurrentlyUsedIPs (boolean including_local) { + string cmd = "ip addr show | grep 'inet\\(6\\)\\?' | sed 's/^[ \\t]\\+inet\\(6\\)\\?[ \\t]\\+\\([^\\/]\\+\\)\\/.*$/\\2/'";
BTW the -E/--extended-regexp flag makes it easier: grep -E 'inet6?' | ...
And what I learned today, sed has -r/--regexp-extended (don't you love consistent tools?)
In this case I might rather do all the parsing in YCP/Perl/Ruby and omit using grep/sed.
+ map cmd_ret = (map) SCR::Execute (.target.bash_output, cmd); + + if (cmd_ret == nil || cmd_ret["exit"]:-1 != 0) { + y2error ("Cannot get list of used IPs: %1", cmd_ret); + return nil; + } + + list <string> used_ips = splitstring (cmd_ret["stdout"]:"", "\n"); + used_ips = filter (string used_ip, used_ips, ``(used_ip != nil && used_ip != ""));
list <string> used_ips = String::NewlineItems(cmd_ret["stdout"]:"");
Everyone raise your mouse cursor if you've ever reimplemented this function ;-)
OK, reinvented Wheel replaced with Wheel 2.0. In fact, this String::XYZ should rather be a built-in ... IM(A)O ... but in another programming language ;) Thanks for your hints. - -- Lukas Ocilka, Appliances Department, SUSE LINUX s.r.o. MD: Jeff Hawn, Jennifer Guild, Alena Hendrichova -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/ iD8DBQFOAEqiVSqMdRCqTiwRAsWHAJ9kTriYoEDVmJjg9SBJbJhM6yYfmQCffYAB FwcdP1NFkXWnCqW6HEJJSGU= =Y/Yz -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (2)
-
Lukas Ocilka
-
Martin Vidner