Module: kamailio
Branch: master
Commit: 1bde8e0e6193f0ed63452b3b8d31bfc78121dfb6
URL:
https://github.com/kamailio/kamailio/commit/1bde8e0e6193f0ed63452b3b8d31bfc…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-04-12T08:38:07+02:00
core: function to get local socket by index
---
Modified: src/core/socket_info.c
Modified: src/core/socket_info.h
---
Diff:
https://github.com/kamailio/kamailio/commit/1bde8e0e6193f0ed63452b3b8d31bfc…
Patch:
https://github.com/kamailio/kamailio/commit/1bde8e0e6193f0ed63452b3b8d31bfc…
---
diff --git a/src/core/socket_info.c b/src/core/socket_info.c
index 5622e2634d..c9dd89118d 100644
--- a/src/core/socket_info.c
+++ b/src/core/socket_info.c
@@ -912,6 +912,40 @@ socket_info_t* ksr_get_socket_by_advertise(str *sockstr)
return NULL;
}
+socket_info_t* ksr_get_socket_by_index(int idx)
+{
+ socket_info_t *si = NULL;
+ struct socket_info** list;
+ unsigned short c_proto;
+
+ if (idx<0) {
+ idx += _ksr_sockets_no;
+ if (idx < 0) {
+ LM_DBG("negative overall index\n");
+ return NULL;
+ }
+ }
+ 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(idx==0) {
+ return si;
+ }
+ idx--;
+ }
+ } 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 3c8deeb244..cbc630b9b8 100644
--- a/src/core/socket_info.h
+++ b/src/core/socket_info.h
@@ -106,6 +106,7 @@ struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
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);
+socket_info_t* ksr_get_socket_by_index(int idx);
struct socket_info** get_sock_info_list(unsigned short proto);