1 /* $Id: macnet.c,v 1.1.2.1 1999/04/01 21:26:03 ben Exp $ */
3 * Copyright (c) 1999 Ben Harris
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
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
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
28 * macnet.c -- PuTTY-to-MacTCP glue
32 #include <AddresXlation.h>
34 #include <MixedMode.h>
35 #include <Processes.h>
41 static short mtcp_refnum;
42 statis OSErr mtcp_initted = FALSE;
44 static void macnet_init(void);
45 static pascal void macnet_resolved(struct HostInfo *, char *);
47 #ifdef TARGET_RT_MAC_CFM
48 static RoutineDescriptor macnet_resolved_upp =
49 BUILD_ROUTINE_DESCRIPTOR(uppResultProcInfo, (ProcPtr)macnet_resolved);
51 #define macnet_resolved_upp macnet_resolved
55 * Initialise networking. Set mtcp_initted if it goes OK.
57 static OSErr macnet_init(void) {
60 err = OpenDriver(".IPP", &mtcp_refnum);
63 err = OpenResolver(NULL);
68 /* XXX: otherwise report an error */
71 Socket *tcp_open(const char *host, int port, char **realhost) {
76 s = smalloc(sizeof(struct Socket));
78 if ((err = macnet_init()) != noErr)
79 fatalbox("Couldn't init network (%d)", err);
81 GetCurrentProcess(&s->psn);
82 err = StrToAddr(host, &s->host_info, &macnet_resolved_upp, (char *)s);
84 fatalbox("Host lookup failed (%d)", err);
85 if (s->host_info.rtnCode != cacheFault)
86 macnet_resolved(&s->host_info, s);
90 static pascal void macnet_resolved(struct hostInfo *hi, char *cookie) {
91 Socket *s = (Socket *)cookie;
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);
100 * c-file-style: "simon"