Lately we have been getting complaints that database mirroring setup on few of our client's site were failing with TCP related errors. For more information these sites are involved within the firewall setup and active directory too.
Initial workaround is to add a Server name & port record in both networks DNS servers or add both SQL servers IP addresses in local hosts files (e.g. C:\Windows\System32\Drivers\Etc\hosts). I would like to refer the MSDN article for a detailed information on "How to: Configure a Firewall for SQL Server Access http://msdn2.microsoft.com/en-us/library/ms175043.aspx" link. Even then we have had issues in getting port numbers and last resort for me to check whether relevant TCP port numbers for endpoints are enabled in the firewall setup and I was under impression that by querying sys.database_mirroring_endpoints catalog, but it isn't the case. I found that they are in sys.tcp_endpoints catalog view and further a query can be written to join sys.database_mirroring_endpoints and sys.tcp_endpoints to get the important metadata information regarding the endpoints:
SELECT e.name, e.protocol_desc, e.type_desc, e.role_desc, e.state_desc,
t.port, e.is_encryption_enabled, e.encryption_algorithm_desc,
e.connection_auth_desc
FROM sys.database_mirroring_endpoints e JOIN sys.tcp_endpoints t
ON e.endpoint_id = t.endpoint_id
Read the complete post at http://sqlserver-qa.net/blogs/ha/archive/2007/09/13/sql-server-database-mirroring-error-with-tcp-port-numbers-firewall-involvement.aspx