Commit d9f2f701 authored by Fabio Baltieri's avatar Fabio Baltieri Committed by Johan Hedberg
Browse files

samples: ensure struct addrinfo is always zero initialized



There's few samples with a struct addrinfo on the stack that only
initialize some of the fields, feeding whatever is on the stack for the
rest to the getaddrinfo() code. Bumped into an issue where that
sometimes happens to set the bit of the (ai_flags & AI_NUMERICHOST),
making host resolution failing.

Add a couple of memset on the affected samples so this does not happen.

Signed-off-by: default avatarFabio Baltieri <fabiobaltieri@google.com>
parent 9fc22015
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -428,6 +428,7 @@ redirect:
	printf("Preparing HTTP GET request for http%s://%s:%s/%s\n",
		       (is_tls ? "s" : ""), host, port, uri_path);

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = AF_INET;
	hints.ai_socktype = SOCK_STREAM;

+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ int main(void)
	printf("Preparing HTTP GET request for http://" HTTP_HOST
	       ":" HTTP_PORT HTTP_PATH "\n");

	memset(&hints, 0, sizeof(hints));
	hints.ai_family = AF_INET;
	hints.ai_socktype = SOCK_STREAM;
	st = getaddrinfo(HTTP_HOST, HTTP_PORT, &hints, &res);