netutils/netcat: fixed ISO C89/C90 related warnings:
warning: ISO C90 forbids variable length array ‘buf’ [-Wvla] warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
This commit is contained in:
parent
8f1948038e
commit
5a697c18ba
@ -44,18 +44,23 @@
|
|||||||
# define NETCAT_PORT 31337
|
# define NETCAT_PORT 31337
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NETCAT_IOBUF_SIZE
|
||||||
|
# define NETCAT_IOBUF_SIZE 256
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int do_io(int infd, int outfd)
|
int do_io(int infd, int outfd)
|
||||||
{
|
{
|
||||||
size_t capacity = 256;
|
ssize_t avail;
|
||||||
char buf[capacity];
|
ssize_t written;
|
||||||
|
char buf[NETCAT_IOBUF_SIZE];
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
ssize_t avail = read(infd, buf, capacity);
|
avail = read(infd, buf, NETCAT_IOBUF_SIZE);
|
||||||
if (avail == 0)
|
if (avail == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
@ -67,7 +72,7 @@ int do_io(int infd, int outfd)
|
|||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t written = write(outfd, buf, avail);
|
written = write(outfd, buf, avail);
|
||||||
if (written == -1)
|
if (written == -1)
|
||||||
{
|
{
|
||||||
perror("do_io: write error");
|
perror("do_io: write error");
|
||||||
@ -113,6 +118,8 @@ int netcat_server(int argc, char * argv[])
|
|||||||
struct sockaddr_in client;
|
struct sockaddr_in client;
|
||||||
int port = NETCAT_PORT;
|
int port = NETCAT_PORT;
|
||||||
int result = EXIT_SUCCESS;
|
int result = EXIT_SUCCESS;
|
||||||
|
int conn;
|
||||||
|
socklen_t addrlen;
|
||||||
|
|
||||||
if ((1 < argc) && (0 == strcmp("-l", argv[1])))
|
if ((1 < argc) && (0 == strcmp("-l", argv[1])))
|
||||||
{
|
{
|
||||||
@ -160,8 +167,6 @@ int netcat_server(int argc, char * argv[])
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
socklen_t addrlen;
|
|
||||||
int conn;
|
|
||||||
if ((conn = accept(id, (struct sockaddr *)&client, &addrlen)) != -1)
|
if ((conn = accept(id, (struct sockaddr *)&client, &addrlen)) != -1)
|
||||||
{
|
{
|
||||||
result = do_io(conn, outfd);
|
result = do_io(conn, outfd);
|
||||||
@ -195,6 +200,7 @@ int netcat_client(int argc, char * argv[])
|
|||||||
char *host = "127.0.0.1";
|
char *host = "127.0.0.1";
|
||||||
int port = NETCAT_PORT;
|
int port = NETCAT_PORT;
|
||||||
int result = EXIT_SUCCESS;
|
int result = EXIT_SUCCESS;
|
||||||
|
struct sockaddr_in server;
|
||||||
#ifdef CONFIG_NETUTILS_NETCAT_SENDFILE
|
#ifdef CONFIG_NETUTILS_NETCAT_SENDFILE
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
#endif
|
#endif
|
||||||
@ -239,7 +245,6 @@ int netcat_client(int argc, char * argv[])
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_in server;
|
|
||||||
server.sin_family = AF_INET;
|
server.sin_family = AF_INET;
|
||||||
server.sin_port = htons(port);
|
server.sin_port = htons(port);
|
||||||
if (1 != inet_pton(AF_INET, host, &server.sin_addr))
|
if (1 != inet_pton(AF_INET, host, &server.sin_addr))
|
||||||
|
Loading…
Reference in New Issue
Block a user