mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-09 18:44:58 -06:00
Change net/socket.c to use socket_*() functions
Use socket_*() functions from include/qemu/sockets.h instead of listen()/bind()/connect()/parse_host_port(). socket_*() fucntions are QAPI based and this patch performs this api conversion since everything will be using QAPI based sockets in the future. Also add a helper function socket_address_to_string() in util/qemu-sockets.c which returns the string representation of socket address. Thetask was listed on http://wiki.qemu.org/BiteSizedTasks page. Signed-off-by: Ashijeet Acharya <ashijeetacharya@gmail.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
parent
d88d3a0938
commit
7e8449594c
3 changed files with 78 additions and 29 deletions
|
@ -1151,3 +1151,39 @@ void qapi_copy_SocketAddress(SocketAddress **p_dest,
|
|||
qmp_input_visitor_cleanup(qiv);
|
||||
qobject_decref(obj);
|
||||
}
|
||||
|
||||
char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
|
||||
{
|
||||
char *buf;
|
||||
InetSocketAddress *inet;
|
||||
char host_port[INET6_ADDRSTRLEN + 5 + 4];
|
||||
|
||||
switch (addr->type) {
|
||||
case SOCKET_ADDRESS_KIND_INET:
|
||||
inet = addr->u.inet.data;
|
||||
if (strchr(inet->host, ':') == NULL) {
|
||||
snprintf(host_port, sizeof(host_port), "%s:%s", inet->host,
|
||||
inet->port);
|
||||
buf = g_strdup(host_port);
|
||||
} else {
|
||||
snprintf(host_port, sizeof(host_port), "[%s]:%s", inet->host,
|
||||
inet->port);
|
||||
buf = g_strdup(host_port);
|
||||
}
|
||||
break;
|
||||
|
||||
case SOCKET_ADDRESS_KIND_UNIX:
|
||||
buf = g_strdup(addr->u.q_unix.data->path);
|
||||
break;
|
||||
|
||||
case SOCKET_ADDRESS_KIND_FD:
|
||||
buf = g_strdup(addr->u.fd.data->str);
|
||||
break;
|
||||
|
||||
default:
|
||||
error_setg(errp, "socket family %d unsupported",
|
||||
addr->type);
|
||||
return NULL;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue