Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#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:
Backport to 1.x milestone: Backported:

Description (last modified by bennylp)

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 (6)

comment:1 follow-up: Changed 15 years ago by bennylp

Done in r2873

comment:2 in reply to: ↑ 1 Changed 15 years ago by bennylp

Replying to bennylp:

Done in r2873

This should read r2743

comment:3 Changed 15 years ago by bennylp

  • Resolution set to fixed
  • Status changed from new to closed

In r2744:

  • updated PJSUA-LIB to use the new API

comment:4 Changed 15 years ago by bennylp

  • Milestone changed from release-1.4 to release-1.3

comment:5 Changed 15 years ago by bennylp

  • Description modified (diff)

comment:6 Changed 15 years ago by bennylp

In r2770:

  • pj_sockaddr_parse() is unable to parse "localhost" on Symbian, so disable the test in pjlib-test for Symbian
Note: See TracTickets for help on using tickets.