Browse code

core: helper function to get socket by advertise address

Daniel-Constantin Mierla authored on 08/04/2022 10:38:27
Showing 2 changed files
... ...
@@ -878,6 +878,40 @@ socket_info_t* ksr_get_socket_by_listen(str *sockstr)
878 878
 	return NULL;
879 879
 }
880 880
 
881
+socket_info_t* ksr_get_socket_by_advertise(str *sockstr)
882
+{
883
+	socket_info_t *si = NULL;
884
+	struct socket_info** list;
885
+	unsigned short c_proto;
886
+
887
+	c_proto = PROTO_UDP;
888
+	do {
889
+		/* get the proper sock_list */
890
+		list=get_sock_info_list(c_proto);
891
+
892
+		if (list==0) {
893
+			/* disabled or unknown protocol */
894
+			continue;
895
+		}
896
+
897
+		for (si=*list; si; si=si->next) {
898
+			if(si->useinfo.sock_str.s == NULL) {
899
+				continue;
900
+			}
901
+			LM_DBG("checking if listen %.*s matches %.*s\n",
902
+					sockstr->len, sockstr->s,
903
+					si->useinfo.sock_str.len, si->useinfo.sock_str.s);
904
+			if (sockstr->len == si->useinfo.sock_str.len
905
+					&& strncasecmp(sockstr->s, si->useinfo.sock_str.s,
906
+							sockstr->len)==0) {
907
+				return si;
908
+			}
909
+		}
910
+	} while((c_proto = next_proto(c_proto))!=0);
911
+
912
+	return NULL;
913
+}
914
+
881 915
 /* checks if the proto:port is one of the ports we listen on
882 916
  * and returns the corresponding socket_info structure.
883 917
  * if proto==0 (PROTO_NONE) the protocol is ignored
... ...
@@ -105,6 +105,7 @@ struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
105 105
 												unsigned short proto);
106 106
 socket_info_t* ksr_get_socket_by_name(str *sockname);
107 107
 socket_info_t* ksr_get_socket_by_listen(str *sockstr);
108
+socket_info_t* ksr_get_socket_by_advertise(str *sockstr);
108 109
 
109 110
 struct socket_info** get_sock_info_list(unsigned short proto);
110 111