2003-01-11 19:43:59 +00:00
|
|
|
#include "putty.h"
|
|
|
|
#include "network.h"
|
|
|
|
#include "mac.h"
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
struct macnet_stack {
|
|
|
|
SockAddr (*namelookup)(char const *, char **);
|
|
|
|
SockAddr (*nonamelookup)(char const *);
|
|
|
|
void (*getaddr)(SockAddr, char *, int);
|
|
|
|
int (*hostname_is_local)(char *);
|
|
|
|
int (*address_is_local)(SockAddr);
|
|
|
|
int (*addrtype)(SockAddr);
|
|
|
|
void (*addrcopy)(SockAddr, char *);
|
|
|
|
void (*addr_free)(SockAddr);
|
|
|
|
Socket (*skregister)(void *, Plug); /* "register" is a reserved word */
|
|
|
|
Socket (*new)(SockAddr, int, int, int, int, Plug);
|
|
|
|
Socket (*newlistener)(char *, int, Plug, int);
|
|
|
|
char *(*addr_error)(SockAddr);
|
|
|
|
void (*poll)(void);
|
|
|
|
void (*cleanup)(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct macnet_stack *stack;
|
|
|
|
|
|
|
|
static struct macnet_stack ot = {
|
|
|
|
ot_namelookup, ot_nonamelookup, ot_getaddr, ot_hostname_is_local,
|
|
|
|
ot_address_is_local, ot_addrtype, ot_addrcopy, ot_addr_free,
|
|
|
|
ot_register, ot_new, ot_newlistener, ot_addr_error, ot_poll, ot_cleanup
|
|
|
|
};
|
|
|
|
|
2003-02-04 02:10:42 +00:00
|
|
|
#if !TARGET_API_MAC_CARBON
|
2003-01-24 00:25:33 +00:00
|
|
|
static struct macnet_stack mactcp = {
|
|
|
|
mactcp_namelookup, mactcp_nonamelookup, mactcp_getaddr,
|
|
|
|
mactcp_hostname_is_local, mactcp_address_is_local, mactcp_addrtype,
|
|
|
|
mactcp_addrcopy, mactcp_addr_free, mactcp_register, mactcp_new,
|
|
|
|
mactcp_newlistener, mactcp_addr_error, mactcp_poll, mactcp_cleanup
|
|
|
|
};
|
2003-02-04 02:10:42 +00:00
|
|
|
#endif
|
2003-01-24 00:25:33 +00:00
|
|
|
|
|
|
|
void sk_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (ot_init() == noErr)
|
|
|
|
stack = &ot;
|
|
|
|
else
|
|
|
|
#endif
|
2003-02-04 02:10:42 +00:00
|
|
|
#if !TARGET_API_MAC_CARBON
|
2003-01-24 00:25:33 +00:00
|
|
|
if (mactcp_init() == noErr)
|
|
|
|
stack = &mactcp;
|
|
|
|
else
|
2003-02-04 02:10:42 +00:00
|
|
|
#endif
|
2003-01-24 00:25:33 +00:00
|
|
|
stack = NULL;
|
|
|
|
}
|
|
|
|
|
2003-01-11 19:43:59 +00:00
|
|
|
/*
|
|
|
|
* Network functions exported to the world. These choose whether to call
|
|
|
|
* MacTCP or OpenTransport and behave accordingly.
|
|
|
|
*/
|
2003-01-12 16:11:27 +00:00
|
|
|
SockAddr sk_namelookup(char const *host, char **canonicalname)
|
2003-01-11 19:43:59 +00:00
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->namelookup(host, canonicalname);
|
|
|
|
return NULL;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
2003-01-12 16:11:27 +00:00
|
|
|
SockAddr sk_nonamelookup(char const *host)
|
2003-01-11 19:43:59 +00:00
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->nonamelookup(host);
|
|
|
|
return NULL;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sk_getaddr(SockAddr addr, char *buf, int buflen)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
stack->getaddr(addr, buf, buflen);
|
2003-01-11 19:43:59 +00:00
|
|
|
else
|
|
|
|
*buf = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
int sk_hostname_is_local(char *name)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->hostname_is_local(name);
|
|
|
|
return 0;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sk_address_is_local(SockAddr addr)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->address_is_local(addr);
|
|
|
|
return 0;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int sk_addrtype(SockAddr addr)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->addrtype(addr);
|
|
|
|
return 0;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sk_addrcopy(SockAddr addr, char *buf)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
stack->addrcopy(addr, buf);
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sk_addr_free(SockAddr addr)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
stack->addr_free(addr);
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Socket sk_register(void *sock, Plug plug)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->skregister(sock, plug);
|
|
|
|
return NULL;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
|
|
|
|
int nodelay, Plug plug)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->new(addr, port, privport, oobinline, nodelay, plug);
|
|
|
|
return NULL;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->newlistener(srcaddr, port, plug, local_host_only);
|
|
|
|
return NULL;
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *sk_addr_error(SockAddr addr)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
return stack->addr_error(addr);
|
|
|
|
return "No TCP/IP stack installed";
|
|
|
|
}
|
|
|
|
|
|
|
|
void sk_poll(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (stack != NULL)
|
|
|
|
stack->poll();
|
2003-01-11 19:43:59 +00:00
|
|
|
}
|
|
|
|
|
2003-01-11 23:33:57 +00:00
|
|
|
void sk_cleanup(void)
|
|
|
|
{
|
|
|
|
|
2003-01-24 00:25:33 +00:00
|
|
|
if (stack != NULL)
|
|
|
|
stack->cleanup();
|
2003-01-11 23:33:57 +00:00
|
|
|
}
|
|
|
|
|
2003-02-06 01:01:27 +00:00
|
|
|
/* We should use Internet Config here. */
|
|
|
|
int net_service_lookup(char *service)
|
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-11 19:43:59 +00:00
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-file-style: "simon"
|
|
|
|
* End:
|
|
|
|
*/
|
|
|
|
|