18

Under IPv4, the de facto standard notation 10.1.2.3:1234 is completely clear: it is an IP address with port number. This is understood in URL's for instance: http://10.1.2.3:1234/doc.xhtml.

If I have a sockaddr_ipv4 class in some code, its tostring method can return this colon notation and everything is cool.

In a fit of myopia, the designers for the IPv6 addresses numeric notation decided that the colon character was available for their use as a separator. As a result, a colon-delimited port number looks ambiguous on an IPv6 address.

How can we incorporate a port number into a printed representation of an IPv6 address-with-port? Is there some de facto standard way?

Kaz
  • 3,692

1 Answers1

26

The common way of doing this is to enclose the IPv6 address in square brackets like this:

[2001:db8::1]:8080

This is what is being used in URLs for example:

http://[2001:db8::1]:8080/