Re: [evlog-dev] [Bug] fail to connect to the remote consolidator host when using IP address which cannot be resolved by dns
Hien Q Nguyen <[email protected]> Wed, 18 Dec 2002 09:33:02 -0800
| Newsgroups | gmane.linux.kernel.event-logging |
|---|---|
| Message-ID | <[email protected]> |
Hi Yi, Thanks for reporting this. Our intention is even if you enter an IP address in the .conf file, it has to be resolved back to the hostname via the DNS or /etc/hosts file. We will make sure that it will be documented in the INSTALL. Thanks, Hien. Hien Nguyen [email protected] (503) 578-4347 |---------+--------------------------------------------> | | "Zhu, Yi" <[email protected]> | | | Sent by: | | | [email protected]| | | ceforge.net | | | | | | | | | 12/18/2002 01:50 AM | | | | |---------+--------------------------------------------> >-----------------------------------------------------------------------------------------------| | | | To: "'[email protected]'" | | <[email protected]> | | cc: | | Subject: [evlog-dev] [Bug] fail to connect to the remote consolidator host when using | | IP address which cannot be resolved by dns | | | | | >-----------------------------------------------------------------------------------------------| Hi, When I setup evlog 1.5 to use the TCP plug-in forwarding events feature, I found my source host cannot connect to the remote consolidator host. I debuged the code by setting DEBUG2 to gcc and finally found out the reason. It is because I use IP address in file /etc/evlog.d/plugins/tcp_rmtlog_be.conf, but I didn't setup my machine to be recognized by the dns server or in the source host's /etc/hosts. So the plug-in code will return -1 (tcp_rmtlog_be.c:90) because gethostbyaddr() returns NULL (tcp_rmtlog_be.c:82). I don't think it is necessary to use gethostbyaddr() if it is a IP address, otherwise it should be documented in INSTALL file to tell people adding the remote consolidator host in the source host's /etc/hosts, right? The same thing happens for UDP. Below is my fix for the bug. diff -Naur evlog/user/cmd/evlogd/tcp_rmtlog_be/tcp_rmtlog_be.c evlog-new/user/cmd/evlogd/tcp_rmtlog_be/tcp_rmtlog_be.c --- evlog/user/cmd/evlogd/tcp_rmtlog_be/tcp_rmtlog_be.c 2002-12-14 03:26:01. 000000000 +0800 +++ evlog-new/user/cmd/evlogd/tcp_rmtlog_be/tcp_rmtlog_be.c 2002-12-18 17:52:04.000000000 +0800 @@ -79,10 +79,11 @@ } /* get host name/ip address */ if (inet_aton(rmt_hostname, &inaddr)) { - rmthost = (struct hostent *) gethostbyaddr((char *) &inaddr, sizeof(inaddr), AF_INET); + address.sin_addr.s_addr = inet_addr (rmt_hostname); } else { rmthost = (struct hostent *) gethostbyname(rmt_hostname); + memcpy(&address.sin_addr, rmthost->h_addr_list[0], rmthost->h_length); } if (!rmthost) { @@ -99,8 +100,6 @@ address.sin_family = AF_INET; address.sin_port = htons(evl_port); - memcpy(&address.sin_addr, rmthost->h_addr_list[0], rmthost->h_length); - if(connect(fd, (struct sockaddr *) &address, sizeof(address)) != 0) { TRACE("Failed to connect to remote server.\n"); close(fd); diff -Naur evlog/user/cmd/evlogd/udp_rmtlog_be/udp_rmtlog_be.c evlog-new/user/cmd/evlogd/udp_rmtlog_be/udp_rmtlog_be.c --- evlog/user/cmd/evlogd/udp_rmtlog_be/udp_rmtlog_be.c 2002-12-12 02:58:57. 000000000 +0800 +++ evlog-new/user/cmd/evlogd/udp_rmtlog_be/udp_rmtlog_be.c 2002-12-18 17:52:05.000000000 +0800 @@ -64,10 +64,11 @@ } /* get host name/ip address */ if (inet_aton(rmt_hostname, &inaddr)) { - rmthost = (struct hostent *) gethostbyaddr((char *) &inaddr, sizeof(inaddr), AF_INET); + address.sin_addr.s_addr = inet_addr (rmt_hostname); } else { rmthost = (struct hostent *) gethostbyname(rmt_hostname); + memcpy(&address.sin_addr, rmthost->h_addr_list[0], rmthost->h_length); } if (!rmthost) { @@ -89,8 +90,6 @@ address.sin_family = AF_INET; address.sin_port = htons(evl_port); - memcpy(&address.sin_addr, rmthost->h_addr_list[0], rmthost->h_length); - return 0; } Thanks, ---------------------------------------------------------------------------- ---------------------------------------------------- Opinions expressed are those of the author and do not represent Intel Corp. Zhu Yi (Chuyee) Intel China Software Lab (ICSL) 22nd Floor, ShanghaiMart Tower No. 2299 Yan'an Road(West) Shanghai 200336, PRC Tel: 8621-52574545-1261 Fax: 8621-62366119 GnuPG v1.0.6 (GNU/Linux) http://cn.geocities.com/chewie_chuyee/gpg.txt 1024D/71C34820 C939 2B0B FBCE 1D51 109A 55E5 8650 DB90 71C3 4820 ------------------------------------------------------- This sf.net email is sponsored by: With Great Power, Comes Great Responsibility Learn to use your power at OSDN's High Performance Computing Channel http://hpc.devchannel.org/ _______________________________________________ evlog-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/evlog-developers ------------------------------------------------------- This SF.NET email is sponsored by: Order your Holiday Geek Presents Now! Green Lasers, Hip Geek T-Shirts, Remote Control Tanks, Caffeinated Soap, MP3 Players, XBox Games, Flying Saucers, WebCams, Smart Putty. T H I N K G E E K . C O M http://www.thinkgeek.com/sf/