Commit e5fe1220 authored by Shashi Guruprasad's avatar Shashi Guruprasad

Changes so as to not depend on 'tmcc hostnames' output format to map

testbed experimental node names to ip addresses. A new class TbResolver
has been written that uses gethostbyname() to resolve ip addresses.
In case this doesn't work, we try the 'tmcc hostnames' approach
parent b812c101
......@@ -4,6 +4,13 @@
# returns ip address of name
proc getipaddr {name} {
set resolver [new TbResolver]
set ip [$resolver lookup $name]
delete $resolver
if { $ip != {} } {
return $ip
}
set hostnamelist [split [exec tmcc hostnames] "\n"]
foreach hostname $hostnamelist {
scan $hostname "NAME=%s IP=%s ALIASES=\'%s\'" hname ip aliases
......
......@@ -4,6 +4,13 @@
# returns ip address of name
proc getipaddr {name} {
set resolver [new TbResolver]
set ip [$resolver lookup $name]
delete $resolver
if { $ip != {} } {
return $ip
}
set hostnamelist [split [exec tmcc hostnames] "\n"]
foreach hostname $hostnamelist {
scan $hostname "NAME=%s IP=%s ALIASES=\'%s\'" hname ip aliases
......
#include "tbevent.h"
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
static class TbEventSinkClass : public TclClass {
public:
......@@ -6,7 +11,7 @@ public:
TclObject* create(int /* argc */, const char*const* /* argv */) {
return (new TbEventSink);
}
} class_realtime_sched;
} class_tbevent_sink;
void
......@@ -170,3 +175,35 @@ TbEventSink::subscribe() {
address_tuple_free(tuple);
}
static class TbResolverClass : public TclClass {
public:
TbResolverClass() : TclClass("TbResolver") {}
TclObject* create(int /* argc */, const char*const* /* argv */) {
return (new TbResolver);
}
} class_tbresolver;
int TbResolver::command(int argc, const char*const* argv)
{
if( argc == 3 ) {
if(strcmp(argv[1], "lookup") == 0) {
struct hostent *he = gethostbyname(argv[2]);
struct in_addr myip;
char ipaddr[BUFSIZ];
Tcl &tcl = Tcl::instance();
if( he ) {
memcpy((char *)&myip, he->h_addr, he->h_length);
strncpy(ipaddr, inet_ntoa(myip), sizeof(ipaddr));
sprintf(tcl.buffer(), "%s", ipaddr );
tcl.result(tcl.buffer());
} else {
tcl.result("");
}
return(TCL_OK);
}
}
return (TclObject::command(argc, argv));
}
......@@ -19,9 +19,6 @@ extern "C" {
}
#endif
#include <netdb.h>
#include <netinet/in.h>
class TbEventSink : public TclObject {
public:
TbEventSink() : gotevent(0), ehandle(0) {
......@@ -51,4 +48,9 @@ private:
event_notification_t notification, void *data);
};
class TbResolver : public TclObject {
public:
virtual int command(int argc, const char*const* argv);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment