1 | /*************************************** 2 | $Revision: 1.14 $ 3 | 4 | Whois query (wh) - connects to a whois server and returns result 5 | 6 | Status: NOT REVIEWED, TESTED 7 | 8 | Design and implementation by: Marek Bukowy 9 | 10 | Note: still not final. Probably SK calls should be moved to the 11 | calling routine 12 | 13 | ******************/ /****************** 14 | Copyright (c) 1999,2000,2001,2002 RIPE NCC 15 | 16 | All Rights Reserved 17 | 18 | Permission to use, copy, modify, and distribute this software and its 19 | documentation for any purpose and without fee is hereby granted, 20 | provided that the above copyright notice appear in all copies and that 21 | both that copyright notice and this permission notice appear in 22 | supporting documentation, and that the name of the author not be 23 | used in advertising or publicity pertaining to distribution of the 24 | software without specific, written prior permission. 25 | 26 | THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 27 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL 28 | AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 29 | DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 30 | AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 31 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 32 | ***************************************/ 33 | 34 | #include "rip.h" 35 | 36 | #include <sys/types.h> 37 | #include <sys/socket.h> 38 | #include <netinet/in.h> 39 | #include <netdb.h> 40 | #include <stdio.h> 41 | 42 | 43 | /*+ as above - but with connection structures, timeouts, maxlines, etc. 44 | +*/ 45 | er_ret_t 46 | WH_cd_sock(sk_conn_st *out_cd, char *hostname, unsigned port, 47 | char *query, unsigned maxlines, unsigned timeout) 48 | { 49 | int s; 50 | int lines = 0; 51 | er_ret_t err; 52 | 53 | if( (err = SK_connect(&s, hostname, port, timeout)) == SK_OK ) 54 | { 55 | #define MAX_LINE_SIZE 1024 56 | 57 | char reply[MAX_LINE_SIZE]; 58 | sk_conn_st peer_cd; 59 | 60 | SK_cd_make( &peer_cd, s, timeout ); 61 | 62 | SK_cd_puts( &peer_cd, query); 63 | SK_cd_puts( &peer_cd, "\r\n"); 64 | 65 | do { 66 | SK_cd_gets(&peer_cd, reply, MAX_LINE_SIZE); 67 | SK_cd_puts(out_cd, reply); 68 | } 69 | while( ++lines <= maxlines && peer_cd.rtc == 0 ); 70 | 71 | 72 | switch(peer_cd.rtc) { 73 | case 0: 74 | case SK_DISCONNECT: 75 | /* OK */ 76 | break; 77 | case SK_TIMEOUT: 78 | err = SK_TIMEOUT; 79 | break; 80 | default: 81 | die; /* it should not happen - change here when allowing this */ 82 | } 83 | 84 | if( lines >= maxlines ) { 85 | err = WH_MAXLINES; 86 | } 87 | 88 | 89 | SK_cd_close(&peer_cd); 90 | SK_cd_free (&peer_cd); 91 | } /* if OK */ 92 | 93 | return err; 94 | } 95 |