diff options
-rw-r--r-- | tests/server/Makefile.inc | 4 | ||||
-rw-r--r-- | tests/server/rtspd.c | 26 | ||||
-rw-r--r-- | tests/server/server_sockaddr.h | 33 | ||||
-rw-r--r-- | tests/server/sockfilt.c | 79 | ||||
-rw-r--r-- | tests/server/sws.c | 26 | ||||
-rw-r--r-- | tests/server/tftpd.c | 149 |
6 files changed, 188 insertions, 129 deletions
diff --git a/tests/server/Makefile.inc b/tests/server/Makefile.inc index c73a85158..be3f06808 100644 --- a/tests/server/Makefile.inc +++ b/tests/server/Makefile.inc @@ -39,22 +39,26 @@ resolve_LDADD = @TEST_SERVER_LIBS@ resolve_CFLAGS = $(AM_CFLAGS) rtspd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \ + server_sockaddr.h \ rtspd.c rtspd_LDADD = @TEST_SERVER_LIBS@ rtspd_CFLAGS = $(AM_CFLAGS) sockfilt_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \ + server_sockaddr.h \ sockfilt.c \ $(top_srcdir)/lib/inet_pton.c sockfilt_LDADD = @TEST_SERVER_LIBS@ sockfilt_CFLAGS = $(AM_CFLAGS) sws_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \ + server_sockaddr.h \ sws.c sws_LDADD = @TEST_SERVER_LIBS@ sws_CFLAGS = $(AM_CFLAGS) tftpd_SOURCES = $(CURLX_SRCS) $(CURLX_HDRS) $(USEFUL) $(UTIL) \ + server_sockaddr.h \ tftpd.c \ tftp.h tftpd_LDADD = @TEST_SERVER_LIBS@ diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index 788d61c36..d2471b998 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -58,6 +58,7 @@ #include "curlx.h" /* from the private lib dir */ #include "getpart.h" #include "util.h" +#include "server_sockaddr.h" /* include memdebug.h last */ #include "memdebug.h" @@ -1169,10 +1170,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) int main(int argc, char *argv[]) { - struct sockaddr_in me; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 me6; -#endif /* ENABLE_IPV6 */ + srvr_sockaddr_union_t me; curl_socket_t sock = CURL_SOCKET_BAD; curl_socket_t msgsock = CURL_SOCKET_BAD; int wrotepidfile = 0; @@ -1294,19 +1292,19 @@ int main(int argc, char *argv[]) #ifdef ENABLE_IPV6 if(!use_ipv6) { #endif - memset(&me, 0, sizeof(me)); - me.sin_family = AF_INET; - me.sin_addr.s_addr = INADDR_ANY; - me.sin_port = htons(port); - rc = bind(sock, (struct sockaddr *) &me, sizeof(me)); + memset(&me.sa4, 0, sizeof(me.sa4)); + me.sa4.sin_family = AF_INET; + me.sa4.sin_addr.s_addr = INADDR_ANY; + me.sa4.sin_port = htons(port); + rc = bind(sock, &me.sa, sizeof(me.sa4)); #ifdef ENABLE_IPV6 } else { - memset(&me6, 0, sizeof(me6)); - me6.sin6_family = AF_INET6; - me6.sin6_addr = in6addr_any; - me6.sin6_port = htons(port); - rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6)); + memset(&me.sa6, 0, sizeof(me.sa6)); + me.sa6.sin6_family = AF_INET6; + me.sa6.sin6_addr = in6addr_any; + me.sa6.sin6_port = htons(port); + rc = bind(sock, &me.sa, sizeof(me.sa6)); } #endif /* ENABLE_IPV6 */ if(0 != rc) { diff --git a/tests/server/server_sockaddr.h b/tests/server/server_sockaddr.h new file mode 100644 index 000000000..e2c059a24 --- /dev/null +++ b/tests/server/server_sockaddr.h @@ -0,0 +1,33 @@ +#ifndef HEADER_SERVER_SOCKADDR_H +#define HEADER_SERVER_SOCKADDR_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +typedef union { + struct sockaddr sa; + struct sockaddr_in sa4; +#ifdef ENABLE_IPV6 + struct sockaddr_in6 sa6; +#endif +} srvr_sockaddr_union_t; + +#endif /* HEADER_SERVER_SOCKADDR_H */ diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c index 714d6fcde..90ce9d919 100644 --- a/tests/server/sockfilt.c +++ b/tests/server/sockfilt.c @@ -109,6 +109,7 @@ #include "getpart.h" #include "inet_pton.h" #include "util.h" +#include "server_sockaddr.h" /* include memdebug.h last */ #include "memdebug.h" @@ -688,10 +689,7 @@ static curl_socket_t sockdaemon(curl_socket_t sock, unsigned short *listenport) { /* passive daemon style */ - struct sockaddr_in me; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 me6; -#endif /* ENABLE_IPV6 */ + srvr_sockaddr_union_t listener; int flag; int rc; int totdelay = 0; @@ -742,19 +740,19 @@ static curl_socket_t sockdaemon(curl_socket_t sock, #ifdef ENABLE_IPV6 if(!use_ipv6) { #endif - memset(&me, 0, sizeof(me)); - me.sin_family = AF_INET; - me.sin_addr.s_addr = INADDR_ANY; - me.sin_port = htons(*listenport); - rc = bind(sock, (struct sockaddr *) &me, sizeof(me)); + memset(&listener.sa4, 0, sizeof(listener.sa4)); + listener.sa4.sin_family = AF_INET; + listener.sa4.sin_addr.s_addr = INADDR_ANY; + listener.sa4.sin_port = htons(*listenport); + rc = bind(sock, &listener.sa, sizeof(listener.sa4)); #ifdef ENABLE_IPV6 } else { - memset(&me6, 0, sizeof(me6)); - me6.sin6_family = AF_INET6; - me6.sin6_addr = in6addr_any; - me6.sin6_port = htons(*listenport); - rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6)); + memset(&listener.sa6, 0, sizeof(listener.sa6)); + listener.sa6.sin6_family = AF_INET6; + listener.sa6.sin6_addr = in6addr_any; + listener.sa6.sin6_port = htons(*listenport); + rc = bind(sock, &listener.sa, sizeof(listener.sa6)); } #endif /* ENABLE_IPV6 */ if(rc) { @@ -769,36 +767,30 @@ static curl_socket_t sockdaemon(curl_socket_t sock, /* The system was supposed to choose a port number, figure out which port we actually got and update the listener port value with it. */ curl_socklen_t la_size; - struct sockaddr *localaddr; - struct sockaddr_in localaddr4; + srvr_sockaddr_union_t localaddr; #ifdef ENABLE_IPV6 - struct sockaddr_in6 localaddr6; - if(!use_ipv6) { + if(!use_ipv6) #endif - la_size = sizeof(localaddr4); - localaddr = (struct sockaddr *)&localaddr4; + la_size = sizeof(localaddr.sa4); #ifdef ENABLE_IPV6 - } - else { - la_size = sizeof(localaddr6); - localaddr = (struct sockaddr *)&localaddr6; - } + else + la_size = sizeof(localaddr.sa6); #endif - memset(localaddr, 0, (size_t)la_size); - if(getsockname(sock, localaddr, &la_size) < 0) { + memset(&localaddr.sa, 0, (size_t)la_size); + if(getsockname(sock, &localaddr.sa, &la_size) < 0) { error = SOCKERRNO; logmsg("getsockname() failed with error: (%d) %s", error, strerror(error)); sclose(sock); return CURL_SOCKET_BAD; } - switch (localaddr->sa_family) { + switch (localaddr.sa.sa_family) { case AF_INET: - *listenport = ntohs(localaddr4.sin_port); + *listenport = ntohs(localaddr.sa4.sin_port); break; #ifdef ENABLE_IPV6 case AF_INET6: - *listenport = ntohs(localaddr6.sin6_port); + *listenport = ntohs(localaddr.sa6.sin6_port); break; #endif default: @@ -831,10 +823,7 @@ static curl_socket_t sockdaemon(curl_socket_t sock, int main(int argc, char *argv[]) { - struct sockaddr_in me; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 me6; -#endif /* ENABLE_IPV6 */ + srvr_sockaddr_union_t me; curl_socket_t sock = CURL_SOCKET_BAD; curl_socket_t msgsock = CURL_SOCKET_BAD; int wrotepidfile = 0; @@ -970,26 +959,26 @@ int main(int argc, char *argv[]) #ifdef ENABLE_IPV6 if(!use_ipv6) { #endif - memset(&me, 0, sizeof(me)); - me.sin_family = AF_INET; - me.sin_port = htons(connectport); - me.sin_addr.s_addr = INADDR_ANY; + memset(&me.sa4, 0, sizeof(me.sa4)); + me.sa4.sin_family = AF_INET; + me.sa4.sin_port = htons(connectport); + me.sa4.sin_addr.s_addr = INADDR_ANY; if (!addr) addr = "127.0.0.1"; - Curl_inet_pton(AF_INET, addr, &me.sin_addr); + Curl_inet_pton(AF_INET, addr, &me.sa4.sin_addr); - rc = connect(sock, (struct sockaddr *) &me, sizeof(me)); + rc = connect(sock, &me.sa, sizeof(me.sa4)); #ifdef ENABLE_IPV6 } else { - memset(&me6, 0, sizeof(me6)); - me6.sin6_family = AF_INET6; - me6.sin6_port = htons(connectport); + memset(&me.sa6, 0, sizeof(me.sa6)); + me.sa6.sin6_family = AF_INET6; + me.sa6.sin6_port = htons(connectport); if (!addr) addr = "::1"; - Curl_inet_pton(AF_INET6, addr, &me6.sin6_addr); + Curl_inet_pton(AF_INET6, addr, &me.sa6.sin6_addr); - rc = connect(sock, (struct sockaddr *) &me6, sizeof(me6)); + rc = connect(sock, &me.sa, sizeof(me.sa6)); } #endif /* ENABLE_IPV6 */ if(rc) { diff --git a/tests/server/sws.c b/tests/server/sws.c index a4c040bd2..1650226e6 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -59,6 +59,7 @@ #include "curlx.h" /* from the private lib dir */ #include "getpart.h" #include "util.h" +#include "server_sockaddr.h" /* include memdebug.h last */ #include "memdebug.h" @@ -1116,10 +1117,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) int main(int argc, char *argv[]) { - struct sockaddr_in me; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 me6; -#endif /* ENABLE_IPV6 */ + srvr_sockaddr_union_t me; curl_socket_t sock = CURL_SOCKET_BAD; curl_socket_t msgsock = CURL_SOCKET_BAD; int wrotepidfile = 0; @@ -1260,19 +1258,19 @@ int main(int argc, char *argv[]) #ifdef ENABLE_IPV6 if(!use_ipv6) { #endif - memset(&me, 0, sizeof(me)); - me.sin_family = AF_INET; - me.sin_addr.s_addr = INADDR_ANY; - me.sin_port = htons(port); - rc = bind(sock, (struct sockaddr *) &me, sizeof(me)); + memset(&me.sa4, 0, sizeof(me.sa4)); + me.sa4.sin_family = AF_INET; + me.sa4.sin_addr.s_addr = INADDR_ANY; + me.sa4.sin_port = htons(port); + rc = bind(sock, &me.sa, sizeof(me.sa4)); #ifdef ENABLE_IPV6 } else { - memset(&me6, 0, sizeof(me6)); - me6.sin6_family = AF_INET6; - me6.sin6_addr = in6addr_any; - me6.sin6_port = htons(port); - rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6)); + memset(&me.sa6, 0, sizeof(me.sa6)); + me.sa6.sin6_family = AF_INET6; + me.sa6.sin6_addr = in6addr_any; + me.sa6.sin6_port = htons(port); + rc = bind(sock, &me.sa, sizeof(me.sa6)); } #endif /* ENABLE_IPV6 */ if(0 != rc) { diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 0adcd496d..b9a0562ee 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -96,6 +96,7 @@ #include "curlx.h" /* from the private lib dir */ #include "getpart.h" #include "util.h" +#include "server_sockaddr.h" /* include memdebug.h last */ #include "memdebug.h" @@ -127,6 +128,11 @@ struct errmsg { const char *e_msg; }; +typedef union { + struct tftphdr hdr; + char storage[PKTSIZE]; +} tftphdr_storage_t; + /* * bf.counter values in range [-1 .. SEGSIZE] represents size of data in the * bf.buf buffer. Additionally it can also hold flags BF_ALLOC or BF_FREE. @@ -134,7 +140,7 @@ struct errmsg { struct bf { int counter; /* size of data in buffer, or flag */ - char buf[PKTSIZE]; /* room for data packet */ + tftphdr_storage_t buf; /* room for data packet */ }; #define BF_ALLOC -3 /* alloc'd but not yet filled */ @@ -190,10 +196,10 @@ static int current; /* index of buffer in use */ static int newline = 0; /* fillbuf: in middle of newline expansion */ static int prevchar = -1; /* putbuf: previous char (cr check) */ -static char buf[PKTSIZE]; -static char ackbuf[PKTSIZE]; +static tftphdr_storage_t buf; +static tftphdr_storage_t ackbuf; -static struct sockaddr_in from; +static srvr_sockaddr_union_t from; static curl_socklen_t fromlen; static curl_socket_t peer = CURL_SOCKET_BAD; @@ -435,7 +441,7 @@ static struct tftphdr *rw_init(int x) current = 0; bfs[1].counter = BF_FREE; nextone = x; /* ahead or behind? */ - return (struct tftphdr *)bfs[0].buf; + return &bfs[0].buf.hdr; } static struct tftphdr *w_init(void) @@ -463,7 +469,7 @@ static int readit(struct testcase *test, struct tftphdr **dpp, if (b->counter == BF_FREE) /* if it's empty */ read_ahead(test, convert); /* fill it */ - *dpp = (struct tftphdr *)b->buf; /* set caller's ptr */ + *dpp = &b->buf.hdr; /* set caller's ptr */ return b->counter; } @@ -485,7 +491,7 @@ static void read_ahead(struct testcase *test, return; nextone = !nextone; /* "incr" next buffer ptr */ - dp = (struct tftphdr *)b->buf; + dp = &b->buf.hdr; if (convert == 0) { /* The former file reading code did this: @@ -539,7 +545,7 @@ static int writeit(struct testcase *test, struct tftphdr **dpp, if (bfs[current].counter != BF_FREE) /* if not free */ write_behind(test, convert); /* flush it */ bfs[current].counter = BF_ALLOC; /* mark as alloc'd */ - *dpp = (struct tftphdr *)bfs[current].buf; + *dpp = &bfs[current].buf.hdr; return ct; /* this is a lie of course */ } @@ -575,7 +581,7 @@ static ssize_t write_behind(struct testcase *test, int convert) count = b->counter; /* remember byte count */ b->counter = BF_FREE; /* reset flag */ - dp = (struct tftphdr *)b->buf; + dp = &b->buf.hdr; nextone = !nextone; /* incr for next time */ writebuf = dp->th_data; @@ -627,7 +633,7 @@ static int synchnet(curl_socket_t f /* socket to flush */) #endif int j = 0; char rbuf[PKTSIZE]; - struct sockaddr_in fromaddr; + srvr_sockaddr_union_t fromaddr; curl_socklen_t fromaddrlen; for (;;) { @@ -638,9 +644,16 @@ 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); +#ifdef ENABLE_IPV6 + if(!use_ipv6) +#endif + fromaddrlen = sizeof(fromaddr.sa4); +#ifdef ENABLE_IPV6 + else + fromaddrlen = sizeof(fromaddr.sa6); +#endif + (void) recvfrom(f, rbuf, sizeof(rbuf), 0, + &fromaddr.sa, &fromaddrlen); } else break; @@ -650,11 +663,7 @@ static int synchnet(curl_socket_t f /* socket to flush */) int main(int argc, char **argv) { - struct sockaddr_in me; -#ifdef ENABLE_IPV6 - struct sockaddr_in6 me6; -#endif /* ENABLE_IPV6 */ - + srvr_sockaddr_union_t me; struct tftphdr *tp; ssize_t n = 0; int arg = 1; @@ -778,19 +787,19 @@ int main(int argc, char **argv) #ifdef ENABLE_IPV6 if(!use_ipv6) { #endif - memset(&me, 0, sizeof(me)); - me.sin_family = AF_INET; - me.sin_addr.s_addr = INADDR_ANY; - me.sin_port = htons(port); - rc = bind(sock, (struct sockaddr *) &me, sizeof(me)); + memset(&me.sa4, 0, sizeof(me.sa4)); + me.sa4.sin_family = AF_INET; + me.sa4.sin_addr.s_addr = INADDR_ANY; + me.sa4.sin_port = htons(port); + rc = bind(sock, &me.sa, sizeof(me.sa4)); #ifdef ENABLE_IPV6 } else { - memset(&me6, 0, sizeof(me6)); - me6.sin6_family = AF_INET6; - me6.sin6_addr = in6addr_any; - me6.sin6_port = htons(port); - rc = bind(sock, (struct sockaddr *) &me6, sizeof(me6)); + memset(&me.sa6, 0, sizeof(me.sa6)); + me.sa6.sin6_family = AF_INET6; + me.sa6.sin6_addr = in6addr_any; + me.sa6.sin6_port = htons(port); + rc = bind(sock, &me.sa, sizeof(me.sa6)); } #endif /* ENABLE_IPV6 */ if(0 != rc) { @@ -811,8 +820,16 @@ int main(int argc, char **argv) for (;;) { fromlen = sizeof(from); - n = (ssize_t)recvfrom(sock, buf, sizeof(buf), 0, - (struct sockaddr *)&from, &fromlen); +#ifdef ENABLE_IPV6 + if(!use_ipv6) +#endif + fromlen = sizeof(from.sa4); +#ifdef ENABLE_IPV6 + else + fromlen = sizeof(from.sa6); +#endif + n = (ssize_t)recvfrom(sock, &buf.storage[0], sizeof(buf.storage), 0, + &from.sa, &fromlen); if(got_exit_signal) break; if (n < 0) { @@ -824,23 +841,42 @@ int main(int argc, char **argv) set_advisor_read_lock(SERVERLOGS_LOCK); serverlogslocked = 1; - from.sin_family = AF_INET; - - peer = socket(AF_INET, SOCK_DGRAM, 0); - if(CURL_SOCKET_BAD == peer) { - logmsg("socket"); - result = 2; - break; +#ifdef ENABLE_IPV6 + if(!use_ipv6) { +#endif + from.sa4.sin_family = AF_INET; + peer = socket(AF_INET, SOCK_DGRAM, 0); + if(CURL_SOCKET_BAD == peer) { + logmsg("socket"); + result = 2; + break; + } + if(connect(peer, &from.sa, sizeof(from.sa4)) < 0) { + logmsg("connect: fail"); + result = 1; + break; + } +#ifdef ENABLE_IPV6 } - - if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) { - logmsg("connect: fail"); - result = 1; - break; + else { + from.sa6.sin6_family = AF_INET6; + peer = socket(AF_INET6, SOCK_DGRAM, 0); + if(CURL_SOCKET_BAD == peer) { + logmsg("socket"); + result = 2; + break; + } + if (connect(peer, &from.sa, sizeof(from.sa6)) < 0) { + logmsg("connect: fail"); + result = 1; + break; + } } +#endif + maxtimeout = 5*TIMEOUT; - tp = (struct tftphdr *)buf; + tp = &buf.hdr; tp->th_opcode = ntohs(tp->th_opcode); if (tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) { memset(&test, 0, sizeof(test)); @@ -935,7 +971,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) cp = (char *)&tp->th_stuff; filename = cp; again: - while (cp < buf + size) { + while (cp < &buf.storage[size]) { if (*cp == '\0') break; cp++; @@ -1089,7 +1125,7 @@ static void sendtftp(struct testcase *test, struct formats *pf) mysignal(SIGALRM, timer); #endif sdp = r_init(); - sap = (struct tftphdr *)ackbuf; + sap = &ackbuf.hdr; do { size = readit(test, &sdp, pf->f_convert); if (size < 0) { @@ -1112,7 +1148,7 @@ static void sendtftp(struct testcase *test, struct formats *pf) #ifdef HAVE_ALARM alarm(rexmtval); /* read the ack */ #endif - n = sread(peer, ackbuf, sizeof (ackbuf)); + n = sread(peer, &ackbuf.storage[0], sizeof(ackbuf.storage)); #ifdef HAVE_ALARM alarm(0); #endif @@ -1157,7 +1193,7 @@ static void recvtftp(struct testcase *test, struct formats *pf) mysignal(SIGALRM, timer); #endif rdp = w_init(); - rap = (struct tftphdr *)ackbuf; + rap = &ackbuf.hdr; do { timeout = 0; rap->th_opcode = htons((u_short)opcode_ACK); @@ -1167,7 +1203,7 @@ static void recvtftp(struct testcase *test, struct formats *pf) (void) sigsetjmp(timeoutbuf, 1); #endif send_ack: - if (swrite(peer, ackbuf, 4) != 4) { + if (swrite(peer, &ackbuf.storage[0], 4) != 4) { logmsg("write: fail\n"); goto abort; } @@ -1214,21 +1250,22 @@ send_ack: rap->th_opcode = htons((u_short)opcode_ACK); /* send the "final" ack */ rap->th_block = htons((u_short)recvblock); - (void) swrite(peer, ackbuf, 4); + (void) swrite(peer, &ackbuf.storage[0], 4); #if defined(HAVE_ALARM) && defined(SIGALRM) mysignal(SIGALRM, justtimeout); /* just abort read on timeout */ alarm(rexmtval); #endif - n = sread(peer, buf, sizeof(buf)); /* normally times out and quits */ + /* normally times out and quits */ + n = sread(peer, &buf.storage[0], sizeof(buf.storage)); #ifdef HAVE_ALARM alarm(0); #endif if(got_exit_signal) goto abort; - if (n >= 4 && /* if read some data */ - rdp->th_opcode == opcode_DATA && /* and got a data block */ - recvblock == rdp->th_block) { /* then my last ack was lost */ - (void) swrite(peer, ackbuf, 4); /* resend final ack */ + if (n >= 4 && /* if read some data */ + rdp->th_opcode == opcode_DATA && /* and got a data block */ + recvblock == rdp->th_block) { /* then my last ack was lost */ + (void) swrite(peer, &ackbuf.storage[0], 4); /* resend final ack */ } abort: return; @@ -1244,7 +1281,7 @@ static void nak(int error) int length; struct errmsg *pe; - tp = (struct tftphdr *)buf; + tp = &buf.hdr; tp->th_opcode = htons((u_short)opcode_ERROR); tp->th_code = htons((u_short)error); for (pe = errmsgs; pe->e_code >= 0; pe++) @@ -1258,6 +1295,6 @@ static void nak(int error) length = (int)strlen(pe->e_msg); tp->th_msg[length] = '\0'; length += 5; - if (swrite(peer, buf, length) != length) + if (swrite(peer, &buf.storage[0], length) != length) logmsg("nak: fail\n"); } |