diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2010-11-24 08:30:47 -0800 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2010-11-24 08:30:47 -0800 |
commit | 50eef01259415a59067de542a21f30f6f4b829d0 (patch) | |
tree | 0f7daf78e6bd8c84dbf88a7ec8a57adf5db5f2ed /sockets.c | |
parent | 3a21de8e50f7c4a3dae578ee428f9aad363183c0 (diff) | |
download | external_qemu-50eef01259415a59067de542a21f30f6f4b829d0.zip external_qemu-50eef01259415a59067de542a21f30f6f4b829d0.tar.gz external_qemu-50eef01259415a59067de542a21f30f6f4b829d0.tar.bz2 |
Implement sock_address_list_create2 routine.
This routine takes socket address in the form of [host:]port and creates array of SockAddress for it.
Change-Id: Ib2d4c1035d109d9d3df100961c4eec728d15e485
Diffstat (limited to 'sockets.c')
-rw-r--r-- | sockets.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -802,6 +802,33 @@ sock_address_list_create( const char* hostname, return list; } +SockAddress** +sock_address_list_create2(const char* host_and_port, unsigned flags ) +{ + char host_name[512]; + const char* actual_host_name = "localhost"; + // Parse host and port name. + const char* port_name = strchr(host_and_port, ':'); + if (port_name != NULL) { + int to_copy = MIN(sizeof(host_name)-1, port_name - host_and_port); + if (to_copy != 0) { + memcpy(host_name, host_and_port, to_copy); + host_name[to_copy] = '\0'; + actual_host_name = host_name; + port_name++; + } else { + return NULL; + } + } else { + port_name = host_and_port; + } + // Make sure that port_name is not empty. + if (port_name[0] == '\0') { + return NULL; + } + return sock_address_list_create(actual_host_name, port_name, flags); +} + void sock_address_list_free( SockAddress** list ) { |