Browse Source

bfgminer-rpc: Catch error when server host fails to resolve to an IP

Luke Dashjr 12 years ago
parent
commit
77e7990456
1 changed files with 5 additions and 0 deletions
  1. 5 0
      api-example.c

+ 5 - 0
api-example.c

@@ -200,6 +200,11 @@ int callapi(char *command, char *host, short int port)
 	SOCKETINIT;
 	SOCKETINIT;
 
 
 	ip = gethostbyname(host);
 	ip = gethostbyname(host);
+	if (!ip)
+	{
+		printf("Failed to resolve host %s\n", host);
+		return 1;
+	}
 
 
 	sock = socket(AF_INET, SOCK_STREAM, 0);
 	sock = socket(AF_INET, SOCK_STREAM, 0);
 	if (sock == INVSOCK) {
 	if (sock == INVSOCK) {