|
@@ -33,6 +33,7 @@
|
|
|
#include <arpa/inet.h>
|
|
#include <arpa/inet.h>
|
|
|
#include <poll.h>
|
|
#include <poll.h>
|
|
|
#include <signal.h>
|
|
#include <signal.h>
|
|
|
|
|
+#include <netdb.h>
|
|
|
|
|
|
|
|
#include <klist.h>
|
|
#include <klist.h>
|
|
|
#include <vcc/vcc.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) {
|
|
int init_socket(const char *server_addr, int server_port) {
|
|
|
struct sockaddr_in addr, server;
|
|
struct sockaddr_in addr, server;
|
|
|
|
|
+ struct hostent *hentry;
|
|
|
|
|
|
|
|
if (unlikely((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)) {
|
|
if (unlikely((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)) {
|
|
|
perror("socket()");
|
|
perror("socket()");
|
|
@@ -73,10 +75,14 @@ int init_socket(const char *server_addr, int server_port) {
|
|
|
server.sin_port = htons(server_port);
|
|
server.sin_port = htons(server_port);
|
|
|
|
|
|
|
|
if (unlikely(!inet_aton(server_addr, &server.sin_addr))) {
|
|
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"));
|
|
"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)) {
|
|
if (unlikely(connect(fd, (struct sockaddr *) &server, sizeof(struct sockaddr_in)) < 0)) {
|