summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--channels/sip/config_parser.c12
-rw-r--r--configs/sip.conf.sample4
-rw-r--r--include/asterisk/netsock2.h20
-rw-r--r--main/netsock2.c6
4 files changed, 34 insertions, 8 deletions
diff --git a/channels/sip/config_parser.c b/channels/sip/config_parser.c
index 659e8cecc..0ab9ed769 100644
--- a/channels/sip/config_parser.c
+++ b/channels/sip/config_parser.c
@@ -661,16 +661,18 @@ int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum s
else
line = *hostname;
- if ((port = strrchr(line, ':'))) {
- *port++ = '\0';
+ if (ast_sockaddr_split_hostport(line, hostname, &port, 0) == 0) {
+ ast_log(LOG_WARNING, "Cannot parse host '%s' on line %d of sip.conf.\n",
+ line, lineno);
+ return -1;
+ }
+ if (port) {
if (!sscanf(port, "%5u", portnum)) {
ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno);
port = NULL;
}
- }
-
- if (!port) {
+ } else {
if (*transport & SIP_TRANSPORT_TLS) {
*portnum = STANDARD_TLS_PORT;
} else {
diff --git a/configs/sip.conf.sample b/configs/sip.conf.sample
index c61e8787c..44ef9aa1a 100644
--- a/configs/sip.conf.sample
+++ b/configs/sip.conf.sample
@@ -367,6 +367,10 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
;outboundproxy=proxy.provider.domain:8080 ; send outbound signaling to this proxy, not directly to the devices
;outboundproxy=proxy.provider.domain,force ; Send ALL outbound signalling to proxy, ignoring route: headers
;outboundproxy=tls://proxy.provider.domain ; same as '=proxy.provider.domain' except we try to connect with tls
+;outboundproxy=192.0.2.1 ; IPv4 address literal (default port is 5060)
+;outboundproxy=2001:db8::1 ; IPv6 address literal (default port is 5060)
+;outboundproxy=192.168.0.2.1:5062 ; IPv4 address literal with explicit port
+;outboundproxy=[2001:db8::1]:5062 ; IPv6 address literal with explicit port
; ; (could also be tcp,udp) - defining transports on the proxy line only
; ; applies for the global proxy, otherwise use the transport= option
;matchexternaddrlocally = yes ; Only substitute the externaddr or externhost setting if it matches
diff --git a/include/asterisk/netsock2.h b/include/asterisk/netsock2.h
index 24330d236..73c57c5d2 100644
--- a/include/asterisk/netsock2.h
+++ b/include/asterisk/netsock2.h
@@ -233,6 +233,26 @@ static inline char *ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
* \since 1.8
*
* \brief
+ * Splits a string into its host and port components
+ *
+ * \param str[in] The string to parse. May be modified by writing a NUL at the end of
+ * the host part.
+ * \param host[out] Pointer to the host component within \a str.
+ * \param port[out] Pointer to the port component within \a str.
+ * \param flags If set to zero, a port MAY be present. If set to PARSE_PORT_IGNORE, a
+ * port MAY be present but will be ignored. If set to PARSE_PORT_REQUIRE,
+ * a port MUST be present. If set to PARSE_PORT_FORBID, a port MUST NOT
+ * be present.
+ *
+ * \retval 1 Success
+ * \retval 0 Failure
+ */
+int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags);
+
+/*!
+ * \since 1.8
+ *
+ * \brief
* Parse an IPv4 or IPv6 address string.
*
* \details
diff --git a/main/netsock2.c b/main/netsock2.c
index 929f4b337..932ca57c2 100644
--- a/main/netsock2.c
+++ b/main/netsock2.c
@@ -118,7 +118,7 @@ char *ast_sockaddr_stringify_fmt(const struct ast_sockaddr *sa, int format)
return ast_str_buffer(str);
}
-int static _ast_sockaddr_parse(char *str, char **host, char **port, int flags)
+int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
{
char *s = str;
@@ -187,7 +187,7 @@ int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
int e;
s = ast_strdupa(str);
- if (!_ast_sockaddr_parse(s, &host, &port, flags)) {
+ if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
return 0;
}
@@ -233,7 +233,7 @@ int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str,
int e, i, res_cnt;
s = ast_strdupa(str);
- if (!_ast_sockaddr_parse(s, &host, &port, flags)) {
+ if (!ast_sockaddr_split_hostport(s, &host, &port, flags)) {
return 0;
}