diff --git a/chap02/time_server.c b/chap02/time_server.c index b3456cb..08ba2bc 100644 --- a/chap02/time_server.c +++ b/chap02/time_server.c @@ -80,7 +80,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap02/time_server_dual.c b/chap02/time_server_dual.c index e40e1a2..ab54c33 100644 --- a/chap02/time_server_dual.c +++ b/chap02/time_server_dual.c @@ -84,7 +84,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap02/time_server_ipv6.c b/chap02/time_server_ipv6.c index ea74b66..9ee401e 100644 --- a/chap02/time_server_ipv6.c +++ b/chap02/time_server_ipv6.c @@ -80,7 +80,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap03/tcp_client.c b/chap03/tcp_client.c index e000939..76b36d1 100644 --- a/chap03/tcp_client.c +++ b/chap03/tcp_client.c @@ -48,8 +48,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], argv[2], &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], argv[2], &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap03/tcp_serve_chat.c b/chap03/tcp_serve_chat.c index fdc54e7..21fcb25 100644 --- a/chap03/tcp_serve_chat.c +++ b/chap03/tcp_serve_chat.c @@ -44,7 +44,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap03/tcp_serve_toupper.c b/chap03/tcp_serve_toupper.c index 240afc1..2c7b644 100644 --- a/chap03/tcp_serve_toupper.c +++ b/chap03/tcp_serve_toupper.c @@ -44,7 +44,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap03/tcp_serve_toupper_fork.c b/chap03/tcp_serve_toupper_fork.c index 13709c7..b90fcb0 100644 --- a/chap03/tcp_serve_toupper_fork.c +++ b/chap03/tcp_serve_toupper_fork.c @@ -41,7 +41,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap04/udp_client.c b/chap04/udp_client.c index e628b9a..17d3f3e 100644 --- a/chap04/udp_client.c +++ b/chap04/udp_client.c @@ -48,8 +48,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_DGRAM; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], argv[2], &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], argv[2], &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap04/udp_recvfrom.c b/chap04/udp_recvfrom.c index 73ba095..c63c799 100644 --- a/chap04/udp_recvfrom.c +++ b/chap04/udp_recvfrom.c @@ -42,7 +42,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap04/udp_sendto.c b/chap04/udp_sendto.c index 245d67f..c59498e 100644 --- a/chap04/udp_sendto.c +++ b/chap04/udp_sendto.c @@ -39,8 +39,9 @@ int main() { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_DGRAM; struct addrinfo *peer_address; - if (getaddrinfo("127.0.0.1", "8080", &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo("127.0.0.1", "8080", &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap04/udp_serve_toupper.c b/chap04/udp_serve_toupper.c index 2c7464e..48b85c6 100644 --- a/chap04/udp_serve_toupper.c +++ b/chap04/udp_serve_toupper.c @@ -44,7 +44,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap04/udp_serve_toupper_simple.c b/chap04/udp_serve_toupper_simple.c index b4fabd4..d5745db 100644 --- a/chap04/udp_serve_toupper_simple.c +++ b/chap04/udp_serve_toupper_simple.c @@ -44,7 +44,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap05/dns_query.c b/chap05/dns_query.c index 56cc4bb..045bc7a 100644 --- a/chap05/dns_query.c +++ b/chap05/dns_query.c @@ -269,8 +269,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_DGRAM; struct addrinfo *peer_address; - if (getaddrinfo("8.8.8.8", "53", &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo("8.8.8.8", "53", &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap05/lookup.c b/chap05/lookup.c index 4ab80b3..659667b 100644 --- a/chap05/lookup.c +++ b/chap05/lookup.c @@ -49,8 +49,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_ALL; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], 0, &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], 0, &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap06/web_get.c b/chap06/web_get.c index 25cc263..980de81 100644 --- a/chap06/web_get.c +++ b/chap06/web_get.c @@ -96,8 +96,9 @@ SOCKET connect_to_host(char *hostname, char *port) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(hostname, port, &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(hostname, port, &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); exit(1); } diff --git a/chap07/web_server.c b/chap07/web_server.c index faf70e0..90aa10b 100644 --- a/chap07/web_server.c +++ b/chap07/web_server.c @@ -57,7 +57,11 @@ SOCKET create_socket(const char* host, const char *port) { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(host, port, &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(host, port, &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + exit(1); + } printf("Creating socket...\n"); SOCKET socket_listen; diff --git a/chap07/web_server2.c b/chap07/web_server2.c index f24f86a..a70ff1a 100644 --- a/chap07/web_server2.c +++ b/chap07/web_server2.c @@ -57,7 +57,11 @@ SOCKET create_socket(const char* host, const char *port) { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(host, port, &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(host, port, &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + exit(1); + } printf("Creating socket...\n"); SOCKET socket_listen; diff --git a/chap08/smtp_send.c b/chap08/smtp_send.c index 3ef8a7f..7ab9557 100644 --- a/chap08/smtp_send.c +++ b/chap08/smtp_send.c @@ -117,8 +117,9 @@ SOCKET connect_to_host(const char *hostname, const char *port) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(hostname, port, &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(hostname, port, &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); exit(1); } diff --git a/chap09/https_get.c b/chap09/https_get.c index 420c570..ecbc6f2 100644 --- a/chap09/https_get.c +++ b/chap09/https_get.c @@ -95,8 +95,9 @@ SOCKET connect_to_host(char *hostname, char *port) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(hostname, port, &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(hostname, port, &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); exit(1); } diff --git a/chap09/https_simple.c b/chap09/https_simple.c index 7b7d9a4..bfa9c47 100644 --- a/chap09/https_simple.c +++ b/chap09/https_simple.c @@ -59,9 +59,10 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(hostname, port, &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); - exit(1); + int getaddrinfo_result = getaddrinfo(hostname, port, &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; } printf("Remote address is: "); diff --git a/chap09/tls_client.c b/chap09/tls_client.c index 642bc19..69acbe6 100644 --- a/chap09/tls_client.c +++ b/chap09/tls_client.c @@ -59,8 +59,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], argv[2], &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], argv[2], &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap09/tls_get_cert.c b/chap09/tls_get_cert.c index 8baef48..7df6449 100644 --- a/chap09/tls_get_cert.c +++ b/chap09/tls_get_cert.c @@ -59,9 +59,10 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(hostname, port, &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); - exit(1); + int getaddrinfo_result = getaddrinfo(hostname, port, &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; } printf("Remote address is: "); diff --git a/chap10/https_server.c b/chap10/https_server.c index aea0b7a..f60297a 100644 --- a/chap10/https_server.c +++ b/chap10/https_server.c @@ -57,7 +57,11 @@ SOCKET create_socket(const char* host, const char *port) { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(host, port, &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(host, port, &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + exit(1); + } printf("Creating socket...\n"); SOCKET socket_listen; diff --git a/chap10/tls_time_server.c b/chap10/tls_time_server.c index bf88124..d38a841 100644 --- a/chap10/tls_time_server.c +++ b/chap10/tls_time_server.c @@ -63,7 +63,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap13/big_send.c b/chap13/big_send.c index ec64182..30e4aea 100644 --- a/chap13/big_send.c +++ b/chap13/big_send.c @@ -44,8 +44,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], argv[2], &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], argv[2], &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap13/connect_blocking.c b/chap13/connect_blocking.c index a1e46f1..19e3f3c 100644 --- a/chap13/connect_blocking.c +++ b/chap13/connect_blocking.c @@ -44,8 +44,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], argv[2], &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], argv[2], &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap13/connect_timeout.c b/chap13/connect_timeout.c index 57232e9..ea478b2 100644 --- a/chap13/connect_timeout.c +++ b/chap13/connect_timeout.c @@ -50,8 +50,9 @@ int main(int argc, char *argv[]) { memset(&hints, 0, sizeof(hints)); hints.ai_socktype = SOCK_STREAM; struct addrinfo *peer_address; - if (getaddrinfo(argv[1], argv[2], &hints, &peer_address)) { - fprintf(stderr, "getaddrinfo() failed. (%d)\n", GETSOCKETERRNO()); + int getaddrinfo_result = getaddrinfo(argv[1], argv[2], &hints, &peer_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); return 1; } diff --git a/chap13/server_crash.c b/chap13/server_crash.c index 1156ac1..9e38b4b 100644 --- a/chap13/server_crash.c +++ b/chap13/server_crash.c @@ -47,7 +47,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap13/server_ignore.c b/chap13/server_ignore.c index 715f631..ba48ab8 100644 --- a/chap13/server_ignore.c +++ b/chap13/server_ignore.c @@ -42,7 +42,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap13/server_noreuse.c b/chap13/server_noreuse.c index 315a095..119f7ab 100644 --- a/chap13/server_noreuse.c +++ b/chap13/server_noreuse.c @@ -42,7 +42,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n"); diff --git a/chap13/server_reuse.c b/chap13/server_reuse.c index 4eeab63..38773b7 100644 --- a/chap13/server_reuse.c +++ b/chap13/server_reuse.c @@ -42,7 +42,11 @@ int main() { hints.ai_flags = AI_PASSIVE; struct addrinfo *bind_address; - getaddrinfo(0, "8080", &hints, &bind_address); + int getaddrinfo_result = getaddrinfo(0, "8080", &hints, &bind_address); + if (getaddrinfo_result) { + fprintf(stderr, "getaddrinfo() failed. (%d, %d)\n", getaddrinfo_result, GETSOCKETERRNO()); + return 1; + } printf("Creating socket...\n");