Ticket #878 (closed enhancement: fixed)
New PJLIB API to parse socket address string
| Reported by: | bennylp | Owned by: | bennylp |
|---|---|---|---|
| Priority: | normal | Milestone: | release-1.3 |
| Component: | pjlib | Version: | trunk |
| Keywords: | Cc: |
Description (last modified by bennylp) (diff)
New PJLIB API to parse string containing socket address (IP address and optional port):
PJ_DECL(pj_status_t) pj_sockaddr_parse(int af, unsigned options, const pj_str_t *str, pj_sockaddr *addr);
This function supports parsing several formats. Sample IPv4 inputs and their default results::
- "10.0.0.1:80": address 10.0.0.1 and port 80.
- "10.0.0.1": address 10.0.0.1 and port zero.
- "10.0.0.1:": address 10.0.0.1 and port zero.
- "10.0.0.1:0": address 10.0.0.1 and port zero.
- ":80": address 0.0.0.0 and port 80.
- ":": address 0.0.0.0 and port 0.
This will also work if host resolution is enabled (i.e. gethostbyname() works):
- "localhost": address 127.0.0.1 and port 0.
- "localhost:": address 127.0.0.1 and port 0.
- "localhost:80": address 127.0.0.1 and port 80.
Sample IPv6 inputs and their default results:
- "[fec0::01]:80": address fec0::01 and port 80
- "[fec0::01]": address fec0::01 and port 0
- "[fec0::01]:": address fec0::01 and port 0
- "[fec0::01]:0": address fec0::01 and port 0
- "fec0::01": address fec0::01 and port 0
- "fec0::01:80": address fec0::01:80 and port 0
- "::": address zero (::) and port 0
- "[::]": address zero (::) and port 0
- "[::]:": address zero (::) and port 0
- ":::": address zero (::) and port 0
- "[::]:80": address zero (::) and port 0
- ":::80": address zero (::) and port 80
Note: when the IPv6 socket address contains port number, the IP part of the socket address should be enclosed with square brackets, otherwise the port number will be included as part of the IP address (see "fec0::01:80" example above).
Change History
Note: See
TracTickets for help on using
tickets.
![(please configure the [header_logo] section in trac.ini)](/repos/chrome/site/pj.jpg)