41 CADynaNetworking::CADynaNetworking() : CAInfoServiceAware()
45 CADynaNetworking::~CADynaNetworking()
63 SINT32 CADynaNetworking::updateNetworkConfiguration(
UINT16 a_port)
65 UINT8 internalIp[255];
66 UINT8 externalIp[255];
69 if( resolveInternalIp( internalIp ) ==
E_UNKNOWN )
79 pglobalOptions->resetNetworkConfiguration();
82 pglobalOptions->getMixXml(doc);
83 DOM_Element elemRoot = doc.getDocumentElement();
84 DOM_Element elemListeners;
86 if(elemListeners == NULL)
88 elemListeners = doc.createElement(
"ListenerInterfaces");
89 elemRoot.appendChild( elemListeners );
92 if(strcmp((
char*)internalIp, (
char*)externalIp) == 0)
95 createListenerInterface( elemListeners, doc, internalIp, a_port,
false,
false);
98 createListenerInterface( elemListeners, doc, internalIp, a_port,
true,
false);
99 createListenerInterface( elemListeners, doc, externalIp, a_port,
false,
true);
121 SINT32 CADynaNetworking::createListenerInterface(DOM_Element r_elemListeners, DOM_Document a_ownerDoc,
const UINT8 *a_ip,
UINT32 a_port,
bool a_bHidden,
bool a_bVirtual)
125 DOM_Element elemListener=a_ownerDoc.createElement(
"ListenerInterface");
128 elemListener.setAttribute(
"hidden",
"True");
133 elemListener.setAttribute(
"virtual",
"True");
135 r_elemListeners.appendChild(elemListener);
136 elemTmp=a_ownerDoc.createElement(
"Port");
138 elemListener.appendChild(elemTmp);
139 elemTmp=a_ownerDoc.createElement(
"NetworkProtocol");
141 elemListener.appendChild(elemTmp);
142 elemTmp=a_ownerDoc.createElement(
"IP");
144 elemListener.appendChild(elemTmp);
151 pglobalOptions->addListenerInterface(elemListener);
162 UINT32 interfaces = pglobalOptions->getListenerInterfaceCount();
164 for(
UINT32 i = 1; i <= interfaces; i++ )
166 pListener = pglobalOptions->getListenerInterface(i);
185 CADynaNetworking* parent = (CADynaNetworking*)p;
189 char *pechoRequest = NULL;
192 CAMsg::printMsg(LOG_DEBUG,
"CADynaNetworking - ConnectivityLoop() started\n");
195 if(pListener == NULL)
197 CAMsg::printMsg(LOG_DEBUG,
"CADynaNetworking - ConnectivityLoop - No valid ListenerInterface found, aborting\n");
206 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - ConnectivityLoop - Unable to listen to standard port, aborting\n");
210 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - ConnectivityLoop - Ok, listening...\n");
214 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - ConnectivityLoop - Unable to accept on standard port, aborting\n");
218 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - ConnectivityLoop - Ok, i accepted\n");
222 CAMsg::printMsg(LOG_DEBUG,
"CADynaNetworking - ConnectivityLoop - Received %i Bits: (%s)\n", rLen, buff);
224 pechoRequest =
new char[rLen+1];
225 strncpy(pechoRequest, buff, rLen+1);
227 CAMsg::printMsg(LOG_DEBUG,
"CADynaNetworking - ConnectivityLoop - echoRequest: (%s)\n", pechoRequest);
228 CAMsg::printMsg(LOG_DEBUG,
"CADynaNetworking - ConnectivityLoop - Will send: %i chars, %s\n", strlen(pechoRequest), pechoRequest);
231 socket.
send( (
const UINT8*)pechoRequest, rLen);
240 serverSocket.
close();
255 SINT32 CADynaNetworking::verifyConnectivity()
258 DOM_Element elemRoot;
264 m_pthreadConnectivtyLoop->
setMainLoop(ConnectivityLoop);
266 m_pthreadConnectivtyLoop->
start(
this);
274 if(pListener == NULL)
276 CAMsg::printMsg( LOG_DEBUG,
"Didn't find a useable ListenerInterface, exiting\n");
278 m_pthreadConnectivtyLoop->
join();
289 if( sendConnectivityRequest( &elemRoot, port) !=
E_SUCCESS )
291 CAMsg::printMsg(LOG_DEBUG,
"CADynaNetworking - verifyConnectivity - Unable to query Infoservice for connectivity! This might becomes a problem soon!\n");
296 m_pthreadConnectivtyLoop->
join();
302 m_pthreadConnectivtyLoop->
join();
306 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - verifyConnectivity - InfoService answer was not parsable\n");
312 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - verifyConnectivity - InfoService answer was not parsable\n");
318 CAMsg::printMsg(LOG_ERR,
"CADynaNetworking - verifyConnectivity - InfoService answer was not parsable\n");
322 if( strcmp( (
const char*)res,
"OK" ) == 0)
325 delete m_pthreadConnectivtyLoop;
326 m_pthreadConnectivtyLoop = NULL;
340 SINT32 CADynaNetworking::sendConnectivityRequest( DOM_Element *r_elemRoot,
UINT32 a_port )
342 DOM_Document doc = DOM_Document::createDocument();
343 DOM_Element elemRoot = doc.createElement(
"ConnectivityCheck");
344 doc.appendChild(elemRoot);
345 DOM_Element elemPort = doc.createElement(
"Port");
347 elemRoot.appendChild(elemPort);
351 sendRandomInfoserviceRequest( (
UINT8*)
"/connectivity", r_elemRoot, buffOut, lenOut);
364 SINT32 CADynaNetworking::resolveInternalIp(
UINT8* r_ip)
367 struct hostent *hent;
370 if (gethostname(hostname,
sizeof(hostname)) < 0)
375 in.s_addr=inet_addr(hostname);
378 hent = (
struct hostent *)gethostbyname(hostname);
381 assert(hent->h_length == 4);
382 memcpy( &in.s_addr, hent->h_addr, hent->h_length );
384 if( isInternalIp( ntohl(in.s_addr) ) )
387 if( getInterfaceIp(&internalIp) ==
E_SUCCESS)
389 in.s_addr = internalIp;
395 if( getInterfaceIp(&internalIp) ==
E_SUCCESS )
397 in.s_addr = internalIp;
401 char* tmp = inet_ntoa(in);
402 strcpy((
char*)r_ip, tmp);
449 sprintf((
char*) request,
"/echoip");
451 DOM_Element elemRoot;
452 if( sendRandomInfoserviceGetRequest(request, &elemRoot) !=
E_SUCCESS )
454 CAMsg::printMsg(LOG_DEBUG,
"CAInfoService::getPublicIp - Unable to query Infoservice for public IP! This will be a problem soon!\n");
460 CAMsg::printMsg(LOG_ERR,
"CAInfoService::getPublicIp - Answer was not parsable\n");
467 CAMsg::printMsg(LOG_ERR,
"CAInfoService::getPublicIp - Answer was not parsable!\n");
473 CAMsg::printMsg(LOG_ERR,
"CAInfoService::getPublicIp - Answer was not parsable!\n");
481 bool CADynaNetworking::isInternalIp(
UINT32 a_ip)
483 if (((a_ip & 0xff000000) == 0x0a000000) ||
484 ((a_ip & 0xff000000) == 0x00000000) ||
485 ((a_ip & 0xff000000) == 0x7f000000) ||
486 ((a_ip & 0xffff0000) == 0xa9fe0000) ||
487 ((a_ip & 0xfff00000) == 0xac100000) ||
488 ((a_ip & 0xffff0000) == 0xc0a80000))
#define BEGIN_STACK(methodName)
#define FINISH_STACK(methodName)
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
SINT32 getDOMChildByName(const DOMNode *pNode, const char *const name, DOMElement *&child, bool deep)
SINT32 msSleep(UINT32 ms)
Sleeps ms milliseconds.
#define THREAD_RETURN_ERROR
#define THREAD_RETURN_SUCCESS
CASocketAddr * getAddr() const
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
This class represents a socket address for Internet (IP) connections.
SINT32 setAddr(const UINT8 *szIP, UINT16 port)
Sets the address to szIP and port.
UINT16 getPort() const
Returns the port value of the address.
virtual SINT32 receive(UINT8 *buff, UINT32 len)
Will receive some bytes from the socket.
virtual SINT32 listen(const CASocketAddr &psa)
Starts listening on address psa.
virtual SINT32 send(const UINT8 *buff, UINT32 len)
Sends some data over the network.
virtual SINT32 setSendTimeOut(UINT32 msTimeOut)
virtual SINT32 accept(CASocket &s)
Accepts a new connection.
virtual SINT32 getLocalIP(UINT8 r_Ip[4])
LERNGRUPPE Returns the source address of the socket.
virtual SINT32 connect(const CASocketAddr &psa)
SINT32 start(void *param, bool bDaemon=false, bool bSilent=false)
Starts the execution of the main function of this thread.
SINT32 setMainLoop(THREAD_MAIN_TYP fnc)
Sets the main function which will be executed within this thread.
SINT32 join()
Waits for the main function to finish execution.
static SINT32 dumpToMem(const DOMNode *node, UINT8 *buff, UINT32 *size)
Dumps the node and all childs into buff.