Module: sip-router
Branch: master
Commit: b7bbcd730b21e7480dc1f1e26de58750395e6ff6
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b7bbcd7…
Author: Charles Chance <charles.chance(a)sipcentric.com>
Committer: Charles Chance <charles.chance(a)sipcentric.com>
Date: Tue Sep 9 23:41:47 2014 +0100
dmq: resolve IP address and store in node structure
---
modules/dmq/dmqnode.c | 19 +++++++++++++++++--
modules/dmq/dmqnode.h | 1 +
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/modules/dmq/dmqnode.c b/modules/dmq/dmqnode.c
index 18b053b..5ac3951 100644
--- a/modules/dmq/dmqnode.c
+++ b/modules/dmq/dmqnode.c
@@ -24,6 +24,7 @@
*/
#include "../../ut.h"
+#include "../../resolve.h"
#include "dmqnode.h"
#include "dmq.h"
@@ -146,7 +147,11 @@ dmq_node_t* build_dmq_node(str* uri, int shm) {
dmq_node_t* ret = NULL;
param_hooks_t hooks;
param_t* params;
-
+
+ /* For DNS-Lookups */
+ static char hn[256];
+ struct hostent* he;
+
LM_DBG("build_dmq_node %.*s with %s memory\n", STR_FMT(uri),
shm?"shm":"private");
if(shm) {
@@ -171,7 +176,7 @@ dmq_node_t* build_dmq_node(str* uri, int shm) {
}
}
set_default_dmq_node_params(ret);
- if(parse_uri(ret->orig_uri.s, ret->orig_uri.len, &ret->uri) < 0) {
+ if(parse_uri(ret->orig_uri.s, ret->orig_uri.len, &ret->uri) < 0 ||
ret->uri.host.len > 254) {
LM_ERR("error parsing uri\n");
goto error;
}
@@ -199,6 +204,16 @@ dmq_node_t* build_dmq_node(str* uri, int shm) {
} else {
LM_DBG("no dmqnode params found\n");
}
+ /* resolve hostname */
+ strncpy(hn, ret->uri.host.s, ret->uri.host.len);
+ hn[ret->uri.host.len]='\0';
+ he=resolvehost(hn);
+ if (he==0) {
+ LM_ERR("could not resolve %.*s\n", ret->uri.host.len,
ret->uri.host.s);
+ goto error;
+ }
+ hostent2ip_addr(&ret->ip_address, he, 0);
+
return ret;
error:
diff --git a/modules/dmq/dmqnode.h b/modules/dmq/dmqnode.h
index dfe684d..10e2962 100644
--- a/modules/dmq/dmqnode.h
+++ b/modules/dmq/dmqnode.h
@@ -44,6 +44,7 @@ typedef struct dmq_node {
int local; /* local type set means the dmq dmqnode == self */
str orig_uri; /* original uri string - e.g. sip:127.0.0.1:5060;passive=true */
struct sip_uri uri; /* parsed uri string */
+ struct ip_addr ip_address; /* resolved IP address */
param_t* params; /* uri parameters */
int status; /* reserved - maybe something like active,timeout,disabled */
int last_notification; /* last notificatino receied from the node */