[sr-dev] git:master:64069867: core: function to search socket by name

Daniel-Constantin Mierla miconda at gmail.com
Thu Apr 2 12:24:50 CEST 2020


Module: kamailio
Branch: master
Commit: 64069867c65239af912d96b7865f4faefb64e338
URL: https://github.com/kamailio/kamailio/commit/64069867c65239af912d96b7865f4faefb64e338

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2020-04-02T12:20:32+02:00

core: function to search socket by name

---

Modified: src/core/socket_info.c
Modified: src/core/socket_info.h

---

Diff:  https://github.com/kamailio/kamailio/commit/64069867c65239af912d96b7865f4faefb64e338.diff
Patch: https://github.com/kamailio/kamailio/commit/64069867c65239af912d96b7865f4faefb64e338.patch

---

diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index 82e66123b4..16a7491f83 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -687,6 +687,40 @@ struct socket_info* grep_sock_info(str* host, unsigned short port,
 	return si;
 }
 
+socket_info_t* ksr_get_socket_by_name(str *sockname)
+{
+	socket_info_t *si = NULL;
+	struct socket_info** list;
+	unsigned short c_proto;
+
+	c_proto = PROTO_UDP;
+	do {
+		/* get the proper sock_list */
+		list=get_sock_info_list(c_proto);
+
+		if (list==0) {
+			/* disabled or unknown protocol */
+			continue;
+		}
+
+		for (si=*list; si; si=si->next) {
+			if(si->sockname.s == NULL) {
+				continue;
+			}
+			LM_DBG("checking if sockname %.*s matches %.*s\n",
+					sockname->len, sockname->s,
+					si->sockname.len, si->sockname.s);
+			if (sockname->len == si->sockname.len
+					&& strncasecmp(sockname->s, si->sockname.s,
+							sockname->len)==0) {
+				return si;
+			}
+		}
+	} while((c_proto = next_proto(c_proto))!=0);
+
+	return NULL;
+}
+
 /* checks if the proto:port is one of the ports we listen on
  * and returns the corresponding socket_info structure.
  * if proto==0 (PROTO_NONE) the protocol is ignored
diff --git a/src/core/socket_info.h b/src/core/socket_info.h
index ffdc419921..4bf7b3e96c 100644
--- a/src/core/socket_info.h
+++ b/src/core/socket_info.h
@@ -103,6 +103,7 @@ struct socket_info* grep_sock_info_by_port(unsigned short port,
 											unsigned short proto);
 struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
 												unsigned short proto);
+socket_info_t* ksr_get_socket_by_name(str *sockname);
 
 struct socket_info** get_sock_info_list(unsigned short proto);
 




More information about the sr-dev mailing list