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

Function ospConvertToOutAddress

modules/osp/destination.c:561–594  ·  view source on GitHub ↗

* Convert "address:port" to "[x.x.x.x]:port" or "hostname:port" format * param src Source address string * param dest Destination address string * param bufsize Size of dest buffer */

Source from the content-addressed store, hash-verified

559 * param bufsize Size of dest buffer
560 */
561void ospConvertToOutAddress(
562 const char* src,
563 char* dest,
564 int bufsize)
565{
566 struct in_addr inp;
567 char buffer[OSP_STRBUF_SIZE];
568 char* port;
569 int size;
570
571 if ((src != NULL) && (*src != '\0')) {
572 size = sizeof(buffer);
573 strncpy(buffer, src, size);
574 buffer[size - 1] = '\0';
575
576 if((port = strchr(buffer, ':')) != NULL) {
577 *port = '\0';
578 port++;
579 }
580
581 if (inet_pton(AF_INET, buffer, &inp) == 1) {
582 if (port != NULL) {
583 snprintf(dest, bufsize, "[%s]:%s", buffer, port);
584 } else {
585 snprintf(dest, bufsize, "[%s]", buffer);
586 }
587 } else {
588 strncpy(dest, src, bufsize);
589 dest[bufsize - 1] = '\0';
590 }
591 } else {
592 *dest = '\0';
593 }
594}
595
596/*
597 * Convert "[x.x.x.x]:port" or "hostname:prot" to "address:port" format

Callers 4

ospReportUsageFromCookieFunction · 0.85
ospRequestRoutingFunction · 0.85
ospVerifyParametersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected