Hello.
I have found that whois utility from inetutils is practically unusable. Because it half-closes socket for write right after sending requests. But whois servers I use are reacting badly on it - they are closing their end too before fully sending repy. For example whois.ripe.net is able to send only header and whois.arin.net is replying nothing. I have wrote a simple program to reproduse this:

#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>

int main(int argc, char **argv)
{
   int sockfd, n;
   struct sockaddr_in servaddr,cliaddr;
   char sendline[1000] = "-VMd4.5 0.0.0.0\r\n";
   char recvline[1001];

   sockfd=socket(AF_INET,SOCK_STREAM,0);
   bzero(&servaddr,sizeof(servaddr));
   servaddr.sin_family = AF_INET;
   servaddr.sin_addr.s_addr=inet_addr(argv[1]);
   servaddr.sin_port=htons(43);

   connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));

   write(sockfd, sendline, strlen(sendline));

   shutdown(sockfd, SHUT_WR);

   while ((n = read(sockfd, recvline, 1000)) != 0)
   {
      write(1, recvline, n);
   }
   close(sockfd);

   return 0;
}

Here is results:
# whois.ripe.net -> 193.0.6.135
$ ./test-shutdown 193.0.6.135
% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf

$

# whois.arin.net -> 199.71.0.47
$ ./test-shutdown 199.71.0.47
$

If I comment shutdown string then I get:

$ ./test-shutdown 193.0.6.135
% This is the RIPE Database query service.
% The objects are in RPSL format.
%
% The RIPE Database is subject to Terms and Conditions.
% See http://www.ripe.net/db/support/db-terms-conditions.pdf

% Note: this output has been filtered.
%       To receive output for a database update, use the "-B" flag.

% Information related to '0.0.0.0 - 255.255.255.255'

% No abuse contact registered for 0.0.0.0 - 255.255.255.255

inetnum:        0.0.0.0 - 255.255.255.255
netname:        IANA-BLK
descr:          The whole IPv4 address space
...

$ ./test-shutdown 199.71.0.47

#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#
# If you see inaccuracies in the results, please report at
# http://www.arin.net/public/whoisinaccuracy/index.xhtml
#


#
# Query terms are too ambiguous.  Please refine query.
#
#

ARIN's WHOIS service provides a mechanism for finding contact and registration
information for resources registered with ARIN. ARIN's database contains IP
addresses, autonomous system numbers, organizations or customers that are
associated with these resources, and related Points of Contact [POC].
...

So I think something like it should be for good:

diff -ru a/whois/whois.c b/whois/whois.c
--- a/whois/whois.c     2013-09-26 13:36:38.000000000 +0400
+++ b/whois/whois.c     2014-07-24 15:30:48.392090728 +0400
@@ -469,8 +469,6 @@
   fi = fdopen (sock, "r");
   if (write (sock, query, strlen (query)) < 0)
     err_sys ("write");
-  if (shutdown (sock, 1) < 0)
-    err_sys ("shutdown");
   while (fgets (buf, 200, fi))
     {                          /* XXX errors? */
       if (hide == 1)

--
Alexander Zubkov


Reply via email to