TweetFollow Us on Twitter

ATalk Server
Volume Number:1
Issue Number:10
Column Tag:C Workshop

"Dial a Fortune Apple Talk Server"

By Robert B. Denny, Timothy T. Coad, Alisa Systems, Inc., MacTutor Editorial Board

It's been about six months since the AppleTalk network was released. Yet there seems to be little software available which uses this network. One reason is that the market is too small as yet and developers can't see enough potential to risk the investment. Another reason is that AppleTalk applications appear difficult to implement, requiring a great deal of knowledge and understanding that is not easy to obtain. Last, but certainly not least, Apple has failed to complete the basic services that history has shown are required for successful introduction of a computer network.

About six or seven months ago, Apple released a publication called Inside AppleTalk, available from the same source as Inside Macintosh. In addition, most developers who subscribed to the Apple "Software Supplement" have received The AppleTalk Manager: A Programmer's Guide, a part of Inside AppleTalk. These documents do a fairly good job of describing the network architecture and the details of using the AppleTalk services. If you have no experience with local area networks, however, you may get lost in the jargon and fail to "see the forest through the trees".

This month's C Workshop is devoted to AppleTalk. It includes a complete server application called Confucious which, when run on a Mac connected to the network, provides a "guru" service. A Mac Pascal client application is described by Alan Wootton in a separate article in this issue of Mac Tutor. The Pascal client, running on another Mac, locates the C server and makes requests for pearls of wisdom, which the server gladly sends back.

In order to keep this article's size reasonable, we assume that (1) you understand how to use the Mac's I/O services and (2) you have access to (at least) the AppleTalk Manager Programmer's Guide. The article describes the overall architecture of the AppleTalk network, and concludes with a listing of the server's code, written mostly in C. We'll look at programming details next month.

Fig. 1 - AppleTalk Components

NOTE: The descriptions given in this article are simplified so as to make it easier to understand the overall architecture of AppleTalk. Please consult the Apple documentation for full details.

Protocols and Layers

The lifeblood of any network is its suite of protocols that are used to negotiate and communicate. Usually, there are two agents in a network operation, the client and the server. The operation consists of a set of information exchanges between the client and the server, according to a protocol.

In order to bring some order to the chaos that would be created by a multitude of protocols, some of which are clients of other protocols and servers to yet others, network designers use the concepts of layers and interfaces. A layer implements a set of services via an interface. For example, the file system on the Mac has a layer that handles "raw" disk I/O (the device manager), and a layer on top of that which handles the organization of data on the disk into files and directories (the file manager). This separation of functions makes it possible to handle both hard disks and floppies with the same file manager routines. The file manager uses a defined interface to the device manager for its requests. Finally, the organization of data on the disk as files and directories is a sort of "spatial protocol".

Network architectures are normally divided into seven layers, according to the ISO "Open Systems Interconnection" convention adopted about five years ago. These layers, from lowest to highest are:

Physical: Electrical and mechanical aspects of communication circuits.

Data Link: Data and frame formats, bus access & contention protocols, error detection, other low level link services.

Network: Addressing and routing of messages between "sockets" transparently across multiple data links.

Transport: Error and flow control between sockets. Exchanges of information between routing agents on special sockets.

Session: Opening and closing logical links between sockets. Starting up remote servers on request. Naming of entities and name services.

Presentation: Cryptosystems, code conversion (e.g., ASCII to EBCDIC), other transformations needed for the native application environment.

Application: Protocols used between specific applications.

AppleTalk Architecture

Apple Computer has so far defined and published protocols for the physical through the transport layers of AppleTalk. Generally speaking, AppleTalk has a bus oriented, packet-based architecture, supporting internetworking, named objects, adaptive routing and a transaction-oriented transport service.

Services are implemented in a pair of I/O drivers and associated resources which are opened permanently on 512K Macs, and live in the system heap. On 128K Macs, applications which want to use the network must manually open the drivers, loading them into the application heap. This means that no "detached" service processes in the system heap can be supported on the smaller systems. Figure 1 shows the breakdown of AppleTalk functions and the drivers that implement them.

Physical & Data Link Layers: ALAP

The physical layer consists of a bus topology twisted-pair cable carrying electrical signals conforming to the EIA RS-422 standard. The Mac hardware has a "serial communications controller" (SCC) which is capable of being software configured as a standard async or sync port, or as an AppleTalk port. AppleTalk uses the printer port on the Mac.

The data link layer is implemented in software and uses the "AppleTalk Link Access Protocol" (ALAP) to manage usage of the common bus and to detect transmission errors between physically connected Mac systems. ALAP uses a frame format which is similar to that used by several well known block-oriented protocols such as HDLC. The algorithms used to manage multiple access to the bus are specific to AppleTalk, and fall into the category of "Carrier Sense Multiple Access" (CSMA).

Simply stated, the rules of CSMA are: (1) talk if no one else is talking; (2) if you want to talk and some one else is already talking, go away and try again later; (3) if two of you start talking at the same time, yell "Abort!" so everyone else knows, then both of you go away and try again later.

One other thing to note: The assignment of node numbers to each station on a network is not done by the user. Rather, the ALAP software tries to assign a random node number when the Mac is booted, then shouts it out over the net. If no one else objects, that is the node number to be used. Otherwise, another try is made.As an application developer, you'll rarely deal directly with ALAP.

Network Layer: DDP

The network layer uses the "Datagram Delivery Protocol" (DDP), which defines the format of the address header which is included in each packet and which stays with the packet between cooperating processes through communication endpoints called sockets. The path between sockets may span several physical links, and may go through intermediate systems. One Mac may have several AppleTalk connections open at a time, so the node number is not enough to identify a network address.

An address must consist of at least a node number and a socket number. In fact, AppleTalk considers a socket to be the one and only network-visible entity. Socket numbers fall into two groups. The "well-known" sockets (1-127) are assigned by Apple for specific generic network services and experimentation. The others (128-254) are called "dynamic" sockets. They are assigned temporarily and are often associated with a name managed by the Name Binding service of AppleTalk (see below).

Individual AppleTalk networks may be tied together to form an internetwork. Node numbers are unique only within a single physical network, so DDP requires that each network be assigned a network number. Figure 2 (see top of next page) shows a three-net internetwork. The Networks are connected by either a full bridge or a pair of half-bridges. The full bridge attaches directly to two physical networks and provides datagram routing from one to the other. The pair of half bridges does the same thing, but they use an intermediate transmission medium such as a long-distance telephone line.

Fig. 2 - An AppleTalk Internetwork

DDP defines an internet address consisting of a net number, a node number and a socket number. One might argue that the net number is superfluous, since the node number could be made unique within the entire internet. True, but the early local net designers at Xerox PARC decided that routing overhead should be minimized.

The key to their idea is that many nodes are attached to a single network, and that getting the packet to the proper local network is all that's needed to get it to the destination node. Normally, there are far fewer networks than nodes, so the routers have a much easier task. AppleTalk incorporates this network-oriented routing system.

The basic service provided by DDP is to "try its best" to get a packet from the source to the destination. If there is a problem somewhere, the packet is vaporized. DDP doesn't care about the details of link management or signalling, it only needs some sort of link service to it's neighbors in the net. Application developers rarely use the datagram services directly.

Routing Services: RTMP

The DDP internet routing process requires information as to the topology (interconnect configuration) of the internet. Each router involved in getting a DDP datagram from the source to the destination net must know where to send the datagram next. The routers use a set of routing tables to maintain this information.

The tables consist of a list of net numbers paired with the local node number of the bridge through which the shortest path to that net exists. These tables are dynamically constructed and maintained, with no need for a network manager to describe the topology. Automatic routing table maintenance is done by the routers carrying on a continuous chit-chat, proclaiming themselves as routers and broadcasting routing information for other routers, using the Routing Table Maintenance Protocol (RTMP).

Routing information exchange uses DDP at its communication medium, via socket number 1. Each Mac has a small RTMP-speaking process that keeps track of the nearest router and the network number of the local net. Bridges have a full-function RTMP-speaking process which engages in the prescribed chit-chat to maintain their routing tables. Bridges use this routing table to relay DDP datagrams according to their destination network number.

Transport Layer: ATP

The transport layer protocols are used to control the flow of data between sockets, and for end-to-end error recovery. Clients of the transport layer are offered some sort of "logical link" or "virtual circuit" service between themselves and other network visible entities.

Most networks are fairly similar in the first three layers, up through the network layer. Above that, however, their architectures begin to diverge. The transport layer is usually the first to reflect the main purpose for which the network was designed. AppleTalk is quite unusual in this respect.

Typically, the transport layer supports a two-way link between clients. Some sort of higher level protocol handles the opening of the link, and the transport layer provides error and flow control. The clients at each end can act as though they have an error-free hardwired line between them. AppleTalk does not support this sort of protocol.

Instead, AppleTalk has a transaction-oriented transport protocol, called AppleTalk Transaction Protocol (ATP). Here, one end acts as a requestor and the other acts as a responder. The responder usually sets itself up on a "permanent" socket. Requestors can "pop up" anywhere, at any time, and send requests. The example application at the end of this article is a responder.

The requestor sends a request which may carry with it up to 578 bytes of data in a single segment. The responder may send back up to eight such segments, for 4624 bytes total. If the request arrives in error, it is simply discarded. The requestor keeps trying until it receives a response. Response segments that are damaged are re-transmitted. This selective retransmission is handled by the ATP protocol, invisible to ATP clients.

Sometimes it is important that a request be serviced once and only once. An example of such a request would be to backspace a record in a remote file. Remember that the requestor repeatedly requests until it receives a response.

ATP provides a special class of transaction service called "exactly once". Each request is tagged with a transaction ID. The responder ATP has the logic needed to assure that the request with a given transaction ID is executed only once. The penalty for such service is extra overhead.

Named Entities: NBP

Recall that the only network-visible entities are sockets (socket clients, actually). Communication between processes on AppleTalk takes place between socket clients. A key feature of the network is that most objects are accessible by name rather than by address. Node numbers and dynamic socket numbers are assigned randomly. People prefer names.

The Name Binding Protocol (NBP) defines a set of services that applications can use to register names for their sockets, and to locate named entities. AppleTalk names consist of three fields: the object name, the type name and the zone name. The object name is the "name" as we usually think of it. The type indicates what sort of object it is. The zone field is not currently supported by AppleTalk and is always set to the value "*", meaning "this zone". The format of a name is:

object:type@zone

The object and type fields in a name may contain the wildcard character "=" which stands for "all possible values". Thus the name "=:printer@*" means "all printers in this zone", or simply "all printers" since the zone concept is not yet supported.

Usually, a server will make itself available to the network by opening an ATP-responding socket, then registering itself by name, associating the name with its network address (net/node/socket). Then a client may lookup the server by name, or it may look up all servers of that type (using the "=" wildcard) then choose a particular one for use.

Limitations of AppleTalk

Now that we have an overview of the network architecture, let's look at the limitations of AppleTalk, especially its unusual transport layer protocol, ATP. Understanding these limitations is very important to you, as a developer. Unless Apple faces up to these limitations, you will be saddled with the responsibility of creating your own "session" oriented service, either on top of ATP or in addition to it. Let's see why.

Recall that ATP provides a transaction-oriented service. There is no provision for sequencing or otherwise grouping transactions. There is no "private wire" service between cooperating applications.

Consider a file server, whose ATP responding socket is visible to the whole network. Anyone, at any time, is free to issue an ATP request to the server's socket, and to expect a response. But file service implies a "context" spanning several transactions: an open file with a current file position.

This means that the file server must remember what's going on for each client who has a file open on that server. And a single client may have more than one file open, further complicating matters. The client and server need to set up a conversation which will continue across several transactions.

An open file is typical of a general class of network operations which require a private "session" to be maintained between the client and the server. This is the domain of the ISO session layer. AppleTalk has no session layer support.

You may say, "Well, at least ATP handles error and flow control; I can build sessions myself". But layering a session protocol on top of a "reliable transaction" protocol creates other problems. If we believe in internetworking, systems of interconnected AppleTalk bus networks, then we must face the problem of transport delay.

Suppose we want to set up an internet session, between sockets on nodes which are on different physical networks, separated by several bridges and perhaps a backbone network. The connection between client and server has plenty of speed capacity, but packets may be delayed up to 100 milliseconds in bridges and routers. ATP requires completion of a transaction before another can start. With a 100 mS delay from one end to the other, our transport protocol is capable of one transaction every 200 mS, or 5 transactions per second! Without the transport delay, the Macintosh ATP implementation is capable of hundreds of transactions per second.

It is important to understand that the degradation is not due to speed limits of the transmission medium, but instead due to the transport delay from one end to the other and ATP's need to complete a transaction before the next can be started. In an internetworking environment such as AppleTalk, transport delays are a fact of life. ATP is poorly suited as a transport protocol in such situations.

Another aspect of ATP is its asymmetry. An ATP request may carry up to 578 bytes of data. The response, on the other hand, can carry 8 times that amount of data. The responding socket is more or less permanent, the requesting socket is opened and closed for each request. The responder has no way of delivering an asynchronous message to the requestor. Data flow from the requestor to the responder has a higher overhead than that in the opposite direction.

These facts have caused some developers to set up responding sockets at each end of a client-server connection. This approach uses two sockets at each end (temporary requestor, permanent responder). But there is a limit to the total number of ATP sockets that may be open in the current version of AppleTalk, 6 requestors and 6 responders. So sockets are a precious quantity and this approach wastes sockets unnecessarily.

AppleTalk has no session layer, a severe architectural deficiency which will promote multiple "private" session protocols, some of which may be poorly designed for the internet environment. Session protocols are among the most difficult to design and test. Often, the theoretical behavior of the network used as the basis for protocol design turns out to be inaccurate. Error recovery in the session layer is probably the most complex design issue in networking.

There is another limitation that took me by surprise. AppleTalk does not support transactions between sockets on the same node. At first this might not seem to be too serious but, as any networking veteran will tell you, it is serious. If your node happens to be the one with a server you need, you can't get to it. Keep this in mind when designing AppleTalk applications: your application must handle the case where the server and client are on the same node.

A Sample AppleTalk Server

The rest of this article contains the sources for an example AppleTalk "Dial-A-Fortune" Server. Note that the main program is fairly simple, and that most of the AppleTalk access functions are broken out separately and written for general use. (See fig. 3 on the previous page.)

There is not room for explanation of the details, but much of the information you'll need to understand this program is covered in Alan Wootton's article in this issue. I will explain its operation next month, along with more about AppleTalk.

One last item: You do NOT have a copy of the file ATALK.H, which contains the structure definitions and constant definitions needed for AppleTalk I/O. The items required for this program will be published next month. The full ATALK.H will be available on a MacTutor Source Disk. Also, look for some interesting AppleTalk developer's tools from Consulair soon.

Resource File in RMaker Format
*
* DFServer.R - RMAKER source.
*
Dev:DFServer
APPL????
* Load linker output
Include Dev:DFServer.Rsrc
*
* Define the DIAL-A-FORTUNE SERVER Modal dialog.
*
Type DLOG
   ,128
 No Title
40 96 240 416
Visible
1
0
128

Type DITL
   ,128
6

Button
175 20 195 90
Fortune

Button
175 230 195 300
Quit

StaticText Disabled
5 80 20 310
AppleTalk Dial-A-Fortune

StaticText Disabled
20 72 35 310
^0

StaticText Disabled
45 110 60 310
Confucious Say: 

StaticText Disabled
70 20 170 310
Press FORTUNE to get your Fortune or QUIT to ++ shutdown the AppleTalk 
Dial-A-Fortune Server.

*
* Entity string components
*
Type STR 
   ,128
Confucious

Type STR 
   ,129
Dial-A-Fortune

Type STR 
   ,130
\2A

*
* Number of fortunes and the fortunes themselves.
*
TYPE DATA = GNRL
   ,128
.H
nnnn

Type STR 
   ,131
One of the greatest sources of energy is pride in ++
what you are doing.

Type STR
   ,132
Take a cannibal to lunch.

( more fortune strings ...)

Type STR
   ,150
Every successful person has had failures but repeated failure is no ++
guarantee of eventual success.

END



/*
  *Dial-A-Fortune AppleTalk™ Server Application
  *
  *Written by:   Timothy T. Coad, Alisa Systems, Inc.
  *June, 1985
  *Written for:  Apple Computer MDS Development System and Consulair 
Mac C™
  *This program uses specific features of the MDS system and Mac C
  *and will almost certainly require modifications for other systems.
  *
  *  LINKER COMMAND FILE (uses Mac C minimum library, output is read 
by RMaker)
  *--
  * !Start
  *
  * /Output Dev:DFServer.Rsrc
  * /Type 'RSRC'
  * 
  * MacCLib
  * DFServer
  *
  * $
  *--
  *
  *Copyright (C) 1985, MacTutor Magazine
  *
  *Permission granted to use only for non-commercial purposes.  This 
notice must be
  *included in any copies made hereof.  All rights otherwise reserved.
  *
  *Warning: This code was edited for publication and may possibly contain 
minor errors
  */

#define VERSION  "\032Experimental version 1.0.A"

#include"Lib:MacDefs.H"   /* The usual collection of Mac definitions 
*/
#include"Lib:QuickDraw.H"
#include"Lib:Window.h"
#include  "Lib:TextEdit.H"
#include"Lib:Dialog.h"
#include"Lib:Events.H"
#include  "Lib:PBDefs.H"

#include"Lib:ATalk.H"/* AppleTalk definitions  to be published next month 
*/

#define FALSE    0
#define TRUE1

#define DIALOG_ID128
#define FORTUNE_DI 6 /* Dialog Item number of Fortune item */

#define NUMOFSTRINGS_ID 128 /* Resource ID of fortune string count ('DATA') 
*/
#define FIRSTSTR_ID131  /* Resource ID of first fortune string ('STR') 
*/

/*
  * Resource IDs of the three parts of server's Network Entity Name.
  */
#define OBJECT_ID128 /* Object name (Confucious) */
#define TYPE_ID  129 /* Object type (Dial-A-Fortune) */
#define ZONE_ID  130 /* Our zone ('*' = 'This zone') */

/*
  *Global Variables
  */

NBPElem *ourName;/* -> Our registered name/skt (locked block) */
ATPBlockATPGetReq, ATPResp; /* Statically allocated I/O parameter blocks 
*/
BDSRespBDS; /* Buffer Descriptor Structure for response */
char    ReqPkt[256]; /* Buffer to receive incoming requests */
char    RespPkt[256];/* Buffer for responses (fortune text) */
unsigned short NumOfStrings;/* Number of fortune string resources */
Handle  Fortuneitem; /* Handle to currently selected fortune string */

extern shortatpOpenSkt();
extern shortatpCloseSkt();
extern intGetReqComplete();
extern intFilterGlue();

/*
  * Dial-A-Fortune Main Program
  */
main()
 {
 unsigned short button, i;/* Locals, usage is obvious except as noted 
*/
 Handle handle;
 DialogPtr dlog;
 unsigned short type;
 Rect rect;
 char fortune[256];
 
 InitDialogs (0);/* No restart function */
 InitCursor ();  /* Make arrow cursor */
 SaveA5();/* Save our A5 for async completion routines */

 /*
   * Allocate a non-relocatable NBPElem structure, request for an ephemeral 
responding socket 
   * and register ourselves on the net.
   */
 ourName = (NBPElem *)NewPtr (sizeof(NBPElem));
 ourName->tuple.addr.skt = 0;
 ourName->tuple.addr.net = 0;
 if(atpOpenSkt(&(ourName->tuple.addr.skt)))
 { /* Can't open a socket */
 DisposPtr (ourName);/* Release tuple storage */
 return;/* and exit. */
 }
 /*
   * Get the three parts of the Network Entity Name and register ourselves 
using NBP.
   */
 handle = (Handle)GetResource ('STR ', OBJECT_ID);
 i = pstrcpy(ourName->tuple.entity, *handle);
 ReleaseResource (handle);
 handle = (Handle)GetResource ('STR ', TYPE_ID);
 i += pstrcpy(ourName->tuple.entity + i, *handle);
 ReleaseResource (handle);
 handle = (Handle)GetResource ('STR ', ZONE_ID);
 pstrcpy(ourName->tuple.entity + i, *handle);
 ReleaseResource (handle);
 if(NBPRegister(2, 8, ourName))    /* Registration error? */
 { 
 atpCloseSkt(ourName->tuple.addr.skt); /* Yes, free the socket and ... 
*/
 DisposPtr (ourName);/* ... release tuple storage. */
 return;/* Exit */
 }
 /* 
   * The number of fortunes is stored in a resource to make it possible 
to add new ones.
   */
 handle = (Handle)GetResource ('DATA', NUMOFSTRINGS_ID); 
 NumOfStrings = (unsigned short)(*((unsigned short *)(*handle)));
 ReleaseResource (handle);

 /*
   * Prime the pump with the initial asynchronous ATP Get Request.
   */
 GetATPRequest(&ATPGetReq, ourName->tuple.addr.skt, ReqPkt, 256, GetReqComplete);

 /*
   * Put up our dialog box.  Use a modal dialog filter procedure to handle 
the completion of the
   *  GetATPRequest.  The GetATPRequest completion routine posts an event 
which is filtered
   * and processed by the modaldialog filter procedure.
   */
 dlog = (DialogPtr)GetNewDialog (DIALOG_ID, 0, -1);
 GetDItem (dlog, FORTUNE_DI, &type, &Fortuneitem, &rect);
 ParamText (VERSION, "", "", "");
 button = 0;
 while(button != cancel)
 {
 ModalDialog (FilterGlue, &button);
 if(button == oK)/* Fortune button pressed? */
 { /* Yes, put up a fortune */
 GetFortune(fortune);
 SetIText (Fortuneitem, fortune);
 }
 }
 DisposeDialog (dlog);    /* Dispose of dialog */
 NBPRemove(ourName->tuple.entity); /* Remove us from net */
 atpCloseSkt(ourName->tuple.addr.skt); /* Free the socket */
 }

/*
  * SendFortune
  *
  * Get a random STR resource, display in the server's dialog box, ship 
it back to the 
  * requestor as an ATP response packet and finally re-arm ourselves 
for another request.
  */
SendFortune()
 {
 GetFortune(RespPkt);
 SetIText (Fortuneitem, RespPkt);
 SendATPResp(&ATPResp, &ATPGetReq.csParam.atpGetRequest.addr, 
 ourName->tuple.addr.skt, RespPkt, 256, &RespBDS,              
 ATPGetReq.csParam.atpGetRequest.transID, 0);
 GetATPRequest(&ATPGetReq, ourName->tuple.addr.skt, ReqPkt, 256, GetReqComplete);
 }

/*
  * GetFortune
  *
  * Get a random STR resource, modulo number of strings.  Return pointer 
to string in memory.
  */
GetFortune(fortune)
char *fortune;
 {
 Handle string;
 unsigned short index;
 
 index = FIRSTSTR_ID + ((unsigned short)Random ()) % NumOfStrings;
 string = (Handle)GetResource ('STR ', index);
 pstrcpy(fortune, *string);
 ReleaseResource (string);
 }

/*
  * AppleTalk Name Binding Protocol (NBP) Low Level I/O Routines
  */

/*
  * nbpRegister - Register an element with AppleTalk.
  *
  * Returns the I/O result.
  */
short nbpRegister(interval, count, elem)
unsigned char interval;   /* Retry interval, ticks */
unsigned char count; /* Number of retries */
NBPElem *elem;   /* -> Element with name to register */
 {
 MPPBlock block;
 
 block.ioRefNum = mppRefNum;/* I/O is to the MPP driver */
 block.csCode = _nbpRegister; /* Function is "Register name" */
 block.csParam.nbpRegister.retry.interval = interval;    /* Fill in retry 
interval */
 block.csParam.nbpRegister.retry.count = count;    /* Fill in retry count 
*/
 block.csParam.nbpRegister.verify = 1; /* Enable name clash checking 
*/
 block.csParam.nbpRegister.elem = elem;/* Fill in -> name to register 
*/
 return(PBControl(&block, 0));/* DO IT, return the result */
 }

/*
  * nbpRemove - Remove an entity from AppleTalk Registry.
  *
  * Return the I/O result code.
  */
short nbpRemove(entity)
Entity *entity;  /* -> Entity string for name to remove */
 {
 MPPBlock block; /* I/O parameter block */
 
 block.ioRefNum = mppRefNum;/* I/O to .MPP driver */
 block.csCode = _nbpRemove; /* Function is "Remove name" */
 block.csParam.nbpRemove.entity = entity;          /* Fill in -> to entity 
string */
 return(PBControl(&block, 0));/* DO IT and return result */
 }


/*
  * AppleTalk Transaction Protocol (ATP) Low Level I/O Routines.
  */

/*
  * atpOpenSkt - Open an dynamic ATP responding socket.
  *
  * Socket number set to 0 if it fails.  Returns the I/O result code.
  */
short atpOpenSkt(skt)
unsigned char *skt;/* -> byte to receive assigned socket number */
 {
 ATPBlock block; /* I/O Parameter block */
 
 block.ioRefNum = atpRefNum;/* I/O is for .ATP driver */
 block.csCode = _atpOpenSkt;/* Func is "Open Responding Socket */
 block.csParam.atpOpenSkt.skt = 0; /* Socket=0 for dynamically assigned 
*/
 block.csParam.atpOpenSkt.addr.net = 0;/* Zero internet fields */
 block.csParam.atpOpenSkt.addr.node = 0;
 block.csParam.atpOpenSkt.addr.skt = 0;
 *skt = PBControl(&block, 0) ? 0 : block.csParam.atpOpenSkt.skt; /* OPEN 
IT */
 return(block.ioResult);  /* Return result */
 }

/*
  * atpCloseSkt - Close an ATP responding socket.
  *
  * Returns I/O result code.
  */
short atpCloseSkt(skt)
unsigned char skt; /* Number of ATP socket to close */
 {
 ATPBlock block;
 
 block.ioRefNum = atpRefNum;/* I/O is for .ATP driver */
 block.csCode = _atpCloseSkt; /* Function is "Close Resp. Socket" */
 block.csParam.atpCloseSkt.skt = skt;/* Fill in socket to close */
 return(PBControl(&block, 0));/* DO IT and return result */
 }

/*
  * SendATPResp - Send a single-packet ATP response. 
  *
  * Currently, this routine only supports responses consisting of a single 
ATP packet.
  * The I/O parameter block is allocated statically because the I/O may 
be  asynchronous,
  * thus the block must stay around after this routine exits.  Same goes 
for the BDS,
  * which gets filled in here.
  */
SendATPResp(ATPSendResp, Dest_NetAddr, SourceSkt, Resp, RespSize,
 atpRespBDS, TransID, asynch)
ATPBlock *ATPSendResp;    /* -> Statically allocated I/O parameter block 
*/
AddrBlock *Dest_NetAddr;  /* -> Destination network address for response 
*/
byte SourceSkt;  /* Local responding socket number */
char *Resp; /* -> response data */
unsigned short RespSize;  /* Length in bytes of response data */
BDS *atpRespBDS; /* Statically allocated Buffer Descriptor Scructure 
*/
unsigned short TransID;   /* ID of transcation being replied to */
short asynch;    /* Boolean defining whether or not it is async. */
 {
 unsigned short atpBDS();

 ATPSendResp->ioRefNum = atpRefNum;/* I/O is for .ATP driver */
 ATPSendResp->csCode = _atpSendResponse;     /* Function is "Send Response 
*/
 /*
   * Copy Requestor's net address into parameter block
   */
 bcopy(&((ATPSendResp->csParam).atpSendResponse.addr), Dest_NetAddr, 

 sizeof(AddrBlock));
 (ATPSendResp->csParam).atpSendResponse.skt = SourceSkt;       /* Responding 
Skt. */
 (ATPSendResp->csParam).atpSendResponse.bdsPtr = atpRespBDS;   /* Fill 
in -> BDS */
 (ATPSendResp->csParam).atpSendResponse.bdsSize = 1;           /* 1-packet 
resp. */
 (ATPSendResp->csParam).atpSendResponse.numOfBuffs = 1;        /* (same) 
*/
 (ATPSendResp->csParam).atpSendResponse.flags = atpEOM;        /* 1st 
has EOM */
 (ATPSendResp->csParam).atpSendResponse.transID = TransID;     /* 
 atpBDS(atpRespBDS, Resp, RespSize); /* Fill in the BDS */
 if(asynch) /* Only 1/0 legal in PBControl */
 PBControl(ATPSendResp, 1); /* Do it asynchronously */
 else
 PBControl(ATPSendResp, 0); /* Do it synchronously */
 return(ATPSendResp->ioResult);    /* Return result code */
 }

/*
  * GetATPRequest - Get an ATP Request
  *
  * Issue an ATP "GetRequest".  If a non-NULL completion routine address 
is supplied, issue the
  * request asynchronously.
  */
GetATPRequest(ATPGetReq, skt, ReqPkt, ReqPktSize, ioCompletion)
ATPBlock *ATPGetReq; /* Statically allocated I/O parameter block */
byte skt; /* Local responding socket on which to accept request */
byte *ReqPkt;    /* -> buffer to get filled in with request data */
unsigned short ReqPktSize;/* Size of request buffer, bytes */
ProcPtr ioCompletion;/* -> entry point of completion routine or NULL 
*/
 {
 ATPGetReq->ioRefNum = atpRefNum;  /* I/O is for .ATP driver */
 ATPGetReq->csCode = _atpGetRequest; /* Function is "Get Request" */
 (ATPGetReq->csParam).atpGetRequest.reqPtr = ReqPkt;     /* Fill in buffer 
data */
 (ATPGetReq->csParam).atpGetRequest.reqSize = ReqPktSize;
 (ATPGetReq->csParam).atpGetRequest.skt = skt;     /* Socket on which 
to receive req. */
 /*
   * Fill in completion routine address, and if non-NULL, issue asynch 
I/O otherwise
   * issue it synchronously.
   */
 if((ATPGetReq->ioCompletion = ioCompletion)) != NULL)   
 PBControl(ATPGetReq, 1);
 else
 PBControl(ATPGetReq, 0);
 return(ATPGetReq->ioResult); /* Return I/O result code */
 }

/*
  * Miscellaneous Low-Level Routines
 */

/*
  * GetReqComplete
  *
  * ATP Get Request Completion Routine simply posts an event with a unique 
event/message pair.
  * When the event is identified by the modal dialog filter procedure, 
a fortune is returned to the
  * requestor and another GetRequest is issued.  Registers must be preserved 
because this routine
  * runs asynchronously, and may interrupt some other process, including 
a local fortune fetch.
  * It's written in assembler 
  */
GetReqComplete()
 {
 #asm
 Movem.La0-a6/d0-d7,-(sp) ; Save registers
 Move.L _SavedA5,a5; Restore A5 context
 Move.W #MouseDown,-(sp)  ; Event type = Mouse Down
 Pea    ATPGetReq; Event message is pointer to GetReq block
 _PostEvent ; Post it
 Movem.L(sp)+,a0-a6/d0-d7 ; Restore registers
 #endasm
 }

/*
  * FilterGlue - Interface for ModalDialog Filter Proc. Callback
  *
  * This is a glue routine to get back into C.  It is called back from 
ModalDialog() with 
  * (naturally) Pascal-flavored arguments on the stack.  See the C Workshop 
in MacTutor
  * Vol. 1, No. 7 (June, 1985) and Inside Macintosh for more information 
on ModalDialog
  * event filter procedures.
  */
FilterGlue()
 {
 #asm
 ;
 ; Inputs (Pascal callfrom ModalDialog):
 ;      4(SP)      Address of word to fill in with item number
 ;      8(SP)      Address of the event record
 ;     12(SP)      Dialog (window) pointer
 ;
 Link   a6,#0    ; no local automatics
 Movem.Ld1-d7/a1-a4,-(sp) ; Save regs
 Move.L 8(a6),d0 ; D0 -> Item number word
 Move.L 12(a6),d1; D1 -> Event record
 Move.L 16(a6),d2; D2 -> Window record
 Jsr    filter   ; Call C for dirty work
 Movem.L(sp)+,d1-d7/a1-a4 ; Restore regs
 Unlk   a6; "standard" Pascal routine exit
 Move.l (sp)+,a0 ; A0 -> return point
 Addq.L #6,sp    ; Pop args
 Addq.L #6,sp
 Move.B d0,(sp)  ; Copy C result to Pascal return
 Jmp    (a0); Return
 #endasm
 }

/*
  * filter - "Real" ModalDialog filter function
  *
  * If there is a "phoney" mouse down event (with message = address of 
our GetReq block)
  * then we have received a fortune request.  In that case, send a fortune 
back to the requestor.
  */
filter(ip, ep, wp)
short *ip;/* -> Word to receive dialog item code */
EventRecord *ep; /* -> Event record */
WindowPtr wp;    /* -> Window record for modal dialog */
 {
 if(ep->what == mouseDown && ep->message == (long)&ATPGetReq)
 {
 SendFortune();  /* Send a responding fortune */
 *ip = 0; /* No item was hit */
 return(TRUE);   /* Indicate that we handled the event */
 }
 return(FALSE);  /* We didn't handle this event */
 }

/*
  * atpBDS- Setup an ATP Buffer Descriptor Structure.
  *
  * Given a buffer-load of data to send, fill in a BDS which describes 
the buffer as possibly 
  * several ATP packets.  Return the number of ATP packets required to 
send the data as
  * a response.
  */
unsigned short atpBDS(bds, buf, size)
BDS *bds; /* -> Buffer Descriptor Structure to fill in */
unsigned char *buf;/* -> Response data buffer */
short size; /* Size (bytes) of response data */
 {
 unsigned short i; /* Counts number of segments */
 
 i = 0;
 while(size > 0) /* Loop till enough packets set up */
 {
 bds->buffSize = (size > atpMaxData) ? atpMaxData : size;      /* Size 
of this packet */
 bds->buffPtr = buf; /* Fill in -> to this segment/packet */
 buf += atpMaxData;/* Advance segment pointer */
 size -= atpMaxData; /* Count down segment size */
 bds++; /* Advance BDS pointer to next seg. */
 i++;   /* Count a segment */ }
 return(i); /* Return segment count */
 }

/*
  * pstrcpy - Pascal String Copy routine.
  *
  * Returns number of bytes copied, including count byte.
  */
pstrcpy(d, s)
char *d;/* -> Destination string */
char *s;/* -> Source string */
 {
 bcopy(d, s, *s + 1);
 return(*s + 1);
 }

/*
  * bcopy -  General purpose byte copy routine.
  */
bcopy(d, s, n)
char *d;/* Destination address */
char *s;/* Source address */
short n;/* Number of bytes to copy */
 {
 #asm
 Move.L d0,a0    ; A0 -> Destination
 Move.L d1,a1    ; A1 -> Source 
 Bra.S  @1; Jump past to correct for dumb DBRA inst.
@0 Move.B (a1)+,(a0)+; Copy a byte
@1 Dbra.W d2,@0  ; Loop till done
 #endasm
 }

/*
  * SaveA5
  */
SaveA5()
{
#asm
 Lea    _SavedA5,a0  ; A0 -> Save cell 
 Move.l a5,(a0)     ; Save A5 
 Rts       ; Return
 
_SavedA5Dc.l0  ; Storage area for A5
#endasm
}
 
AAPL
$102.50
Apple Inc.
+0.25
MSFT
$45.43
Microsoft Corpora
+0.55
GOOG
$571.60
Google Inc.
+2.40

MacTech Search:
Community Search:

Software Updates via MacUpdate

pwSafe 3.1 - Secure password management...
pwSafe provides simple and secure password management across devices and computers. pwSafe uses iCloud to keep your password databases backed-up and synced between Macs and iOS devices. It is... Read more
StatsBar 1.8 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Path Finder 6.5.5 - Powerful, award-winn...
Path Finder is a file browser that combines the familiar Finder interface with the powerful utilities and innovative features. Just a small selection of the Path Finder 6 feature set: Dual pane... Read more
QuarkXPress 10.2.1 - Desktop publishing...
With QuarkXPress, you can communicate in all the ways you need to -- and always look professional -- in print and digital media, all in a single tool. Features include: Easy to Use -- QuarkXPress is... Read more
Skype 6.19.0.450 - Voice-over-internet p...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
VueScan 9.4.41 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Cloud 3.0.0 - File sharing from your men...
Cloud is simple file sharing for the Mac. Drag a file from your Mac to the CloudApp icon in the menubar and we take care of the rest. A link to the file will automatically be copied to your clipboard... Read more
LibreOffice 4.3.1.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
SlingPlayer Plugin 3.3.20.505 - Browser...
SlingPlayer is the screen interface software that works hand-in-hand with the hardware inside the Slingbox to make your TV viewing experience just like that at home. It features an array of... Read more
Get Lyrical 3.8 - Auto-magically adds ly...
Get Lyrical auto-magically add lyrics to songs in iTunes. You can choose either a selection of tracks, or the current track. Or turn on "Active Tagging" to get lyrics for songs as you play them.... Read more

Latest Forum Discussions

See All

Rhonna Designs Magic (Photography)
Rhonna Designs Magic 1.0 Device: iOS Universal Category: Photography Price: $1.99, Version: 1.0 (iTunes) Description: Want to sprinkle *magic* on your photos? With RD Magic, you can add colors, filters, light leaks, bokeh, edges,... | Read more »
This Week at 148Apps: August 25-29, 2014
Shiny Happy App Reviews   | Read more »
Qube Kingdom – Tips, Tricks, Strategies,...
Qube Kingdom is a tower defense game from DeNA. You rally your troops – magicians, archers, knights, barbarians, and others – and fight against an evil menace looking to dominate your kingdom of tiny squares. Planning a war isn’t easy, so here are a... | Read more »
Qube Kingdom Review
Qube Kingdom Review By Nadia Oxford on August 29th, 2014 Our Rating: :: KIND OF A SQUARE KINGDOMUniversal App - Designed for iPhone and iPad Qube Kingdom has cute visuals, but it’s a pretty basic tower defense game at heart.   | Read more »
Fire in the Hole Review
Fire in the Hole Review By Rob Thomas on August 29th, 2014 Our Rating: :: WALK THE PLANKUniversal App - Designed for iPhone and iPad Seafoam’s Fire in the Hole looks like a bright, 8-bit throwback, but there’s not enough booty to... | Read more »
Alien Creeps TD is Now Available Worldwi...
Alien Creeps TD is Now Available Worldwide Posted by Ellis Spice on August 29th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Dodo Master Review
Dodo Master Review By Jordan Minor on August 29th, 2014 Our Rating: :: NEST EGGiPad Only App - Designed for the iPad Dodo Master is tough but fair, and that’s what makes it a joy to play.   | Read more »
Motorsport Manager Review
Motorsport Manager Review By Lee Hamlet on August 29th, 2014 Our Rating: :: MARVELOUS MANAGEMENTUniversal App - Designed for iPhone and iPad Despite its depth and sense of tactical freedom, Motorsport Manager is one of the most... | Read more »
Motorsport Manager – Beginner Tips, Tric...
The world of Motorsport management can be an unforgiving and merciless one, so to help with some of the stress that comes with running a successful race team, here are a few hints and tips to leave your opponents in the dust. | Read more »
CalPal Update Brings the App to 2.0, Add...
CalPal Update Brings the App to 2.0, Adds Lots of New Stuff Posted by Ellis Spice on August 29th, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

Are We Now In The Post-Post-PC Era?
A longtime and thoroughgoing laptop aficionado, I was more than a little dismayed by Steve Jobs’s declaration back in 2010 when he sprang the iPad on an unsuspecting world. that we’d entered a “post-... Read more
Apple now offering refurbished 21-inch 1.4GHz...
The Apple Store is now offering Apple Certified Refurbished 21″ 1.4GHz iMacs for $929 including free shipping plus Apple’s standard one-year warranty. Their price is $170 off the cost of new models,... Read more
Save $50 on the 2.5GHz Mac mini, on sale for...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more
Save up to $300 on an iMac with Apple refurbi...
The Apple Store has Apple Certified Refurbished iMacs available for up to $300 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. These are the best prices on... Read more
The Rise of Phablets
Carlisle & Gallagher Consulting Group, a businesses and technology consulting firm focused solely on the financial services industry, has released an infographic depicting the convergence of... Read more
Bad Driver Database App Allows Good Drivers t...
Bad Driver Database 1.4 by Facile Group is a new iOS and Android app that lets users instantly input and see how many times a careless, reckless or just plain stupid driver has been added to the... Read more
Eddy – Cloud Music Player for iPhone/iPad Fre...
Ukraine based CapableBits announces the release of Eddy, its tiny, but smart and powerful cloud music player for iPhone and iPad that allows users to stream or download music directly from cloud... Read more
A&D Medical Launches Its WellnessConnecte...
For consumers and the healthcare providers and loved ones who care for them, A&D Medical, a leader in connected health and biometric measurement devices and services, has launched its... Read more
Anand Lal Shimpi Retires From AnandTech
Anand Lal Shimpi, whose AnandTech Website is famous for its meticulously detailed and thoroughgoing reviews and analysis, is packing it in. Lal Shimpi, who founded the tech site at age 14 in 1997,... Read more
2.5GHz Mac mini, Apple refurbished, in stock...
The Apple Store has Apple Certified Refurbished 2.5GHz Mac minis available for $509, $90 off MSRP. Apple’s one-year warranty is included, and shipping is free. Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.