Skip to content

Commit

Permalink
Standardize empty IP address return values
Browse files Browse the repository at this point in the history
  • Loading branch information
ztefn committed Oct 3, 2021
1 parent c8760a0 commit 6660e49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
22 changes: 17 additions & 5 deletions src/hamachi.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Hamachi : Object

public static void init ()
{
ip_version = "IPv4";
ip_version = "";
demo_account = "-";

get_info();
Expand Down Expand Up @@ -260,18 +260,31 @@ public class Hamachi : Object

ipv4 = mi.fetch_named ("ipv4");
ipv6 = mi.fetch_named ("ipv6");

Debug.log (Debug.domain.HAMACHI, "Hamachi.get_address", "IPv4: " + ipv4);
Debug.log (Debug.domain.HAMACHI, "Hamachi.get_address", "IPv6: " + ipv6);
}
catch (RegexError e)
{
Debug.log (Debug.domain.ERROR, "Hamachi.get_address", e.message);
}

if ((ipv4 != "") &&
if (ipv4 == "")
{
ipv4 = null;
}

if (ipv6 == "")
{
ipv6 = null;
}

if ((ipv4 != null) &&
(ipv6 != null))
{
ip_version = "Both";
}
else if (ipv4 != "")
else if (ipv4 != null)
{
ip_version = "IPv4";
}
Expand All @@ -280,8 +293,7 @@ public class Hamachi : Object
ip_version = "IPv6";
}

Debug.log (Debug.domain.HAMACHI, "Hamachi.get_address", "IPv4: " + ipv4);
Debug.log (Debug.domain.HAMACHI, "Hamachi.get_address", "IPv6: " + ipv6);
Debug.log (Debug.domain.HAMACHI, "Hamachi.get_address", "IP version: " + ip_version);

return new string[] {ipv4, ipv6};
}
Expand Down
3 changes: 1 addition & 2 deletions src/headerbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public class Headerbar : HeaderBar

copy_section.remove_all();

if ((ipv4 != null) &&
(ipv4 != ""))
if (ipv4 != null)
{
copy_section.append_item (copy_ipv4);
}
Expand Down
3 changes: 1 addition & 2 deletions src/sidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,7 @@ public class Sidebar : Box
string ipv4 = address[0];
string ipv6 = address[1];

if ((ipv4 == null) ||
(ipv4 == ""))
if (ipv4 == null)
{
ipv4_label.hide();
ipv4_entry.hide();
Expand Down

0 comments on commit 6660e49

Please sign in to comment.