Module: kamailio Branch: master Commit: bed923ddb92d9d7b694167f0276414373d3297c4 URL: https://github.com/kamailio/kamailio/commit/bed923ddb92d9d7b694167f027641437...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@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/bed923ddb92d9d7b694167f027641437... Patch: https://github.com/kamailio/kamailio/commit/bed923ddb92d9d7b694167f027641437...
---
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);