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

Function ospGetViaAddress

modules/osp/sipheader.c:1114–1150  ·  view source on GitHub ↗

* Get first VIA header and use the IP or host name * param msg SIP message * param viaaddr Via header IP address * param bufsize Size of viaaddr * return 0 success, -1 failure */

Source from the content-addressed store, hash-verified

1112 * return 0 success, -1 failure
1113 */
1114int ospGetViaAddress(
1115 struct sip_msg* msg,
1116 char* viaaddr,
1117 int bufsize)
1118{
1119 struct hdr_field* hf;
1120 struct via_body* via;
1121 int result = -1;
1122
1123 if ((viaaddr != NULL) && (bufsize > 0)) {
1124 /*
1125 * No need to call parse_headers, called already and VIA is parsed
1126 * anyway by default
1127 */
1128 for (hf = msg->headers; hf; hf = hf->next) {
1129 if (hf->type == HDR_VIA_T) {
1130 /* found first VIA */
1131 via = (struct via_body*)hf->parsed;
1132
1133 if (via->port != 0) {
1134 snprintf(viaaddr, bufsize, "%.*s:%d", via->host.len, via->host.s, via->port);
1135 } else {
1136 ospCopyStrToBuffer(&via->host, viaaddr, bufsize);
1137 }
1138
1139 LM_DBG("via address '%s'\n", viaaddr);
1140
1141 result = 0;
1142 break;
1143 }
1144 }
1145 } else {
1146 LM_ERR("bad parameters to parse host from VIA header\n");
1147 }
1148
1149 return result;
1150}
1151
1152/*
1153 * Get source device IP address

Callers 4

ospReportUsageFromCookieFunction · 0.85
ospValidateHeaderFunction · 0.85
ospGetSrcDevFunction · 0.85
ospGetSourceFunction · 0.85

Calls 1

ospCopyStrToBufferFunction · 0.85

Tested by

no test coverage detected