瀏覽代碼

vcc: support hostnames

intirain 4 年之前
父節點
當前提交
32d816cec8
共有 3 個文件被更改,包括 12 次插入 和 6 次删除
  1. 2 2
      Makefile
  2. 2 2
      include/vcc/version.h
  3. 8 2
      vcc.c

+ 2 - 2
Makefile

@@ -1,6 +1,6 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 36
-VCC_PATCH 		= 1
+VCC_MINOR 		= 37
+VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 # change this to '/usr/share/' or '/opt/vcc/' etc

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "vcc 1.36.0 Sun Jun 19 07:18:30 PM CST 2022 root"
-#define VCC_SEMVER "vcc 1.36.0-rc "
+#define VCC_VERSION "vcc 1.37.0 Sun Jun 19 07:35:09 PM CST 2022 root"
+#define VCC_SEMVER "vcc 1.37.0-rc "

+ 8 - 2
vcc.c

@@ -33,6 +33,7 @@
 #include <arpa/inet.h>
 #include <poll.h>
 #include <signal.h>
+#include <netdb.h>
 
 #include <klist.h>
 #include <vcc/vcc.h>
@@ -48,6 +49,7 @@ struct klist_node sname_cache = KLIST_NODE_INIT(&sname_cache);
 
 int init_socket(const char *server_addr, int server_port) {
 	struct sockaddr_in addr, server;
+	struct hostent *hentry;
 
 	if (unlikely((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)) {
 		perror("socket()");
@@ -73,10 +75,14 @@ int init_socket(const char *server_addr, int server_port) {
 	server.sin_port = htons(server_port);
 
 	if (unlikely(!inet_aton(server_addr, &server.sin_addr))) {
-		fprintf(stderr, _("invalid ip address. "
+		if (!(hentry = gethostbyname(server_addr))) {	
+			fprintf(stderr, _("invalid address or host. "
 				"leave blank if you want to connect the default server. \n"));
 
-		exit(1);
+			exit(1);
+		}
+
+		inet_aton(inet_ntoa(*(struct in_addr *) hentry->h_addr), &server.sin_addr);
 	}
 
 	if (unlikely(connect(fd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) < 0)) {