Module: kamailio
Branch: master
Commit: 313c0a93ad2076a2eac88c95d8992c42975a36cf
URL:
https://github.com/kamailio/kamailio/commit/313c0a93ad2076a2eac88c95d8992c4…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-04-08T12:38:27+02:00
core: helper function to get socket by advertise address
---
Modified: src/core/socket_info.c
Modified: src/core/socket_info.h
---
Diff:
https://github.com/kamailio/kamailio/commit/313c0a93ad2076a2eac88c95d8992c4…
Patch:
https://github.com/kamailio/kamailio/commit/313c0a93ad2076a2eac88c95d8992c4…
---
diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index 2b29d2b95c..5622e2634d 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -878,6 +878,40 @@ socket_info_t* ksr_get_socket_by_listen(str *sockstr)
return NULL;
}
+socket_info_t* ksr_get_socket_by_advertise(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->useinfo.sock_str.s == NULL) {
+ continue;
+ }
+ LM_DBG("checking if listen %.*s matches %.*s\n",
+ sockstr->len, sockstr->s,
+ si->useinfo.sock_str.len, si->useinfo.sock_str.s);
+ if (sockstr->len == si->useinfo.sock_str.len
+ && strncasecmp(sockstr->s, si->useinfo.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 0b517de2de..3c8deeb244 100644
--- a/src/core/socket_info.h
+++ b/src/core/socket_info.h
@@ -105,6 +105,7 @@ 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);
+socket_info_t* ksr_get_socket_by_advertise(str *sockstr);
struct socket_info** get_sock_info_list(unsigned short proto);