ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dce-misc.cc
Go to the documentation of this file.
1 #include "dce-misc.h"
2 #include "process.h"
3 #include "ns3/log.h"
4 #include "utils.h"
5 #include "ns3/names.h"
6 #include "ns3/node.h"
7 #include "ns3/node-list.h"
8 #include "dce-node-context.h"
9 #include "dce-manager.h"
10 #include "errno.h"
11 
12 using namespace ns3;
13 
14 NS_LOG_COMPONENT_DEFINE ("DceMisc");
15 
16 int dce_uname (struct utsname *buf)
17 {
18  Ptr<DceNodeContext> nodeContext = DceNodeContext::GetNodeContext ();
19  NS_ASSERT (0 != nodeContext);
20 
21  return nodeContext->UName (buf);
22 }
23 
24 int dce_gethostname (char *name, size_t len)
25 {
26  Thread *current = Current ();
27  NS_LOG_FUNCTION (current << UtilsGetNodeId ());
28  NS_ASSERT (current != 0);
29 
30  if (!name)
31  {
32  current->err = EFAULT;
33  return 1;
34  }
35  if (len <= 0)
36  {
37  current->err = EINVAL;
38  return 1;
39  }
40 
41  struct utsname tmp;
42 
43  dce_uname (&tmp);
44 
45  size_t sl = strlen (tmp.nodename);
46 
47  memset (name, 0, len);
48  memcpy (name, &tmp.nodename, std::min (sl, len));
49 
50  return 0;
51 }