简体   繁体   中英

kamailio: how to extract IP from received route header

Could any help me to find way to extract IP & Port from route header received (which is on the SIP INVITE received from a remote server).

KAMAILO ----> A Server

A - Server is appending router header with destination IP address like below.

A Server ----> KAMAILIO

Route: <sip:<KAMILIO IP (Unchanged)>:5060;lr>,<sip:<B-Server>:5060;lr>

Here i need to extract the destination server (B-Server) IP & Port from received route header in the SIP INVITE.

KAMAILI ----> B - Server

i have found below from kamailio forum for extracting VIA header using select method, but i am not sure how to use the right variable for Route header.

    onreply_route[MANAGE_REPLY] {
    ...
    if(search_hf("Via", "received", "f")) {
            xdbg("received param exists on top most via header \n");
            $var(public_ip) = $sel(via.received);
        }
    ...
    }

A note that the call scenario and requirement is not clear in my opinion.

But in general you can access the Route header of a message using $hdr(Route) , eg:

$var(the_route) = $hdr(Route);

That would give you the whole list, in case of comma separated values, so from your example $var(the_route) would contain <sip:<KAMILIO IP (Unchanged)>:5060;lr>,<sip:<B-Server>:5060;lr> .

After that you can parse it by splitting on the comma with something like:

$var(route0) = $(var(the_route){s.select,0,,});
$var(route1) = $(var(the_route){s.select,1,,});

You can use an index and loop through it until the extracted value will be an empty string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM