diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index d9a97fcfa49d7e6bcc3c4b4234eccb3a26d2034c..ad6e00ab2c155ca31d1df3025741245f6e038e68 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -2881,7 +2881,24 @@ static int find_sip_method(const char *msg)
 /*! \brief See if we pass debug IP filter */
 static inline int sip_debug_test_addr(const struct ast_sockaddr *addr)
 {
-	return sipdebug && !ast_sockaddr_isnull(addr) && !ast_sockaddr_cmp_addr(&debugaddr, addr);
+	/* Can't debug if sipdebug is not enabled */
+	if (!sipdebug) {
+		return 0;
+	}
+
+	/* A null debug_addr means we'll debug any address */
+	if (ast_sockaddr_isnull(&debugaddr)) {
+		return 1;
+	}
+
+	/* If no port was specified for a debug address, just compare the
+	 * addresses, otherwise compare the address and port
+	 */
+	if (ast_sockaddr_port(&debugaddr)) {
+		return !ast_sockaddr_cmp(&debugaddr, addr);
+	} else {
+		return !ast_sockaddr_cmp_addr(&debugaddr, addr);
+	}
 }
 
 /*! \brief The real destination address for a write */