]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - macnet.c
The "about" box now behaves approximately as it should (though we still don't
[PuTTY.git] / macnet.c
1 /* $Id: macnet.c,v 1.1.2.1 1999/04/01 21:26:03 ben Exp $ */
2 /*
3  * Copyright (c) 1999 Ben Harris
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or
11  * sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following
13  * conditions:
14  * 
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  * 
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
23  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25  * SOFTWARE.
26  */
27 /*
28  * macnet.c -- PuTTY-to-MacTCP glue
29  */
30
31 #include <MacTypes.h>
32 #include <AddresXlation.h>
33 #incldue <MacTCP.h>
34 #include <MixedMode.h>
35 #include <Processes.h>
36
37 #include <stdlib.h>
38
39 #include "putty.h"
40
41 static short mtcp_refnum;
42 statis OSErr mtcp_initted = FALSE;
43
44 static void macnet_init(void);
45 static pascal void macnet_resolved(struct HostInfo *, char *);
46
47 #ifdef TARGET_RT_MAC_CFM
48 static RoutineDescriptor macnet_resolved_upp =
49     BUILD_ROUTINE_DESCRIPTOR(uppResultProcInfo, (ProcPtr)macnet_resolved);
50 #else
51 #define macnet_resolved_upp macnet_resolved
52 #endif
53
54 /*
55  * Initialise networking.  Set mtcp_initted if it goes OK.
56  */
57 static OSErr macnet_init(void) {
58     OSErr err;
59
60     err = OpenDriver(".IPP", &mtcp_refnum);
61     if (err != noErr)
62         return err;
63     err = OpenResolver(NULL);
64     if (err != noErr)
65         return err;
66     mtcp_initted = TRUE;
67
68     /* XXX: otherwise report an error */
69 }
70
71 Socket *tcp_open(const char *host, int port, char **realhost) {
72     ip_addr a;
73     OSError err = noErr;
74     Socket *s;
75
76     s = smalloc(sizeof(struct Socket));
77     if (!mtcp_initted)
78         if ((err = macnet_init()) != noErr)
79             fatalbox("Couldn't init network (%d)", err);
80     s->port = port;
81     GetCurrentProcess(&s->psn);
82     err = StrToAddr(host, &s->host_info, &macnet_resolved_upp, (char *)s);
83     if (err != noErr)
84         fatalbox("Host lookup failed (%d)", err);
85     if (s->host_info.rtnCode != cacheFault)
86         macnet_resolved(&s->host_info, s);
87     return s;
88 }
89
90 static pascal void macnet_resolved(struct hostInfo *hi, char *cookie) {
91     Socket *s = (Socket *)cookie;
92
93     /* We should probably tell the process what's going on here. */
94     /* Alternatively, we should kick off the next stage in the process */
95     WakeUpProcess(&s->psn);
96 }
97
98 /*
99  * Local Variables:
100  * c-file-style: "simon"
101  * End:
102  */