pingpong: fix compiler warnings

This commit is contained in:
Christian Helmuth 2013-09-04 11:27:22 +02:00
parent 989e880c69
commit 8707771d35
8 changed files with 18 additions and 33 deletions

View File

@ -2,7 +2,5 @@ TARGET = test-ping_client_libc_lwip
LIBS = base libc libc_lwip lwip libc_lwip_nic_dhcp libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT_main += -fpermissive
vpath main.cc $(PRG_DIR)/..
vpath pingpong.cc $(PRG_DIR)/../..

View File

@ -2,8 +2,6 @@ TARGET = test-ping_client_lwip
LIBS = base libc lwip libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT_main += -fpermissive
INC_DIR += $(REP_DIR)/src/lib/lwip/include
vpath main.cc $(PRG_DIR)/..

View File

@ -48,12 +48,12 @@ dial(const char *addr)
}
int
sendping(const char *addr, size_t dsize, int count)
sendping(const char *addr, size_t dsize, size_t count)
{
Packet p;
int s;
size_t i;
ssize_t n;
size_t n = 0;
s = dial(addr);
if (s == -1)
@ -67,12 +67,12 @@ sendping(const char *addr, size_t dsize, int count)
return -1;
}
printf("Trying to send %d packets...\n", count);
printf("Trying to send %zd packets...\n", count);
for (i = 0; i < count; i++) {
forgepacket(&p, i + 1);
n = sendpacket(s, &p);
if (n <= 0)
if (n == 0)
break;
if (n != (sizeof (Packetheader) + p.h.dsize)) {
printf("ERROR: size mismatch: %ld != %lu\n", n, sizeof (Packetheader) + p.h.dsize);
@ -88,15 +88,11 @@ sendping(const char *addr, size_t dsize, int count)
switch (n) {
case 0:
printf("Disconnect, sent packets: %lu\n", i);
printf("Disconnect, sent packets: %zu\n", i);
return 0;
break;
case -1:
printf("Error, sent packets: %lu\n", i);
return 1;
break;
default:
printf("Sucessful, sent packets: %lu\n", i);
printf("Sucessfull, sent packets: %zu\n", i);
return 0;
break;
}

View File

@ -44,7 +44,7 @@ checkpacket(size_t n, Packet *p)
}
/* check payload */
if (p->d[p->h.dsize - 1] != (p->h.id % 128)) {
if (p->d[p->h.dsize - 1] != (char)(p->h.id % 128)) {
printf("ERROR: packet payload corrupt, expected: %d got: %d\n", (p->h.id % 128),
p->d[p->h.dsize - 1]);
return -1;
@ -53,12 +53,12 @@ checkpacket(size_t n, Packet *p)
return 0;
}
ssize_t
size_t
sendpacket(int s, Packet *p)
{
char *b;
ssize_t sent, nd, nh;
size_t dsize;
ssize_t sent;
size_t nd, nh, dsize;
/* send packet header */
b = (char *)&p->h;
@ -102,12 +102,12 @@ sendpacket(int s, Packet *p)
return nh + nd;
}
ssize_t
size_t
recvpacket(int s, Packet *p, char *dbuf, size_t ldbuf)
{
char *b;
ssize_t r, nd, nh;
size_t dsize;
ssize_t r;
size_t nd, nh, dsize;
/* recv packet header */
b = (char *)&p->h;

View File

@ -68,7 +68,7 @@ struct Packet
void forgepacket(Packet *, uint32_t);
int checkpacket(size_t, Packet *);
ssize_t sendpacket(int, Packet *);
ssize_t recvpacket(int, Packet *, char *, size_t);
size_t sendpacket(int, Packet *);
size_t recvpacket(int, Packet *, char *, size_t);
#endif /* _PINGPONG_H_ */

View File

@ -2,7 +2,5 @@ TARGET = test-ping_server_libc_lwip
LIBS = base libc libc_lwip_nic_dhcp libc_lwip lwip libc_log config_args
SRC_CC = main.cc pingpong.cc
CC_OPT_main += -fpermissive
vpath main.cc $(PRG_DIR)/..
vpath pingpong.cc $(PRG_DIR)/../..

View File

@ -4,8 +4,6 @@ SRC_CC = main.cc pingpong.cc
CC_OPT += -DLWIP_NATIVE
CC_OPT_main += -fpermissive
INC_DIR += $(REP_DIR)/src/lib/lwip/include
vpath main.cc $(PRG_DIR)/..

View File

@ -103,9 +103,6 @@ recvping(const char *addr)
n = recvpacket(c, &p, p.d, Databuf);
switch (n) {
case -1:
/* error */
printf("ERROR: recvpacket() == -1\n");
case 0:
/* disconnect */
//printf("ERROR: disconnect\n");
@ -113,7 +110,7 @@ recvping(const char *addr)
act = 0;
break;
default:
/* check if packet is vaid */
/* check if packet is valid */
if (checkpacket(n, &p)) {
act = 0;
} else {
@ -124,9 +121,9 @@ recvping(const char *addr)
}
if (verbose)
printf("%u %d\n", p.h.id, n);
printf("%u %zd\n", p.h.id, n);
}
printf("received %u packets of size %u\n", packets, packet_size);
printf("received %zu packets of size %zu\n", packets, packet_size);
free(p.d);
}