diff --git a/macnet.c b/macnet.c new file mode 100644 index 00000000..a4b7944b --- /dev/null +++ b/macnet.c @@ -0,0 +1,102 @@ +/* $Id: macnet.c,v 1.1.2.1 1999/04/01 21:26:03 ben Exp $ */ +/* + * Copyright (c) 1999 Ben Harris + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +/* + * macnet.c -- PuTTY-to-MacTCP glue + */ + +#include +#include +#incldue +#include +#include + +#include + +#include "putty.h" + +static short mtcp_refnum; +statis OSErr mtcp_initted = FALSE; + +static void macnet_init(void); +static pascal void macnet_resolved(struct HostInfo *, char *); + +#ifdef TARGET_RT_MAC_CFM +static RoutineDescriptor macnet_resolved_upp = + BUILD_ROUTINE_DESCRIPTOR(uppResultProcInfo, (ProcPtr)macnet_resolved); +#else +#define macnet_resolved_upp macnet_resolved +#endif + +/* + * Initialise networking. Set mtcp_initted if it goes OK. + */ +static OSErr macnet_init(void) { + OSErr err; + + err = OpenDriver(".IPP", &mtcp_refnum); + if (err != noErr) + return err; + err = OpenResolver(NULL); + if (err != noErr) + return err; + mtcp_initted = TRUE; + + /* XXX: otherwise report an error */ +} + +Socket *tcp_open(const char *host, int port, char **realhost) { + ip_addr a; + OSError err = noErr; + Socket *s; + + s = smalloc(sizeof(struct Socket)); + if (!mtcp_initted) + if ((err = macnet_init()) != noErr) + fatalbox("Couldn't init network (%d)", err); + s->port = port; + GetCurrentProcess(&s->psn); + err = StrToAddr(host, &s->host_info, &macnet_resolved_upp, (char *)s); + if (err != noErr) + fatalbox("Host lookup failed (%d)", err); + if (s->host_info.rtnCode != cacheFault) + macnet_resolved(&s->host_info, s); + return s; +} + +static pascal void macnet_resolved(struct hostInfo *hi, char *cookie) { + Socket *s = (Socket *)cookie; + + /* We should probably tell the process what's going on here. */ + /* Alternatively, we should kick off the next stage in the process */ + WakeUpProcess(&s->psn); +} + +/* + * Local Variables: + * c-file-style: "simon" + * End: + */ diff --git a/macnet.h b/macnet.h new file mode 100644 index 00000000..74cd6d12 --- /dev/null +++ b/macnet.h @@ -0,0 +1,42 @@ +/* + * macnet.h -- Mac OS networtking stuff for PuTTY + */ + +#ifndef _PUTTY_MACNET_H +#define _PUTTY_MACNET_H + +#include +#include +#include +#include + +typedef struct { + StreamPtr tcp_stream; + struct HostInfo host_info; + int port; + unsigned char *inbuf; + int inbuf_head, inbuf_reap, inbuf_size; + unsigned char *outbuf; + int outbuf_head, outbuf_reap, outbuf_size; + ProcessSerialNumber psn; +} Socket; + +typedef Socket *SOCKET + +#define INVALID_SOCKET NULL + +#define MSG_OOB 1 + +extern int send(SOCKET, const void *, size_t, int); +extern int recv(SOCKET, void *, size_t, int); +extern SOCKET tcp_open(const char *, int, char **); +extern void tcp_close(SOCKET); +extern void tcp_abort(SOCKET); + +#endif + +/* + * Local Variables: + * c-file-style: "simon" + * End: + */ diff --git a/telnet.c b/telnet.c index bf569b49..26cb9180 100644 --- a/telnet.c +++ b/telnet.c @@ -1,4 +1,6 @@ -#ifndef macintosh +#ifdef macintosh +#include +#else /* not macintosh */ #include #include #endif /* not macintosh */