]> git.saurik.com Git - apple/network_cmds.git/blame - identd.tproj/proxy.c
network_cmds-77.tar.gz
[apple/network_cmds.git] / identd.tproj / proxy.c
CommitLineData
b7080c8e
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25** $Id: proxy.c,v 1.1.1.1 1999/05/02 03:57:41 wsanchez Exp $
26**
27** proxy.c This file implements the proxy() call.
28**
29** This program is in the public domain and may be used freely by anyone
30** who wants to.
31**
32** Last update: 12 Dec 1992
33**
34** Please send bug fixes/bug reports to: Peter Eriksson <pen@lysator.liu.se>
35*/
36
37#include <stdio.h>
38#include <errno.h>
39
40#include "identd.h"
41
42
43#ifdef INCLUDE_PROXY
44#include <sys/types.h>
45#include <sys/time.h>
46#include <netinet/in.h>
47
48#include <ident.h>
49#endif
50
51
52/*
53** This function should establish a connection to a remote IDENT
54** server and query it for the information associated with the
55** specified connection and the return that to the caller.
56**
57** Should there be three different timeouts (Connection Establishment,
58** Query Transmit and Query Receive)?
59*/
60int proxy(laddr, faddr, lport, fport, timeout)
61 struct in_addr *laddr;
62 struct in_addr *faddr;
63 int lport;
64 int fport;
65 struct timeval *timeout;
66{
67#ifndef INCLUDE_PROXY
68 printf("%d , %d : ERROR : %s\r\n",
69 lport, fport,
70 unknown_flag ? "UNKNOWN-ERROR" : "X-NOT-YET-IMPLEMENTED");
71
72 return -1;
73#else
74 id_t *idp;
75 char *answer;
76 char *opsys;
77 char *charset;
78
79 idp = id_open(laddr, faddr, timeout);
80 if (!idp)
81 {
82 printf("%d , %d : ERROR : %s\r\n",
83 lport, fport,
84 unknown_flag ? "UNKNOWN-ERROR" : "X-CONNECTION-REFUSED");
85 return -1;
86 }
87
88 if (id_query(idp, lport, fport, timeout) < 0)
89 {
90 printf("%d , %d : ERROR : %s\r\n",
91 lport, fport,
92 unknown_flag ? "UNKNOWN-ERROR" : "X-TRANSMIT-QUERY-ERROR");
93 id_close(idp);
94 return -1;
95 }
96
97 switch (id_parse(idp, timeout, &lport, &fport, &answer, &opsys, &charset))
98 {
99 case 1:
100 printf("%d , %d : USERID : %s %s%s : %s\r\n",
101 lport, fport,
102 opsys,
103 charset ? "," : "",
104 charset ? charset : "",
105 answer);
106 break;
107
108 case 2:
109 printf("%d , %d : ERROR : %s\r\n",
110 lport, fport, answer);
111 break;
112
113 case 0: /* More to parse - fix this later! */
114 case -1: /* Internal error */
115 default:
116 printf("%d , %d : ERROR : %s\r\n",
117 lport, fport,
118 unknown_flag ? "UNKNOWN-ERROR" : "X-PARSE-REPLY-ERROR");
119 }
120
121 id_close(idp);
122#endif
123}