From 1b37baf6568e37d52601231c45e6394a3d0ff55b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 21 Jul 2008 03:06:07 +0000 Subject: Use the sreadfrom() wrapper to replace recvfrom() in our code. --- CHANGES | 3 +++ ares/setup_once.h | 7 +++++++ lib/setup_once.h | 7 +++++++ lib/tftp.c | 14 +++++++------- tests/server/tftpd.c | 16 +++++++--------- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index 841d2c0d6..4c0c2dc2f 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ Changelog +Yang Tse (21 Jul 2008) +- Use the sreadfrom() wrapper to replace recvfrom() in our code. + Yang Tse (20 Jul 2008) - when recvfrom prototype uses a void pointer for arguments 2, 5 or 6 this will now cause the definition, as appropriate, of RECVFROM_TYPE_ARG2_IS_VOID, diff --git a/ares/setup_once.h b/ares/setup_once.h index d3159904f..e1c5af278 100644 --- a/ares/setup_once.h +++ b/ares/setup_once.h @@ -222,6 +222,13 @@ struct timeval { #endif /* HAVE_RECVFROM */ +#ifdef RECVFROM_TYPE_ARG6_IS_VOID +# define RECVFROM_ARG6_T unsigned int +#else +# define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6 +#endif + + /* * Uppercase macro versions of ANSI/ISO is*() functions/macros which * avoid negative number inputs with argument byte codes > 127. diff --git a/lib/setup_once.h b/lib/setup_once.h index 0e2d8bc12..e96f6984a 100644 --- a/lib/setup_once.h +++ b/lib/setup_once.h @@ -229,6 +229,13 @@ struct timeval { #endif /* HAVE_RECVFROM */ +#ifdef RECVFROM_TYPE_ARG6_IS_VOID +# define RECVFROM_ARG6_T unsigned int +#else +# define RECVFROM_ARG6_T RECVFROM_TYPE_ARG6 +#endif + + /* * Uppercase macro versions of ANSI/ISO is*() functions/macros which * avoid negative number inputs with argument byte codes > 127. diff --git a/lib/tftp.c b/lib/tftp.c index ffd668c19..8ee947dfd 100644 --- a/lib/tftp.c +++ b/lib/tftp.c @@ -141,7 +141,7 @@ typedef struct tftp_state_data { struct Curl_sockaddr_storage local_addr; struct Curl_sockaddr_storage remote_addr; socklen_t remote_addrlen; - int rbytes; + ssize_t rbytes; int sbytes; tftp_packet_t rpacket; tftp_packet_t spacket; @@ -420,7 +420,7 @@ static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event) } /* Check if completed (That is, a less than full packet is received) */ - if(state->rbytes < (int)sizeof(state->spacket)){ + if(state->rbytes < sizeof(state->spacket)){ state->state = TFTP_STATE_FIN; } else { @@ -717,7 +717,7 @@ static CURLcode tftp_do(struct connectdata *conn, bool *done) CURLcode code; int rc; struct Curl_sockaddr_storage fromaddr; - socklen_t fromlen; + RECVFROM_ARG6_T fromlen; int check_time = 0; struct SingleRequest *k = &data->req; @@ -764,10 +764,10 @@ static CURLcode tftp_do(struct connectdata *conn, bool *done) else { /* Receive the packet */ - fromlen=sizeof(fromaddr); - state->rbytes = recvfrom(state->sockfd, - (void *)&state->rpacket, sizeof(state->rpacket), - 0, (struct sockaddr *)&fromaddr, &fromlen); + fromlen = (RECVFROM_ARG6_T)sizeof(fromaddr); + state->rbytes = sreadfrom(state->sockfd, + &state->rpacket, sizeof(state->rpacket), + &fromaddr, &fromlen); if(state->remote_addrlen==0) { memcpy(&state->remote_addr, &fromaddr, fromlen); state->remote_addrlen = fromlen; diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index bafe47cf6..67daa15ac 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -132,7 +132,7 @@ static int maxtimeout = 5*TIMEOUT; static char buf[PKTSIZE]; static char ackbuf[PKTSIZE]; static struct sockaddr_in from; -static socklen_t fromlen; +static RECVFROM_ARG6_T fromlen; struct bf { int counter; /* size of data in buffer, or flag */ @@ -355,7 +355,7 @@ static int synchnet(curl_socket_t f /* socket to flush */) int j = 0; char rbuf[PKTSIZE]; struct sockaddr_in fromaddr; - socklen_t fromaddrlen; + RECVFROM_ARG6_T fromaddrlen; while (1) { #if defined(HAVE_IOCTLSOCKET) @@ -365,9 +365,8 @@ static int synchnet(curl_socket_t f /* socket to flush */) #endif if (i) { j++; - fromaddrlen = sizeof fromaddr; - (void) recvfrom(f, rbuf, sizeof (rbuf), 0, - (struct sockaddr *)&fromaddr, &fromaddrlen); + fromaddrlen = (RECVFROM_ARG6_T)sizeof(fromaddr); + (void)sreadfrom(f, rbuf, sizeof(rbuf), &fromaddr, &fromaddrlen); } else break; @@ -407,7 +406,7 @@ int main(int argc, char **argv) #endif /* ENABLE_IPV6 */ struct tftphdr *tp; - int n = 0; + ssize_t n = 0; int arg = 1; char *pidname= (char *)".tftpd.pid"; unsigned short port = DEFAULT_PORT; @@ -514,9 +513,8 @@ int main(int argc, char **argv) , port ); do { - fromlen = sizeof(from); - n = recvfrom(sock, buf, sizeof (buf), 0, - (struct sockaddr *)&from, &fromlen); + fromlen = (RECVFROM_ARG6_T)sizeof(from); + n = sreadfrom(sock, buf, sizeof(buf), &from, &fromlen); if (n < 0) { logmsg("recvfrom:\n"); result = 3; -- cgit v1.2.3