Module: sip-router
Branch: master
Commit: bc4ee02272f15c540e1010400542e2b2550e9524
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=bc4ee02…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Sun Mar 15 23:38:32 2009 +0100
Add sock_str (si as string) to struct socket_info.
This patch adds a new variable to the structure socket_info. The
variable contains a string representation of the socket in form
'proto:address:port'.
---
ip_addr.h | 1 +
socket_info.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/ip_addr.h b/ip_addr.h
index fdaf6f3..50bcbe4 100644
--- a/ip_addr.h
+++ b/ip_addr.h
@@ -113,6 +113,7 @@ struct socket_info{
struct socket_info* prev;
unsigned short port_no; /* port number */
char proto; /* tcp or udp*/
+ str sock_str; /* Socket proto, ip, and port as string */
struct addr_info* addr_info_lst; /* extra addresses (e.g. SCTP mh) */
};
diff --git a/socket_info.c b/socket_info.c
index abd3064..8fa909b 100644
--- a/socket_info.c
+++ b/socket_info.c
@@ -268,6 +268,7 @@ static void free_sock_info(struct socket_info* si)
if(si->address_str.s) pkg_free(si->address_str.s);
if(si->port_no_str.s) pkg_free(si->port_no_str.s);
if (si->addr_info_lst) free_addr_info_lst(&si->addr_info_lst);
+ if(si->sock_str.s) pkg_free(si->sock_str.s);
}
}
@@ -298,6 +299,42 @@ static char* get_proto_name(unsigned short proto)
}
+/* Fill si->sock_str with string representing the socket_info structure,
+ * format of the string is 'proto:address:port'. Returns 0 on success and
+ * negative number on failure.
+ */
+static int fix_sock_str(struct socket_info* si)
+{
+ char* p;
+ str proto;
+
+ if (si->sock_str.s) pkg_free(si->sock_str.s);
+
+ proto.s = get_proto_name(si->proto);
+ proto.len = strlen(proto.s);
+
+ si->sock_str.len = proto.len + si->address_str.len +
+ si->port_no_str.len + 2;
+
+ si->sock_str.s = pkg_malloc(si->sock_str.len + 1);
+ if (si->sock_str.s == NULL) {
+ LOG(L_ERR, "fix_sock_str: No pkg memory left\n");
+ return -1;
+ }
+ p = si->sock_str.s;
+ memcpy(p, proto.s, proto.len);
+ p += proto.len;
+ *p = ':'; p++;
+ memcpy(p, si->address_str.s, si->address_str.len);
+ p += si->address_str.len;
+ *p = ':'; p++;
+ memcpy(p, si->port_no_str.s, si->port_no_str.len);
+ p += si->port_no_str.len;
+ *p = '\0';
+
+ return 0;
+}
+
/* returns 0 if support for the protocol is not compiled or if proto is
invalid */
@@ -1028,6 +1065,8 @@ static int fix_socket_list(struct socket_info **list, int*
type_flags)
&ail->flags, type_flags, si) !=0 )
goto error;
}
+
+ if (fix_sock_str(si) < 0) goto error;
#ifdef EXTRA_DEBUG
printf(" %.*s [%s]:%s%s\n", si->name.len,