[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 7/9] net: introduce parse_host_port_info()
From: |
Amos Kong |
Subject: |
[Qemu-devel] [PATCH v3 7/9] net: introduce parse_host_port_info() |
Date: |
Wed, 07 Mar 2012 06:48:39 +0800 |
User-agent: |
StGit/0.15 |
int parse_host_port(struct sockaddr_in *saddr, const char *str)
Parsed address info will be restored into 'saddr', it only support ipv4.
This function is used by net_socket_mcast_init() and net_socket_udp_init().
int parse_host_port_info(struct addrinfo *result, const char *str)
Parsed address info will be restored into 'result', it's an address list.
It can be used to parse IPv6 address/port.
Signed-off-by: Amos Kong <address@hidden>
---
net.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/net.c b/net.c
index de1db8c..2518e5f 100644
--- a/net.c
+++ b/net.c
@@ -130,18 +130,15 @@ static int tcp_client_connect(int fd, struct addrinfo *rp)
return ret;
}
-static int tcp_start_common(const char *str, int *fd, bool server)
+static int parse_host_port_info(struct addrinfo **result, const char *str,
+ bool server)
{
char hostname[512];
const char *service;
const char *name;
struct addrinfo hints;
- struct addrinfo *result, *rp;
int s;
- int sfd;
- int ret = -EINVAL;
- *fd = -1;
service = str;
if (get_str_sep(hostname, sizeof(hostname), &service, ':') < 0) {
@@ -164,12 +161,29 @@ static int tcp_start_common(const char *str, int *fd,
bool server)
hints.ai_flags = AI_PASSIVE;
}
- s = getaddrinfo(name, service, &hints, &result);
+ s = getaddrinfo(name, service, &hints, result);
if (s != 0) {
error_report("qemu: getaddrinfo: %s", gai_strerror(s));
return -EINVAL;
}
+ return 0;
+}
+
+static int tcp_start_common(const char *str, int *fd, bool server)
+{
+ struct addrinfo *rp;
+ int sfd;
+ int ret = -EINVAL;
+ struct addrinfo *result;
+
+ *fd = -1;
+
+ ret = parse_host_port_info(&result, str, server);
+ if (ret < 0) {
+ return -EINVAL;
+ }
+
/* getaddrinfo() returns a list of address structures.
Try each address until we successfully bind/connect).
If socket(2) (or bind/connect(2)) fails, we (close the socket
- Re: [Qemu-devel] [PATCH v3 1/9] net: introduce tcp_server_start(), (continued)
- [Qemu-devel] [PATCH v3 4/9] net: use tcp_client_start for tcp client creation, Amos Kong, 2012/03/06
- [Qemu-devel] [PATCH v3 6/9] net: use getaddrinfo() in tcp_start_common, Amos Kong, 2012/03/06
- [Qemu-devel] [PATCH v3 7/9] net: introduce parse_host_port_info(),
Amos Kong <=
- [Qemu-devel] [PATCH v3 5/9] net: refector tcp_*_start functions, Amos Kong, 2012/03/06
- [Qemu-devel] [PATCH v3 8/9] net: split hostname and service by last colon, Amos Kong, 2012/03/06
- [Qemu-devel] [PATCH v3 9/9] net: support to include ipv6 address by brackets, Amos Kong, 2012/03/06