change TCP port datatype from int to uint16_t

because int doesn't match the range
add range check in every TCP binary
This commit is contained in:
Stefan Wahren
2013-05-12 21:26:38 +02:00
parent b0dff87093
commit 4d85dad403
19 changed files with 96 additions and 50 deletions

View File

@ -54,32 +54,33 @@ main(int argc, char **argv)
{
mbus_handle *handle;
char *host;
int port, address, retries = 0;
int address, retries = 0;
long port;
int ret;
if (argc == 3)
{
host = argv[1];
port = atoi(argv[2]);
port = atol(argv[2]);
}
else if (argc == 4 && strcmp(argv[1], "-d") == 0)
{
debug = 1;
host = argv[2];
port = atoi(argv[3]);
port = atol(argv[3]);
}
else if (argc == 5 && strcmp(argv[1], "-r") == 0)
{
retries = atoi(argv[2]);
host = argv[3];
port = atoi(argv[4]);
port = atol(argv[4]);
}
else if (argc == 6 && strcmp(argv[1], "-d") == 0 && strcmp(argv[2], "-r") == 0)
{
debug = 1;
retries = atoi(argv[3]);
host = argv[4];
port = atoi(argv[5]);
port = atol(argv[5]);
}
else
{
@ -87,6 +88,12 @@ main(int argc, char **argv)
return 0;
}
if ((port < 0) || (port > 0xFFFF))
{
fprintf(stderr, "Invalid port: %ld\n", port);
return 1;
}
if (debug)
{
mbus_register_send_event(&mbus_dump_send_event);