2 * Copyright (c) 2003 Ben Harris
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without
8 * restriction, including without limitation the rights to use,
9 * copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
22 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * mtcpnet.c - MacTCP interface
35 #include <MixedMode.h>
36 #include <Resources.h>
40 #define DEFINE_PLUG_METHOD_MACROS
46 * The following structures are documented as being in
47 * <AddressXlation.h>, but that isn't shipped with Universal
48 * Interfaces, and it's easier to define them here than to require
49 * people to download yet another SDK.
52 static OSErr
OpenResolver(char *);
53 static OSErr
CloseResolver(void);
66 #define NUM_ALT_ADDRS 4
68 typedef struct hostInfo
{
71 unsigned long addr
[NUM_ALT_ADDRS
];
74 typedef CALLBACK_API(void, ResultProcPtr
)(struct hostInfo
*, char *);
75 typedef STACK_UPP_TYPE(ResultProcPtr
) ResultUPP
;
76 enum { uppResultProcInfo
= kPascalStackBased
77 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(struct hostInfo
*)))
78 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
80 #define NewResultUPP(userRoutine) \
81 (ResultUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), \
83 GetCurrentArchitecture())
84 #define DisposeResultUPP(userUPP) DisposeRoutineDescriptor(userUPP)
86 static OSErr
StrToAddr(char *, struct hostInfo
*, ResultUPP
*, char *);
88 typedef CALLBACK_API_C(OSErr
, OpenResolverProcPtr
)(UInt32
, char *);
89 typedef STACK_UPP_TYPE(OpenResolverProcPtr
) OpenResolverUPP
;
90 enum { uppOpenResolverProcInfo
= kCStackBased
91 | RESULT_SIZE(SIZE_CODE(sizeof(OSErr
)))
92 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32
)))
93 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
95 #define InvokeOpenResolverUPP(selector, fileName, userUPP) \
96 CALL_TWO_PARAMETER_UPP((userUPP), uppOpenResolverProcInfo, \
97 (selector), (fileName))
99 typedef CALLBACK_API_C(OSErr
, CloseResolverProcPtr
)(UInt32
);
100 typedef STACK_UPP_TYPE(CloseResolverProcPtr
) CloseResolverUPP
;
101 enum { uppCloseResolverProcInfo
= kCStackBased
102 | RESULT_SIZE(SIZE_CODE(sizeof(OSErr
)))
103 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32
)))
105 #define InvokeCloseResolverUPP(selector, userUPP) \
106 CALL_ONE_PARAMETER_UPP((userUPP), uppCloseResolverProcInfo, (selector))
108 typedef CALLBACK_API_C(OSErr
, StrToAddrProcPtr
)(UInt32
, char *,
109 struct hostInfo
*, ResultUPP
,
111 typedef STACK_UPP_TYPE(StrToAddrProcPtr
) StrToAddrUPP
;
112 enum { uppStrToAddrProcInfo
= kCStackBased
113 | RESULT_SIZE(SIZE_CODE(sizeof(OSErr
)))
114 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(UInt32
)))
115 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
116 | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct hostInfo
*)))
117 | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(ResultUPP
)))
118 | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char *)))
120 #define InvokeStrToAddrUPP(selector, hostName, hostInfoPtr, ResultProc, \
121 userDataPtr, userUPP) \
122 CALL_FIVE_PARAMETER_UPP((userUPP), uppStrToAddrProcInfo, (selector),\
123 (hostName), (hostInfoPtr), (ResultProc), \
125 #define StrToAddr(hostName, hostInfoPtr, ResultProc, userDataPtr) \
126 InvokeStrToAddrUPP(STRTOADDR, hostName, hostInfoPtr, ResultProc, \
127 userDataPtr, (StrToAddrUPP)*mactcp.dnr_handle)
129 typedef CALLBACK_API_C(OSErr
, AddrToStrProcPtr
)(UInt32
, unsigned long, char *);
130 typedef STACK_UPP_TYPE(AddrToStrProcPtr
) AddrToStrUPP
;
131 enum { uppAddrToStrProcInfo
= kCStackBased
132 | RESULT_SIZE(SIZE_CODE(sizeof(OSErr
)))
133 | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned long)))
134 | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *)))
136 #define InvokeAddrToStrUPP(selector, addr, addrStr, userUPP) \
137 CALL_THREE_PARAMETER_UPP((userUPP), uppAddrToStrProcInfo, (selector),\
139 #define AddrToStr(addr, addrStr) \
140 InvokeAddrToStrUPP(ADDRTOSTR, addr, addrStr, \
141 (AddrToStrUPP)*mactcp.dnr_handle)
143 /* End of AddressXlation.h bits */
145 /* TCP connection states, mysteriously missing from <MacTCP.h> */
146 #define TCPS_CLOSED 0
147 #define TCPS_LISTEN 2
148 #define TCPS_SYN_RECEIVED 4
149 #define TCPS_SYN_SENT 6
150 #define TCPS_ESTABLISHED 8
151 #define TCPS_FIN_WAIT_1 10
152 #define TCPS_FIN_WAIT_2 12
153 #define TCPS_CLOSE_WAIT 14
154 #define TCPS_CLOSING 16
155 #define TCPS_LAST_ACK 18
156 #define TCPS_TIME_WAIT 20
159 struct socket_function_table
*fn
;
160 /* the above variable absolutely *must* be the first in this structure */
165 bufchain output_data
;
168 int frozen
; /* this causes readability notifications to be ignored */
169 int frozen_readable
; /* this means we missed at least one readability
170 * notification while we were frozen */
171 int localhost_only
; /* for listening sockets */
174 int oobpending
; /* is there OOB data available to read? */
176 int pending_error
; /* in case send() returns error */
178 struct Socket_tag
*next
;
179 struct Socket_tag
**prev
;
183 * We used to typedef struct Socket_tag *Socket.
185 * Since we have made the networking abstraction slightly more
186 * abstract, Socket no longer means a tcp socket (it could mean
187 * an ssl socket). So now we must use Actual_Socket when we know
188 * we are talking about a tcp socket.
190 typedef struct Socket_tag
*Actual_Socket
;
192 struct SockAddr_tag
{
194 struct hostInfo hostinfo
;
198 /* Global variables */
203 ProcessSerialNumber self
;
204 Actual_Socket socklist
;
207 static pascal void mactcp_lookupdone(struct hostInfo
*hi
, char *cookie
);
208 static pascal void mactcp_asr(StreamPtr
, unsigned short, Ptr
, unsigned short,
209 struct ICMPReport
*);
210 static Plug
mactcp_plug(Socket
, Plug
);
211 static void mactcp_flush(Socket
);
212 static void mactcp_close(Socket
);
213 static int mactcp_write(Socket
, char const *, int);
214 static int mactcp_write_oob(Socket
, char const*, int);
215 static void mactcp_set_private_ptr(Socket
, void *);
216 static void *mactcp_get_private_ptr(Socket
);
217 static char *mactcp_socket_error(Socket
);
218 static void mactcp_set_frozen(Socket
, int);
220 static void mactcp_recv(Actual_Socket s
, size_t len
);
224 * This should be called once before any TCP connection is opened.
227 OSErr
mactcp_init(void)
232 * IM:Devices describes a convoluted way of finding a spare unit
233 * number to open a driver on before calling OpenDriver. Happily,
234 * the MacTCP INIT ensures that .IPP is already open (and hence
235 * has a valid unit number already) so we don't need to go through
236 * all that. (MacTCP Programmer's Guide p6)
238 err
= OpenDriver("\p.IPP", &mactcp
.refnum
);
239 if (err
!= noErr
) return err
;
240 err
= OpenResolver(NULL
);
241 if (err
!= noErr
) return err
;
243 mactcp
.initialised
= TRUE
;
247 void mactcp_shutdown(void)
249 Actual_Socket s
, next
;
252 * Eventually, PuTTY should close down each session as it exits,
253 * so there should be no sockets left when we get here. Still,
254 * better safe than sorry.
256 * XXX What about in-flight aync I/O (when we support that)?
258 for (s
= mactcp
.socklist
; s
!= NULL
; s
= next
) {
259 next
= s
->next
; /* s is about to vanish */
260 mactcp_close(&s
->fn
);
264 * When we get async DNS, we have to wait for any outstanding
265 * requests to complete here before exiting.
268 mactcp
.initialised
= FALSE
;
271 static ResultUPP mactcp_lookupdone_upp
;
273 SockAddr
mactcp_namelookup(char *host
, char **canonicalname
)
275 SockAddr ret
= smalloc(sizeof(struct SockAddr_tag
));
277 volatile int done
= FALSE
;
280 /* Clear the structure. */
281 memset(ret
, 0, sizeof(struct SockAddr_tag
));
282 if (mactcp_lookupdone_upp
== NULL
)
283 mactcp_lookupdone_upp
= NewResultUPP(&mactcp_lookupdone
);
284 err
= StrToAddr(host
, &ret
->hostinfo
, mactcp_lookupdone_upp
,
287 * PuTTY expects DNS lookups to be synchronous (see bug
288 * "async-dns"), so we pretend they are.
290 if (err
== cacheFault
)
293 ret
->resolved
= TRUE
;
295 if (ret
->hostinfo
.rtnCode
== noErr
)
296 realhost
= ret
->hostinfo
.cname
;
299 *canonicalname
= smalloc(1+strlen(realhost
));
300 strcpy(*canonicalname
, realhost
);
304 static pascal void mactcp_lookupdone(struct hostInfo
*hi
, char *cookie
)
306 volatile int *donep
= (int *)cookie
;
311 SockAddr
mactcp_nonamelookup(char *host
)
313 SockAddr ret
= smalloc(sizeof(struct SockAddr_tag
));
315 ret
->resolved
= FALSE
;
316 ret
->hostinfo
.rtnCode
= noErr
;
317 ret
->hostname
[0] = '\0';
318 strncat(ret
->hostname
, host
, lenof(ret
->hostname
) - 1);
322 void mactcp_getaddr(SockAddr addr
, char *buf
, int buflen
)
327 if (addr
->resolved
) {
328 /* XXX only return first address */
329 err
= AddrToStr(addr
->hostinfo
.addr
[0], mybuf
);
332 strncat(buf
, mybuf
, buflen
- 1);
335 strncat(buf
, addr
->hostname
, buflen
- 1);
339 /* I think "local" here really means "loopback" */
341 int mactcp_hostname_is_local(char *name
)
344 return !strcmp(name
, "localhost");
347 int mactcp_address_is_local(SockAddr addr
)
352 for (i
= 0; i
< NUM_ALT_ADDRS
; i
++)
353 if (addr
->hostinfo
.addr
[i
] & 0xff000000 == 0x7f000000)
358 int mactcp_addrtype(SockAddr addr
)
362 return ADDRTYPE_IPV4
;
363 return ADDRTYPE_NAME
;
366 void mactcp_addrcopy(SockAddr addr
, char *buf
)
369 /* XXX only return first address */
370 memcpy(buf
, &addr
->hostinfo
.addr
[0], 4);
373 void mactcp_addr_free(SockAddr addr
)
379 static Plug
mactcp_plug(Socket sock
, Plug p
)
381 Actual_Socket s
= (Actual_Socket
) sock
;
389 static void mactcp_flush(Socket s
)
392 fatalbox("mactcp_flush");
395 Socket
mactcp_register(void *sock
, Plug plug
)
398 fatalbox("mactcp_register");
401 static TCPNotifyUPP mactcp_asr_upp
;
403 Socket
mactcp_new(SockAddr addr
, int port
, int privport
, int oobinline
,
404 int nodelay
, Plug plug
)
406 static struct socket_function_table fn_table
= {
412 mactcp_set_private_ptr
,
413 mactcp_get_private_ptr
,
424 * Create Socket structure.
426 ret
= smalloc(sizeof(struct Socket_tag
));
431 bufchain_init(&ret
->output_data
);
432 ret
->connected
= 0; /* to start with */
433 ret
->writable
= 0; /* to start with */
434 ret
->sending_oob
= 0;
436 ret
->frozen_readable
= 0;
437 ret
->localhost_only
= 0; /* unused, but best init anyway */
438 ret
->pending_error
= 0;
439 ret
->oobinline
= oobinline
;
440 ret
->oobpending
= FALSE
;
443 dstaddr
= addr
->hostinfo
.addr
[0]; /* XXX should try all of them */
445 * Create a TCP stream.
447 * MacTCP requires us to provide it with some buffer memory. Page
448 * 31 of the Programmer's Guide says it should be a minimum of
449 * 4*MTU+1024. Page 36 says a minimum of 4096 bytes. Assume
450 * they're both correct.
452 assert(addr
->resolved
);
453 upb
.ioCRefNum
= mactcp
.refnum
;
454 upb
.csCode
= UDPMaxMTUSize
;
455 upb
.csParam
.mtu
.remoteHost
= dstaddr
;
456 upb
.csParam
.mtu
.userDataPtr
= NULL
;
457 ret
->err
= PBControlSync((ParmBlkPtr
)&upb
);
458 if (ret
->err
!= noErr
) return (Socket
)ret
;
460 buflen
= upb
.csParam
.mtu
.mtuSize
* 4 + 1024;
461 if (buflen
< 4096) buflen
= 4096;
462 if (mactcp_asr_upp
== NULL
)
463 mactcp_asr_upp
= NewTCPNotifyUPP(&mactcp_asr
);
464 GetCurrentProcess(&mactcp
.self
);
465 pb
.ioCRefNum
= mactcp
.refnum
;
466 pb
.csCode
= TCPCreate
;
467 pb
.csParam
.create
.rcvBuff
= smalloc(buflen
);
468 pb
.csParam
.create
.rcvBuffLen
= buflen
;
469 pb
.csParam
.create
.notifyProc
= mactcp_asr_upp
;
470 pb
.csParam
.create
.userDataPtr
= (Ptr
)ret
;
471 ret
->err
= PBControlSync((ParmBlkPtr
)&pb
);
472 if (ret
->err
!= noErr
) return (Socket
)ret
;
473 ret
->s
= pb
.tcpStream
;
476 * Open the connection.
478 pb
.ioCRefNum
= mactcp
.refnum
;
479 pb
.csCode
= TCPActiveOpen
;
480 pb
.tcpStream
= ret
->s
;
481 pb
.csParam
.open
.validityFlags
= 0;
482 pb
.csParam
.open
.remoteHost
= dstaddr
;
483 pb
.csParam
.open
.remotePort
= port
;
484 pb
.csParam
.open
.localPort
= privport ?
1023 : 0;
485 pb
.csParam
.open
.dontFrag
= FALSE
;
486 pb
.csParam
.open
.timeToLive
= 0;
487 pb
.csParam
.open
.security
= 0;
488 pb
.csParam
.open
.optionCnt
= 0;
489 pb
.csParam
.open
.userDataPtr
= (Ptr
)ret
;
491 ret
->err
= PBControlSync((ParmBlkPtr
)&pb
);
492 if (!privport
|| ret
->err
!= duplicateSocket
)
494 pb
.csParam
.open
.localPort
--;
495 if (pb
.csParam
.open
.localPort
== 0)
499 if (ret
->err
!= noErr
) return (Socket
)ret
;
501 ret
->connected
= TRUE
;
502 ret
->writable
= TRUE
;
504 /* Add this to the list of all sockets */
505 ret
->next
= mactcp
.socklist
;
506 ret
->prev
= &mactcp
.socklist
;
507 ret
->next
->prev
= &ret
->next
;
508 mactcp
.socklist
= ret
;
513 Socket
mactcp_newlistener(char *srcaddr
, int port
, Plug plug
,
517 fatalbox("mactcp_newlistener");
520 static void mactcp_close(Socket sock
)
522 Actual_Socket s
= (Actual_Socket
)sock
;
526 * TCPClose is equivalent to shutdown(fd, SHUT_WR), and hence
527 * leaves the Rx side open, while TCPAbort seems rather vicious,
528 * throwing away Tx data that haven't been ACKed yet. We do both
531 pb
.ioCRefNum
= mactcp
.refnum
;
532 pb
.csCode
= TCPClose
;
534 pb
.csParam
.close
.validityFlags
= 0;
535 pb
.csParam
.close
.userDataPtr
= (Ptr
)s
;
536 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
537 /* Not much we can do about an error anyway. */
539 pb
.ioCRefNum
= mactcp
.refnum
;
540 pb
.csCode
= TCPAbort
;
542 pb
.csParam
.abort
.userDataPtr
= (Ptr
)s
;
543 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
544 /* Even less we can do about an error here. */
546 pb
.ioCRefNum
= mactcp
.refnum
;
547 pb
.csCode
= TCPRelease
;
549 pb
.csParam
.create
.userDataPtr
= (Ptr
)s
;
550 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
552 sfree(pb
.csParam
.create
.rcvBuff
);
554 /* Unhitch from list of sockets */
557 s
->next
->prev
= s
->prev
;
562 static int mactcp_write(Socket sock
, char const *buf
, int len
)
564 Actual_Socket s
= (Actual_Socket
) sock
;
569 * Casting away const from buf should be safe -- MacTCP won't
573 wds
[0].ptr
= (char *)buf
;
576 pb
.ioCRefNum
= mactcp
.refnum
;
579 pb
.csParam
.send
.validityFlags
= 0;
580 pb
.csParam
.send
.pushFlag
= TRUE
; /* XXX we want it to return. */
581 pb
.csParam
.send
.urgentFlag
= 0;
582 pb
.csParam
.send
.wdsPtr
= (Ptr
)wds
;
583 pb
.csParam
.send
.userDataPtr
= (Ptr
)s
;
584 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
588 static int mactcp_write_oob(Socket sock
, char const *buf
, int len
)
591 fatalbox("mactcp_write_oob");
594 static pascal void mactcp_asr(StreamPtr str
, unsigned short event
, Ptr cookie
,
595 unsigned short termin_reason
,
596 struct ICMPReport
*icmp
)
599 WakeUpProcess(&mactcp
.self
);
603 * Called from our event loop if there's work to do.
605 void mactcp_poll(void)
607 Actual_Socket s
, next
;
610 for (s
= mactcp
.socklist
; s
!= NULL
; s
= next
) {
613 pb
.ioCRefNum
= mactcp
.refnum
;
614 pb
.csCode
= TCPStatus
;
616 pb
.csParam
.status
.userDataPtr
= (Ptr
)s
;
617 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
620 if (pb
.csParam
.status
.amtUnreadData
== 0)
622 mactcp_recv(s
, pb
.csParam
.status
.amtUnreadData
);
624 switch (pb
.csParam
.status
.connectionState
) {
625 case TCPS_CLOSE_WAIT
:
626 /* Remote end has sent us a FIN */
627 plug_closing(s
->plug
, NULL
, 0, 0);
634 static void mactcp_recv(Actual_Socket s
, size_t len
)
639 if (s
->frozen
) return;
642 pb
.ioCRefNum
= mactcp
.refnum
;
643 pb
.csCode
= TCPNoCopyRcv
;
645 pb
.csParam
.receive
.commandTimeoutValue
= 0;
646 pb
.csParam
.receive
.rdsPtr
= (Ptr
)rds
;
647 pb
.csParam
.receive
.rdsLength
= lenof(rds
) - 1;
648 pb
.csParam
.receive
.userDataPtr
= (Ptr
)s
;
649 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
652 plug_receive(s
->plug
, 0, rds
[0].ptr
, rds
[0].length
);
653 len
-= rds
[0].length
;
654 pb
.csCode
= TCPRcvBfrReturn
;
655 s
->err
= PBControlSync((ParmBlkPtr
)&pb
);
662 * Each socket abstraction contains a `void *' private field in
663 * which the client can keep state.
665 static void mactcp_set_private_ptr(Socket sock
, void *ptr
)
667 Actual_Socket s
= (Actual_Socket
) sock
;
668 s
->private_ptr
= ptr
;
671 static void *mactcp_get_private_ptr(Socket sock
)
673 Actual_Socket s
= (Actual_Socket
) sock
;
674 return s
->private_ptr
;
678 * Special error values are returned from mactcp_namelookup and
679 * mactcp_new if there's a problem. These functions extract an error
680 * message, or return NULL if there's no problem.
682 char *mactcp_addr_error(SockAddr addr
)
686 switch (addr
->hostinfo
.rtnCode
) {
690 return "Name syntax error";
692 return "No name server found";
694 return "Domain name does not exist";
696 return "No answer from domain name server";
698 return "Domain name server returned an error";
700 return "Out of memory";
702 sprintf(buf
, "Unknown DNR error %d", addr
->hostinfo
.rtnCode
);
707 static char *mactcp_socket_error(Socket sock
)
710 Actual_Socket s
= (Actual_Socket
) sock
;
715 case insufficientResources
:
716 return "Insufficient resources to open TCP stream";
717 case duplicateSocket
:
718 return "Duplicate socket";
720 return "Connection failed while opening";
722 sprintf(buf
, "Unknown MacTCP error %d", s
->err
);
727 static void mactcp_set_frozen(Socket sock
, int is_frozen
)
729 Actual_Socket s
= (Actual_Socket
) sock
;
731 if (s
->frozen
== is_frozen
)
733 s
->frozen
= is_frozen
;
737 * Bits below here would usually be in dnr.c, shipped with the MacTCP
738 * SDK, but its convenient not to require that, and since we assume
739 * System 7 we can actually simplify things a lot.
742 static OSErr
OpenResolver(char *hosts_file
)
752 if (mactcp
.dnr_handle
!= NULL
)
755 err
= FindFolder(kOnSystemDisk
, kControlPanelFolderType
, FALSE
, &vrefnum
,
757 if (err
!= noErr
) return err
;
760 * Might be better to use PBCatSearch here, but it's not always
763 pb
.fileParam
.ioCompletion
= NULL
;
764 pb
.fileParam
.ioNamePtr
= filename
;
765 pb
.fileParam
.ioVRefNum
= vrefnum
;
766 pb
.fileParam
.ioFDirIndex
= 1;
767 pb
.fileParam
.ioDirID
= dirid
;
770 while (PBHGetFInfoSync(&pb
) == noErr
) {
771 if (pb
.fileParam
.ioFlFndrInfo
.fdType
== 'cdev' &&
772 pb
.fileParam
.ioFlFndrInfo
.fdCreator
== 'ztcp') {
773 fd
= HOpenResFile(vrefnum
, dirid
, filename
, fsRdPerm
);
774 if (fd
== -1) continue;
775 dnr_handle
= Get1IndResource('dnrp', 1);
776 if (dnr_handle
!= NULL
)
781 pb
.fileParam
.ioDirID
= dirid
;
782 pb
.fileParam
.ioFDirIndex
++;
787 DetachResource(dnr_handle
);
793 err
= InvokeOpenResolverUPP(OPENRESOLVER
, hosts_file
,
794 (OpenResolverUPP
)*dnr_handle
);
797 DisposeHandle(dnr_handle
);
801 mactcp
.dnr_handle
= dnr_handle
;
805 OSErr
CloseResolver(void)
807 Handle dnr_handle
= mactcp
.dnr_handle
;
810 if (mactcp
.dnr_handle
== NULL
)
813 err
= InvokeCloseResolverUPP(CLOSERESOLVER
,
814 (CloseResolverUPP
)*mactcp
.dnr_handle
);
818 mactcp
.dnr_handle
= NULL
;
820 DisposeHandle(dnr_handle
);
824 /* MacTCP doesn't have a services database. */
825 int net_service_lookup(char *service
)
834 * c-file-style: "simon"