diff --git a/chap02/time_server.c b/chap02/time_server.c index b3456cb..3233ec5 100644 --- a/chap02/time_server.c +++ b/chap02/time_server.c @@ -130,7 +130,7 @@ int main() { printf("Reading request...\n"); char request[1024]; - int bytes_received = recv(socket_client, request, 1024, 0); + int bytes_received = recv(socket_client, request, sizeof(request), 0); printf("Received %d bytes.\n", bytes_received); //printf("%.*s", bytes_received, request); diff --git a/chap02/time_server_dual.c b/chap02/time_server_dual.c index e40e1a2..72c5b2c 100644 --- a/chap02/time_server_dual.c +++ b/chap02/time_server_dual.c @@ -139,7 +139,7 @@ int main() { printf("Reading request...\n"); char request[1024]; - int bytes_received = recv(socket_client, request, 1024, 0); + int bytes_received = recv(socket_client, request, sizeof(request), 0); printf("Received %d bytes.\n", bytes_received); //printf("%.*s", bytes_received, request); diff --git a/chap02/time_server_ipv6.c b/chap02/time_server_ipv6.c index ea74b66..e41812f 100644 --- a/chap02/time_server_ipv6.c +++ b/chap02/time_server_ipv6.c @@ -130,7 +130,7 @@ int main() { printf("Reading request...\n"); char request[1024]; - int bytes_received = recv(socket_client, request, 1024, 0); + int bytes_received = recv(socket_client, request, sizeof(request), 0); printf("Received %d bytes.\n", bytes_received); //printf("%.*s", bytes_received, request); diff --git a/chap03/tcp_client.c b/chap03/tcp_client.c index e000939..5d22e4f 100644 --- a/chap03/tcp_client.c +++ b/chap03/tcp_client.c @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) { if (FD_ISSET(socket_peer, &reads)) { char read[4096]; - int bytes_received = recv(socket_peer, read, 4096, 0); + int bytes_received = recv(socket_peer, read, sizeof(read), 0); if (bytes_received < 1) { printf("Connection closed by peer.\n"); break; @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) { if(FD_ISSET(0, &reads)) { #endif char read[4096]; - if (!fgets(read, 4096, stdin)) break; + if (!fgets(read, sizeof(read), stdin)) break; printf("Sending: %s", read); int bytes_sent = send(socket_peer, read, strlen(read), 0); printf("Sent %d bytes.\n", bytes_sent); diff --git a/chap03/tcp_serve_chat.c b/chap03/tcp_serve_chat.c index fdc54e7..3149000 100644 --- a/chap03/tcp_serve_chat.c +++ b/chap03/tcp_serve_chat.c @@ -117,7 +117,7 @@ int main() { } else { char read[1024]; - int bytes_received = recv(i, read, 1024, 0); + int bytes_received = recv(i, read, sizeof(read), 0); if (bytes_received < 1) { FD_CLR(i, &master); CLOSESOCKET(i); diff --git a/chap03/tcp_serve_toupper.c b/chap03/tcp_serve_toupper.c index 240afc1..d9479b2 100644 --- a/chap03/tcp_serve_toupper.c +++ b/chap03/tcp_serve_toupper.c @@ -117,7 +117,7 @@ int main() { } else { char read[1024]; - int bytes_received = recv(i, read, 1024, 0); + int bytes_received = recv(i, read, sizeof(read), 0); if (bytes_received < 1) { FD_CLR(i, &master); CLOSESOCKET(i); diff --git a/chap03/tcp_serve_toupper_fork.c b/chap03/tcp_serve_toupper_fork.c index 13709c7..876ea5f 100644 --- a/chap03/tcp_serve_toupper_fork.c +++ b/chap03/tcp_serve_toupper_fork.c @@ -94,7 +94,7 @@ int main() { CLOSESOCKET(socket_listen); while(1) { char read[1024]; - int bytes_received = recv(socket_client, read, 1024, 0); + int bytes_received = recv(socket_client, read, sizeof(read), 0); if (bytes_received < 1) { CLOSESOCKET(socket_client); exit(0); diff --git a/chap04/udp_client.c b/chap04/udp_client.c index e628b9a..46a92da 100644 --- a/chap04/udp_client.c +++ b/chap04/udp_client.c @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) { if (FD_ISSET(socket_peer, &reads)) { char read[4096]; - int bytes_received = recv(socket_peer, read, 4096, 0); + int bytes_received = recv(socket_peer, read, sizeof(read), 0); if (bytes_received < 1) { printf("Connection closed by peer.\n"); break; @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) { if(FD_ISSET(0, &reads)) { #endif char read[4096]; - if (!fgets(read, 4096, stdin)) break; + if (!fgets(read, sizeof(read), stdin)) break; printf("Sending: %s", read); int bytes_sent = send(socket_peer, read, strlen(read), 0); printf("Sent %d bytes.\n", bytes_sent); diff --git a/chap04/udp_recvfrom.c b/chap04/udp_recvfrom.c index 73ba095..c240efb 100644 --- a/chap04/udp_recvfrom.c +++ b/chap04/udp_recvfrom.c @@ -68,7 +68,7 @@ int main() { socklen_t client_len = sizeof(client_address); char read[1024]; int bytes_received = recvfrom(socket_listen, - read, 1024, + read, sizeof(read), 0, (struct sockaddr*) &client_address, &client_len); diff --git a/chap04/udp_serve_toupper.c b/chap04/udp_serve_toupper.c index 2c7464e..e3e542e 100644 --- a/chap04/udp_serve_toupper.c +++ b/chap04/udp_serve_toupper.c @@ -86,7 +86,7 @@ int main() { socklen_t client_len = sizeof(client_address); char read[1024]; - int bytes_received = recvfrom(socket_listen, read, 1024, 0, + int bytes_received = recvfrom(socket_listen, read, sizeof(read), 0, (struct sockaddr *)&client_address, &client_len); if (bytes_received < 1) { fprintf(stderr, "connection closed. (%d)\n", diff --git a/chap04/udp_serve_toupper_simple.c b/chap04/udp_serve_toupper_simple.c index b4fabd4..d078245 100644 --- a/chap04/udp_serve_toupper_simple.c +++ b/chap04/udp_serve_toupper_simple.c @@ -73,7 +73,7 @@ int main() { socklen_t client_len = sizeof(client_address); char read[1024]; - int bytes_received = recvfrom(socket_listen, read, 1024, 0, + int bytes_received = recvfrom(socket_listen, read, sizeof(read), 0, (struct sockaddr *)&client_address, &client_len); if (bytes_received < 1) { fprintf(stderr, "connection closed. (%d)\n", diff --git a/chap05/dns_query.c b/chap05/dns_query.c index 56cc4bb..d029115 100644 --- a/chap05/dns_query.c +++ b/chap05/dns_query.c @@ -321,7 +321,7 @@ int main(int argc, char *argv[]) { char read[1024]; int bytes_received = recvfrom(socket_peer, - read, 1024, 0, 0, 0); + read, sizeof(read), 0, 0, 0); printf("Received %d bytes.\n", bytes_received); diff --git a/chap08/smtp_send.c b/chap08/smtp_send.c index 3ef8a7f..fe517e6 100644 --- a/chap08/smtp_send.c +++ b/chap08/smtp_send.c @@ -209,7 +209,7 @@ int main() { timeinfo = gmtime(&timer); char date[128]; - strftime(date, 128, "%a, %d %b %Y %H:%M:%S +0000", timeinfo); + strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S +0000", timeinfo); send_format(server, "Date:%s\r\n", date); diff --git a/chap09/tls_client.c b/chap09/tls_client.c index 642bc19..b9969f2 100644 --- a/chap09/tls_client.c +++ b/chap09/tls_client.c @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) { if (FD_ISSET(socket_peer, &reads)) { char read[4096]; - int bytes_received = SSL_read(ssl, read, 4096); + int bytes_received = SSL_read(ssl, read, sizeof(read)); if (bytes_received < 1) { int err; if ((err = SSL_get_error(ssl, bytes_received)) && @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) { if(FD_ISSET(0, &reads)) { #endif char read[4096]; - if (!fgets(read, 4096, stdin)) break; + if (!fgets(read, sizeof(read), stdin)) break; printf("Sending: %s", read); int bytes_sent = SSL_write(ssl, read, strlen(read)); printf("Sent %d bytes.\n", bytes_sent); diff --git a/chap10/tls_time_server.c b/chap10/tls_time_server.c index bf88124..846ac2b 100644 --- a/chap10/tls_time_server.c +++ b/chap10/tls_time_server.c @@ -135,7 +135,7 @@ int main() { printf("Reading request...\n"); char request[1024]; - int bytes_received = SSL_read(ssl, request, 1024); + int bytes_received = SSL_read(ssl, request, sizeof(request)); printf("Received %d bytes.\n", bytes_received); //printf("%.*s", bytes_received, request); diff --git a/chap13/error_text.c b/chap13/error_text.c index 6432ff1..0410d88 100644 --- a/chap13/error_text.c +++ b/chap13/error_text.c @@ -32,7 +32,7 @@ const char *get_error_text() { static char message[256] = {0}; FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - 0, WSAGetLastError(), 0, message, 256, 0); + 0, WSAGetLastError(), 0, message, sizeof(message), 0); char *nl = strrchr(message, '\n'); if (nl) *nl = 0; return message; diff --git a/chap13/server_crash.c b/chap13/server_crash.c index 1156ac1..0dc0c01 100644 --- a/chap13/server_crash.c +++ b/chap13/server_crash.c @@ -93,7 +93,7 @@ int main() { int bytes_received; while(1) { char read[1024]; - bytes_received = recv(socket_client, read, 1024, 0); + bytes_received = recv(socket_client, read, sizeof(read), 0); if (bytes_received < 1) { break; } else {