[sr-dev] git:master:bed923dd: core: helper function to get socket by listen string

Daniel-Constantin Mierla miconda at gmail.com
Wed Apr 6 17:23:34 CEST 2022


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-04-06T17:00:02+02:00

core: helper function to get socket by listen string

---

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

---

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

---

diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index a60c4c5678..2b29d2b95c 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -844,6 +844,40 @@ socket_info_t* ksr_get_socket_by_name(str *sockname)
 	return NULL;
 }
 
+socket_info_t* ksr_get_socket_by_listen(str *sockstr)
+{
+	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->sock_str.s == NULL) {
+				continue;
+			}
+			LM_DBG("checking if listen %.*s matches %.*s\n",
+					sockstr->len, sockstr->s,
+					si->sock_str.len, si->sock_str.s);
+			if (sockstr->len == si->sock_str.len
+					&& strncasecmp(sockstr->s, si->sock_str.s,
+							sockstr->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 77baeb42fb..0b517de2de 100644
--- a/src/core/socket_info.h
+++ b/src/core/socket_info.h
@@ -104,6 +104,7 @@ struct socket_info* grep_sock_info_by_port(unsigned short port,
 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);
+socket_info_t* ksr_get_socket_by_listen(str *sockstr);
 
 struct socket_info** get_sock_info_list(unsigned short proto);
 




More information about the sr-dev mailing list