From: Daniel-Constantin Mierla Date: Thu, 2 Apr 2020 10:20:32 +0000 (+0200) Subject: core: function to search socket by name X-Git-Tag: 5.4.0~593 X-Git-Url: http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=commitdiff_plain;h=64069867c65239af912d96b7865f4faefb64e338 core: function to search socket by name --- 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 @@ found: 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);