MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / grep_sock_info_ext

Function grep_sock_info_ext

socket_info.c:387–504  ·  view source on GitHub ↗

checks if the proto: host:port is one of the address we listen on * and returns the corresponding socket_info structure. * if port==0, the port number is ignored * if proto==0 (PROTO_NONE) the protocol is ignored * returns 0 if not found * WARNING: uses str2ip6 so it will overwrite any previous * unsaved result of this function (static buffer) */

Source from the content-addressed store, hash-verified

385 * unsaved result of this function (static buffer)
386 */
387const struct socket_info* grep_sock_info_ext(str* host, unsigned short port,
388 unsigned short proto, int check_tags)
389{
390 char* hname;
391 int h_len;
392 const struct socket_info* si = NULL;
393 struct socket_info_full* sif;
394 struct socket_info_full ** list;
395 unsigned short c_proto;
396 struct ip_addr* ip6;
397
398 h_len=host->len;
399 hname=host->s;
400
401 if (proto == PROTO_BOND) {
402 if (!check_tags)
403 goto not_found;
404 for (sif = bond_sockets; sif; sif = sif->next) {
405 si = &sif->socket_info;
406 if (h_len == si->name.len &&
407 strncasecmp(hname, si->name.s, si->name.len) == 0)
408 goto found;
409 }
410 goto not_found;
411 }
412
413 if ((h_len>2)&&((*hname)=='[')&&(hname[h_len-1]==']')){
414 /* ipv6 reference, skip [] */
415 hname++;
416 h_len-=2;
417 }
418
419 c_proto=proto?proto:PROTO_UDP;
420 do{
421 /* "proto" is all the time valid here */
422 list=get_sock_info_list(c_proto);
423
424 if (list==0){
425 LM_WARN("unknown proto %d\n", c_proto);
426 goto not_found; /* false */
427 }
428 for (sif=*list; sif; sif=sif->next){
429 si = &sif->socket_info;
430 LM_DBG("checking if host==us: %d==%d && "
431 " [%.*s] == [%.*s]\n",
432 h_len,
433 si->name.len,
434 h_len, hname,
435 si->name.len, si->name.s
436 );
437
438 if (check_tags && port==0 && si->tag.s && h_len==si->tag.len &&
439 strncasecmp(hname, si->tag.s, si->tag.len)==0 )
440 goto found;
441
442 if (port) {
443 LM_DBG("checking if port %d matches port %d\n",
444 si->port_no, port);

Callers

nothing calls this directly

Calls 2

str2ip6Function · 0.85
next_protoFunction · 0.85

Tested by

no test coverage detected