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

Function update_sock_struct_from_via

forward.c:431–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429
430
431int update_sock_struct_from_via( union sockaddr_union* to,
432 struct sip_msg* msg,
433 struct via_body* via )
434{
435 struct hostent* he;
436 str* name;
437 int err;
438 unsigned short port;
439
440 port=0;
441 if(via==msg->via1){
442 /* _local_ reply, we ignore any rport or received value
443 * (but we will send back to the original port if rport is
444 * present) */
445 if ((msg->msg_flags&FL_FORCE_RPORT)||(via->rport))
446 port=msg->rcv.src_port;
447 else port=via->port;
448 if(via->maddr)
449 name= &(via->maddr->value);
450 else
451 name=&(via->host); /* received=ip in 1st via is ignored (it's
452 not added by us so it's bad) */
453 }else{
454 /* "normal" reply, we use rport's & received value if present */
455 if (via->rport && via->rport->value.s){
456 LM_DBG("using 'rport'\n");
457 port=str2s(via->rport->value.s, via->rport->value.len, &err);
458 if (err){
459 LM_NOTICE("bad rport value(%.*s)\n",
460 via->rport->value.len,via->rport->value.s);
461 port=0;
462 }
463 }
464
465 if (via->maddr){
466 name= &(via->maddr->value);
467 if (port==0) port=via->port?via->port:SIP_PORT;
468 } else if (via->received){
469 LM_DBG("using 'received'\n");
470 name=&(via->received->value);
471 /* making sure that we won't do SRV lookup on "received" */
472 if (port==0) port=via->port?via->port:SIP_PORT;
473 }else{
474 LM_DBG("using via host\n");
475 name=&(via->host);
476 if (port==0) port=via->port;
477 }
478 }
479 LM_DBG("trying SRV lookup\n");
480 he=sip_resolvehost(name, &port, &via->proto, 0, 0);
481
482 if (he==0){
483 LM_NOTICE("resolve_host(%.*s) failure\n", name->len, name->s);
484 return -1;
485 }
486
487 hostent2su( to, he, 0, port);
488 return 1;

Callers 4

forward_replyFunction · 0.85
sl_send_reply_helperFunction · 0.85
force_rtpproxy_body_partFunction · 0.85
init_rbFunction · 0.85

Calls 3

str2sFunction · 0.85
sip_resolvehostFunction · 0.85
hostent2suFunction · 0.85

Tested by

no test coverage detected