On Mon, Jun 20, 2011 at 01:47:39PM -0000, [email protected] 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
pgpqp4hyD5U7r.pgp
Description: PGP signature
