modules/wh/wh_queries.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- WH_cd_sock
1 /***************************************
2 $Revision: 1.12 $
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 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 <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <netdb.h>
38 #include <stdio.h>
39
40 #include <erroutines.h>
41 #include "sk.h"
42
43
44
45 /*+ as above - but with connection structures, timeouts, maxlines, etc.
46 +*/
47 er_ret_t
48 WH_cd_sock(sk_conn_st *out_cd, char *hostname, unsigned port,
/* [<][>][^][v][top][bottom][index][help] */
49 char *query, unsigned maxlines, unsigned timeout)
50 {
51 int s;
52 int lines = 0;
53 er_ret_t err;
54
55 if( (err = SK_connect(&s, hostname, port, timeout)) == SK_OK )
56 {
57 #define MAX_LINE_SIZE 1024
58
59 char reply[MAX_LINE_SIZE];
60 sk_conn_st peer_cd;
61
62 SK_cd_make( &peer_cd, s, timeout );
63
64 SK_cd_puts( &peer_cd, query);
65 SK_cd_puts( &peer_cd, "\r\n");
66
67 do {
68 SK_cd_gets(&peer_cd, reply, MAX_LINE_SIZE);
69 SK_cd_puts(out_cd, reply);
70 }
71 while( ++lines <= maxlines && peer_cd.rtc == 0 );
72
73
74 switch(peer_cd.rtc) {
75 case 0:
76 case SK_DISCONNECT:
77 /* OK */
78 break;
79 case SK_TIMEOUT:
80 err = SK_TIMEOUT;
81 break;
82 default:
83 die; /* it should not happen - change here when allowing this */
84 }
85
86 if( lines >= maxlines ) {
87 err = WH_MAXLINES;
88 }
89
90
91 SK_cd_close(&peer_cd);
92 SK_cd_free (&peer_cd);
93 } /* if OK */
94
95 return err;
96 }
97