Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
ProjectBuilder (OS X)/OTEndpointInfo.c
/* |
File: OTEndpointInfo.c |
Contains: Sample to dump out the endpoint info for common OT endpoint types. |
Written by: Quinn "The Eskimo!" |
Copyright: Copyright © 1997-1999 by Apple Computer, Inc., All Rights Reserved. |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. |
("Apple") in consideration of your agreement to the following terms, and your |
use, installation, modification or redistribution of this Apple software |
constitutes acceptance of these terms. If you do not agree with these terms, |
please do not use, install, modify or redistribute this Apple software. |
In consideration of your agreement to abide by the following terms, and subject |
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs |
copyrights in this original Apple software (the "Apple Software"), to use, |
reproduce, modify and redistribute the Apple Software, with or without |
modifications, in source and/or binary forms; provided that if you redistribute |
the Apple Software in its entirety and without modifications, you must retain |
this notice and the following text and disclaimers in all such redistributions of |
the Apple Software. Neither the name, trademarks, service marks or logos of |
Apple Computer, Inc. may be used to endorse or promote products derived from the |
Apple Software without specific prior written permission from Apple. Except as |
expressly stated in this notice, no other rights or licenses, express or implied, |
are granted by Apple herein, including but not limited to any patent rights that |
may be infringed by your derivative works or by other works in which the Apple |
Software may be incorporated. |
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN |
COMBINATION WITH YOUR PRODUCTS. |
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION |
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT |
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Change History (most recent first): |
7/2003 MK Updated for Project Builder |
7/22/1999 KG Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
// The OT debugging macros in <OTDebug.h> require this variable to |
// be set. |
#include <Carbon/Carbon.h> |
#ifndef qDebug |
#define qDebug 1 |
#endif |
///////////////////////////////////////////////////////////////////// |
// Pick up all the standard OT stuff. |
//%#include <OpenTransport.h> |
///////////////////////////////////////////////////////////////////// |
// Pick up device type definitions. |
//%#include <OpenTptLinks.h> |
///////////////////////////////////////////////////////////////////// |
// Pick up device type definitions. |
//%#include <OpenTptAppleTalk.h> |
///////////////////////////////////////////////////////////////////// |
// Pick up device type definitions. |
//%#include <OpenTptInternet.h> |
///////////////////////////////////////////////////////////////////// |
// Pick up the OTDebugBreak and OTAssert macros. |
//%#include <OTDebug.h> |
///////////////////////////////////////////////////////////////////// |
// Standard C prototypes. |
#include <stdio.h> |
///////////////////////////////////////////////////////////////////// |
// OTDebugStr is not defined in any OT header files, but it is |
// exported by the libraries, so we define the prototype here. |
extern pascal void OTDebugStr(const char* str); |
///////////////////////////////////////////////////////////////////// |
/******************************************************************************* |
** EndPointInfo |
********************************************************************************/ |
enum { |
kNumberOfServiceTypeNames = 8 |
}; |
static char *gServiceTypeConstants[kNumberOfServiceTypeNames] = { |
"unknown", |
"T_COTS", |
"T_COTS_ORD", |
"T_CLTS", |
"unknown", |
"T_TRANS", |
"T_TRANS_ORD", |
"T_TRANS_CLTS" |
}; |
static char *gServiceTypeDescriptions[kNumberOfServiceTypeNames] = { |
"unknown", |
"Connection-oriented, transactionless", |
"Connection-oriented, transactionless, orderly release", |
"Connectionless, transactionless", |
"unknown", |
"Connection-oriented, transaction", |
"Connection-oriented, transaction, orderly release", |
"Connectionless, transaction" |
}; |
static void PrintFlag(char *flagName, UInt32 flagField, UInt32 flagMask) |
// If the flagMask bit in flagField is set, print the flagName |
// string. |
{ |
printf(" %s = %d\n", flagName, (flagField & flagMask) != 0); |
} |
static void ValueToString(SInt32 value, char *valueString) |
// Convert value to a string and put it in valueString, |
// formatting the two special case values appropriately. |
{ |
switch (value) { |
case T_INFINITE: |
sprintf(valueString, "T_INFINITE (%ld)", value); |
break; |
case T_INVALID: |
sprintf(valueString, "T_INVALID (%ld)", value); |
break; |
default: |
sprintf(valueString, "%ld", value); |
break; |
} |
} |
static void OpenEndpointAndPrintInfo(char *config) |
// Open an endpoint with the given configuration, call |
// OTGetEndpointInfo to get the endpoint information, |
// and print that out in a nicely formatted manner. |
{ |
OSStatus err; |
EndpointRef ep; |
TEndpointInfo epInfo; |
char *serviceTypeConstant; |
char *serviceTypeDescription; |
char valueString[256]; |
ep = OTOpenEndpointInContext(OTCreateConfiguration(config), 0, &epInfo, &err, NULL); |
if (err == noErr) { |
printf("TEndpointInfo for Ò%sÓ\n", config); |
ValueToString(epInfo.addr, valueString); |
printf(" addr (max size of address) = %s\n", valueString); |
ValueToString(epInfo.options, valueString); |
printf(" options (max size of options) = %s\n", valueString); |
ValueToString(epInfo.tsdu, valueString); |
printf(" tsdu (max size of data unit) = %s\n", valueString); |
ValueToString(epInfo.etsdu, valueString); |
printf(" etsdu (max size of expedited data unit) = %s\n", valueString); |
ValueToString(epInfo.connect, valueString); |
printf(" connect (max size of connect data) = %s\n", valueString); |
ValueToString(epInfo.discon, valueString); |
printf(" discon (max size of disconnect data) = %s\n", valueString); |
if (epInfo.servtype >= 0 && epInfo.servtype < kNumberOfServiceTypeNames) { |
serviceTypeConstant = gServiceTypeConstants[epInfo.servtype]; |
serviceTypeDescription = gServiceTypeDescriptions[epInfo.servtype]; |
} else { |
serviceTypeConstant = "unknown"; |
serviceTypeDescription = "unknown"; |
}; |
printf(" servtype = %s (%ld)\n", serviceTypeConstant, epInfo.servtype); |
printf(" (%s)\n", serviceTypeDescription); |
printf(" flags = $%08x\n", (unsigned int) epInfo.flags); |
PrintFlag("T_SENDZERO (can send 0 byte units) ", epInfo.flags, T_SENDZERO); |
PrintFlag("T_XPG4_1 (supports GetProtAddress) ", epInfo.flags, T_XPG4_1); |
PrintFlag("CAN_RESOLVE_ADDR (supports ResolveAddress)", epInfo.flags, T_CAN_RESOLVE_ADDR); |
PrintFlag("CAN_SUPPLY_MIB (SNMP) ", epInfo.flags, T_CAN_SUPPLY_MIB); |
PrintFlag("T_CAN_SUPPORT_MDATA (support M_DATA mode) ", epInfo.flags, T_CAN_SUPPORT_MDATA); |
(void) OTCloseProvider(ep); |
}; |
if (err != noErr) { |
printf("OpenEndpointAndPrintInfo(%s) = %d\n", config, (int) err); |
}; |
printf("\n"); |
} |
static void EndpointInfo(void) |
{ |
OpenEndpointAndPrintInfo(kEnetName); |
OpenEndpointAndPrintInfo(kRawIPName); |
OpenEndpointAndPrintInfo(kUDPName); |
OpenEndpointAndPrintInfo(kTCPName); |
OpenEndpointAndPrintInfo(kDDPName); |
OpenEndpointAndPrintInfo(kATPName); |
OpenEndpointAndPrintInfo(kPAPName); |
OpenEndpointAndPrintInfo(kADSPName); |
} |
///////////////////////////////////////////////////////////////////// |
int main(void) |
{ |
OSStatus err; |
printf("OTEndpointInfo\n"); |
printf("-- Prints TEndpointInfo for common endpoint configurations.\n"); |
printf("-- This is for informational purposes only, don't even think\n"); |
printf("-- about hard-coding any of these values! If you need them you\n"); |
printf("-- should fetch them at run time using OTGetEndpointInfo.\n"); |
printf("\n"); |
err = InitOpenTransportInContext(kInitOTForApplicationMask, NULL); |
if (err == noErr) { |
EndpointInfo(); |
CloseOpenTransportInContext( NULL ); |
} |
if (err == noErr) { |
printf("Success.\n"); |
} else { |
printf("Failed with error %d.\n", (int) err); |
} |
return 0; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-08-20