diff options
author | Alon Levy <alevy@redhat.com> | 2011-01-28 11:00:10 +0200 |
---|---|---|
committer | Alon Levy <alevy@redhat.com> | 2011-02-03 16:54:27 +0200 |
commit | 278aad9f849e4a606d28c846f796967cc1940797 (patch) | |
tree | ef14c51f4cc21779807ab0513f36187ae450d839 | |
parent | c9823c549f7dd2853423fa970551cfce31865916 (diff) |
vscclient: VSCMsgReconnect changed to have two strings
-rw-r--r-- | vscclient.c | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/vscclient.c b/vscclient.c index 4dd8a35..41e44aa 100644 --- a/vscclient.c +++ b/vscclient.c @@ -47,17 +47,6 @@ print_usage (void) { vcard_emul_usage(); } -static char* -ip_numeric_to_char( - uint32_t ip -) { - char buf[4*4]; - - sprintf(buf, "%d.%d.%d.%d", (ip & 0xff000000) >> 24, (ip & 0xff0000) >> 16, - (ip & 0xff00) >> 8, ip & 0xff); - return strdup(buf); -} - static mutex_t write_lock; static int @@ -381,13 +370,12 @@ do_command(void) static int connect_to_qemu ( - const char *ip, - uint32_t port + const char *host, + const char *port ) { struct addrinfo hints; struct addrinfo* server; int ret; - char port_str[10]; sock = socket ( AF_INET, @@ -400,13 +388,12 @@ connect_to_qemu ( } memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_INET; + hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = 0; hints.ai_protocol = 0; /* Any protocol */ - snprintf(port_str, sizeof(port_str) - 1, "%d", port); - ret = getaddrinfo(ip, port_str, &hints, &server); + ret = getaddrinfo(host, port, &hints, &server); if (ret != 0) { printf ("getaddrinfo failed\n"); @@ -434,8 +421,8 @@ main ( int argc, char *argv[] ) { - char* qemu_ip; - uint16_t qemu_port; + char* qemu_host; + char* qemu_port; VSCMsgHeader mhHeader; VSCMsgError *error_msg; @@ -520,9 +507,9 @@ main ( vcard_emul_options(emul_args); } - qemu_ip = strdup(argv[argc - 2]); - qemu_port = (uint16_t)atoi(argv[argc -1]); - sock = connect_to_qemu(qemu_ip, qemu_port); + qemu_host = strdup(argv[argc - 2]); + qemu_port = strdup(argv[argc -1]); + sock = connect_to_qemu(qemu_host, qemu_port); /* remove whatever reader might be left in qemu, * in case of a unclean previous exit. */ @@ -653,21 +640,26 @@ main ( close (sock); return (8); } - if (reconnect.ip != 0) { - reconnect.ip = ntohl(reconnect.ip); - free(qemu_ip); - qemu_ip = ip_numeric_to_char(reconnect.ip); - qemu_port = reconnect.port; + if (reconnect.host[0] != 0) { + free(qemu_host); + free(qemu_port); + qemu_host = strdup(reconnect.host); + qemu_port = strdup(reconnect.port); } else { printf("info: reconnect with no target ip:port: " "bumping port by one and reconnecting\n"); - qemu_port = qemu_port + 1; + char buf[100]; + uint32_t port = atoi(qemu_port); + snprintf(buf, sizeof(buf), "%d", port+1); + buf[sizeof(buf)-1] = 0; + free(qemu_port); + qemu_port = strdup(buf); } /* sent when qemu is migrating, we need to close the socket * and reconnect. */ close(sock); - printf("reconnecting to %s:%d\n", qemu_ip, qemu_port); - sock = connect_to_qemu(qemu_ip, qemu_port); + printf("reconnecting to %s:%s\n", qemu_host, qemu_port); + sock = connect_to_qemu(qemu_host, qemu_port); } break; case VSC_ReaderAddResponse: |