Use the sreadfrom() wrapper to replace recvfrom() in our code.

This commit is contained in:
Yang Tse 2008-07-21 03:06:07 +00:00
parent bffe69a151
commit 1b37baf656
5 changed files with 31 additions and 16 deletions

View File

@ -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,

View File

@ -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.

View File

@ -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.

View File

@ -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;

View File

@ -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;