소스 검색

core: function to search socket by name

Daniel-Constantin Mierla 5 년 전
부모
커밋
64069867c6
2개의 변경된 파일35개의 추가작업 그리고 0개의 파일을 삭제
  1. 34 0
      src/core/socket_info.c
  2. 1 0
      src/core/socket_info.h

+ 34 - 0
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

+ 1 - 0
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);