Skip to content

Commit

Permalink
core: helper function to get socket by listen string
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 6, 2022
1 parent 507b8ab commit bed923d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/core/socket_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/socket_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bed923d

Please sign in to comment.