Re: OK, I'm stumped - Why doesn't this work?
Re: OK, I'm stumped - Why doesn't this work?
- Subject: Re: OK, I'm stumped - Why doesn't this work?
- From: Quinn <email@hidden>
- Date: Wed, 24 Nov 2004 11:17:58 +0000
At 11:18 -0800 9/11/04, Dakidd wrote:
Here's the actual routine that's doing a good job of driving me bonkers:
void GetMyIPNumber(char *Storage)
{
OSStatus Error;
InetInterfaceInfo TheInfo;
SInt32 Val = kDefaultInetInterface;
// Make sure OT is alive and kicking...
if (OTInited != 1)
{
Error = InitOpenTransport();
[...]
OTInited = true;
}
else // OT is ready to roll...
{
// Clear any cruft out of the return buffer.
for (Storage[0] = 1; Storage[0] < 16;Storage[0]++)
Storage[Storage[0]] = ' ';
Storage[0] = ' ';
// Ask OT what my address is.
Error = OTInetGetInterfaceInfo(&TheInfo, Val);
[...]
}
}
I don't understand the logic of the above at all. Consider the first
invocation of this routine. There are two cases:
o If OTInited is not 1, it initialises OT but doesn't even try to
call OTInetGetInterfaceInfo, and so never returns a value to the
client.
o If OTInited is 1, it calls OTInetGetInterfaceInfo without ever
initialising OT.
The reality is that you shouldn't be initialising OT within a library
routine like this. Rather, the initialisation [1] of OT should be
managed by the top level of each code fragment. See DTS Technote
1173 "Understanding Open Transport Asset Management" for an
explanation of why.
<http://developer.apple.com/technotes/tn/tn1173.html>
[1] Also termination. Remember on traditional Mac OS quitting
without shutting down system services is a really bad idea.
On the minor nitpick side of things, you can clear memory with
OTMemzero rather than rolling your own code.
As to your specific questions...
// Invariably, "Error" returns from the above call holding -3201.
// Looking in MacErrors.h for an explanation shows two separate
// errors that map to -3201:
// kOTNotFoundErr = -3201, /* OT generic not found error */
// kENOENTErr = -3201, /* No such file or directory */
// First problem: Which error am I actually seeing?
Both errors mean the same thing. kOTNotFoundErr is a nice Mac-style
name for kENOENTErr, which in turn is the OSStatus translation of the
ENOENT error code within the OT kernel.
// Second problem: Neither one makes any sense (at least to me) in
// this context.
If TCP/IP is unloaded, there is no default interface and so I'd
expect you to get an error from OTInetGetInterfaceInfo. OTOH, if the
TCP/IP is loaded, you should get back no error and useful info. For
information about what causes the stack to load and unload, see DTS
Technote 1145 "Living in a Dynamic TCP/IP Environment".
<http://developer.apple.com/technotes/tn/tn1145.html>
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden