mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
remote: Fix incorrect handling of port
option
The `port` option is converted from unsigned short integer to network byte order twice. Unfortunately the 2nd conversion reverses the 1st one. Example: #include <stdio.h> #include <arpa/inet.h> #include <stdlib.h> int main() { printf("%d\n", htons(atoi("1234"))); /* 53764 */ printf("%d\n", htons(htons(atoi("1234")))); /* 1234 */ return 0; } Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
This commit is contained in:
committed by
Andrei Vagin
parent
347f210893
commit
0ea9dd99c5
@@ -377,7 +377,7 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
|
||||
}
|
||||
|
||||
if (req->ps) {
|
||||
opts.port = htons((short)req->ps->port);
|
||||
opts.port = (short)req->ps->port;
|
||||
|
||||
if (!opts.lazy_pages) {
|
||||
opts.use_page_server = true;
|
||||
|
@@ -719,7 +719,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
opts.addr = optarg;
|
||||
break;
|
||||
case 1052:
|
||||
opts.port = htons(atoi(optarg));
|
||||
opts.port = atoi(optarg);
|
||||
if (!opts.port)
|
||||
goto bad_arg;
|
||||
break;
|
||||
|
@@ -1077,7 +1077,7 @@ int disconnect_from_page_server(void)
|
||||
return 0;
|
||||
|
||||
pr_info("Disconnect from the page server %s:%u\n",
|
||||
opts.addr, (int)ntohs(opts.port));
|
||||
opts.addr, opts.port);
|
||||
|
||||
if (opts.ps_socket != -1)
|
||||
/*
|
||||
|
@@ -1275,7 +1275,7 @@ static int get_sockaddr_in(struct sockaddr_in *addr, char *host)
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr->sin_port = opts.port;
|
||||
addr->sin_port = htons(opts.port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1285,7 +1285,7 @@ int setup_tcp_server(char *type)
|
||||
struct sockaddr_in saddr;
|
||||
socklen_t slen = sizeof(saddr);
|
||||
|
||||
pr_info("Starting %s server on port %u\n", type, (int)ntohs(opts.port));
|
||||
pr_info("Starting %s server on port %u\n", type, opts.port);
|
||||
|
||||
sk = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sk < 0) {
|
||||
@@ -1375,7 +1375,7 @@ int setup_tcp_client(char *addr)
|
||||
struct sockaddr_in saddr;
|
||||
int sk;
|
||||
|
||||
pr_info("Connecting to server %s:%u\n", addr, (int)ntohs(opts.port));
|
||||
pr_info("Connecting to server %s:%u\n", addr, opts.port);
|
||||
|
||||
if (get_sockaddr_in(&saddr, addr))
|
||||
return -1;
|
||||
|
Reference in New Issue
Block a user