hostid fix on solaris
[deliverable/titan.core.git] / core / Runtime.cc
index 27ca3b3b28c021d65d08dec2ca960062654a0d1e..cf54eb6d6b7fdeb60a55bd34de8883040d014291 100644 (file)
@@ -16,6 +16,7 @@
  *   Lovassy, Arpad
  *   Raduly, Csaba
  *   Szabados, Kristof
+ *   Szabo, Bence Janos
  *   Szabo, Janos Zoltan – initial implementation
  *   Zalanyi, Balazs Andor
  *   Pandi, Krisztian
@@ -281,6 +282,39 @@ const char *TTCN_Runtime::get_host_name()
   return host_name;
 }
 
+CHARSTRING TTCN_Runtime::get_host_address(const CHARSTRING& type)
+{
+  if (type != "Ipv4orIpv6" && type != "Ipv4" && type != "Ipv6") {
+      TTCN_error("The argument of hostid function must be Ipv4orIpv6 or Ipv4"
+        "or Ipv6. %s is not a valid argument.", (const char*)type);
+  }
+  
+  // Return empty if no host address could be retrieved
+  if (!TTCN_Communication::has_local_address()) {
+    return CHARSTRING("");
+  }
+  const IPAddress *address = TTCN_Communication::get_local_address();
+  
+  // Return empty if the type is not matching the address type
+  if (type == "Ipv4") {
+    const IPv4Address * ipv4 = dynamic_cast<const IPv4Address*>(address);
+    if (ipv4 == NULL) {
+      return CHARSTRING("");
+    }
+  }
+  if (type == "Ipv6") {
+    const IPv6Address * ipv6 = NULL;
+#if defined(LINUX) || defined(CYGWIN17)
+    ipv6 = dynamic_cast<const IPv6Address*>(address);
+#endif // LINUX || CYGWIN17
+    if (ipv6 == NULL) {
+      return CHARSTRING("");
+    }
+  }
+  // Return the string representation of the address
+  return CHARSTRING(address->get_addr_str());
+}
+
 CHARSTRING TTCN_Runtime::get_testcase_id_macro()
 {
   if (in_controlpart()) TTCN_error("Macro %%testcaseId cannot be used from "
@@ -502,6 +536,9 @@ int TTCN_Runtime::ptc_main()
       ret_val = EXIT_FAILURE;
     }
     if (ret_val == EXIT_SUCCESS) {
+      if (ttcn3_debugger.is_activated()) {
+        ttcn3_debugger.open_output_file();
+      }
       try {
         do {
           TTCN_Snapshot::take_new(TRUE);
This page took 0.037099 seconds and 5 git commands to generate.