checks if the proto: ip:port is one of the address we listen on * and returns the corresponding socket_info structure. * (same as grep_socket_info, but use ip addr instead) * 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
| 515 | * unsaved result of this function (static buffer) |
| 516 | */ |
| 517 | const struct socket_info* find_si(const struct ip_addr* ip, unsigned short port, |
| 518 | unsigned short proto) |
| 519 | { |
| 520 | const struct socket_info* si = NULL; |
| 521 | struct socket_info_full* sif; |
| 522 | struct socket_info_full** list; |
| 523 | unsigned short c_proto; |
| 524 | |
| 525 | c_proto=proto?proto:PROTO_UDP; |
| 526 | do{ |
| 527 | /* get the proper sock_list */ |
| 528 | list=get_sock_info_list(c_proto); |
| 529 | |
| 530 | if (list==0){ |
| 531 | LM_WARN("unknown proto %d\n", c_proto); |
| 532 | goto not_found; /* false */ |
| 533 | } |
| 534 | for (sif=*list; sif; sif=sif->next){ |
| 535 | si = &sif->socket_info; |
| 536 | if (port) { |
| 537 | if (si->port_no!=port) { |
| 538 | continue; |
| 539 | } |
| 540 | } |
| 541 | if (ip_addr_cmp(ip, &si->address) || ip_addr_cmp(ip, &si->adv_address)) |
| 542 | goto found; |
| 543 | } |
| 544 | }while( (proto==0) && (c_proto=next_proto(c_proto)) ); |
| 545 | not_found: |
| 546 | return 0; |
| 547 | found: |
| 548 | return si; |
| 549 | } |
| 550 | |
| 551 | |
| 552 | /* parses the specified `spec` and returns an associated |
no test coverage detected