home *** CD-ROM | disk | FTP | other *** search
- #include "OpenTransport.h"
- #include "OpenTptLinks.h"
- #include "OpenTptAppleTalk.h"
- #include <Events.h>
- #include <stdio.h>
-
- #define DDP_OPT_SRCADDR 0x2101 // define this here for now.
- #define kDestNodeID 128
-
- DDPAddress reqDDPAddr;
- DDPAddress retDDPAddr;
- TBind req;
- TBind ret;
- EndpointRef ep = 0;
-
- main()
- {
- short bOTAvaliable;
- OSStatus otErr=0;
- UInt8 packet[1024];
- DDPAddress sendAddr;
- DDPAddress recvAddr;
- TUnitData otPB;
- UInt8 buf[kOTOptionHeaderSize + kDDPAddressLength]; // define buffer for fourByte Option size
- TOption* opt; // option ptr to make items easier to access
- OTFlags flags;
- long timer;
- Boolean processIncoming;
-
- /* Initialize Open Transport. */
- /* NOTE - I'm not initializing any */
- /* other managers. Should I? */
-
- bOTAvaliable = InitOpenTransport();
- if (bOTAvaliable != kOTNoError)
- {
-
- printf("\n failed to init OT");
- return(0);
- }
- /* open the DDP endpoint */
-
- ep = OTOpenEndpoint(OTCreateConfiguration("ddp"), 0, 0, &otErr);
-
- if (otErr || !ep) {
-
- printf("\n failed to open endpoint");
- return(0);
- }
- /* build the DDPAddress for binding */
- /* to Multinode AppleTalk. The */
- /* network field matches our network*/
- /* and the node ID is a value that */
- /* is known to be available. */
-
- reqDDPAddr.fAddressType = AF_ATALK_MNODE;
- reqDDPAddr.fNetwork = 0;
- reqDDPAddr.fNodeID = 0;
-
- /* fill out the request and return */
- /* TBind blocks */
-
- req.addr.maxlen = 0;
- req.addr.len = sizeof(DDPAddress);
- req.addr.buf = (UInt8 *)&reqDDPAddr;
- req.qlen = 0;
-
- ret.addr.maxlen = sizeof(DDPAddress);
- ret.addr.len = 0;
- ret.addr.buf = (UInt8 *)&retDDPAddr;
- ret.qlen = 0;
-
- /* bind the endpoint */
-
- otErr = OTBind(ep, &req, &ret);
- if (otErr != kOTNoError)
- {
-
- printf("\n Failed to bind ");
- OTCloseProvider(ep);
- return(0);
- }
- else
- {
- printf("\n\nBind successful, node %d acquired.", retDDPAddr.fNodeID);
- }
- /* build a AppleTalk Echo Protocol */
- /* packet to be sent to the local */
- /* network node 0x42. While 0x42 */
- /* may not actually exist on the */
- /* network, sending this packet */
- /* to OT should at least generate */
- /* AARP request packets to resolve */
- /* the destNodeID to ELAP address. */
-
- /* fill out the destination */
- /* DDPAddress struct based on the */
- /* values stuffed in the DDP Packet */
-
- sendAddr.fAddressType = AF_ATALK_DDP;
- sendAddr.fNetwork = retDDPAddr.fNetwork;
- sendAddr.fNodeID = kDestNodeID;
- sendAddr.fSocket = 4; // echo socket
- sendAddr.fDDPType = 4; // echo packet type
-
- opt = (TOption*)buf; // set option ptr to buffer
-
- opt->level = ATK_DDP; // dealing with tpi
- opt->name = DDP_OPT_SRCADDR;
- opt->len = kOTOptionHeaderSize + kDDPAddressLength;
- opt->status = 0;
- // move the mnode src address into the value field
- BlockMove((Ptr)&retDDPAddr, (Ptr)&opt->value, kDDPAddressLength);
-
- /* fill out the OpenTransport Param */
- /* block for sending data */
- otPB.addr.maxlen = 0;
- otPB.addr.len = sizeof(DDPAddress);
- otPB.addr.buf = (UInt8*)&sendAddr;
- otPB.opt.maxlen = 0;
- otPB.opt.len = kOTOptionHeaderSize + kDDPAddressLength;
- otPB.opt.buf = (UInt8*)opt;
- otPB.udata.maxlen = 0;
- otPB.udata.len = 20; // send only the first 20 bytes of the data buffer
- otPB.udata.buf = (UInt8 *)&packet;
-
- packet[0] = 1; // set the echo packet as a request
-
- /* send the data over the endpoint. */
- /* As noted above, at a minimum, */
- /* AARP packets should be sent to */
- /* resolve the DDP nodeID. */
-
- otErr = OTSndUData(ep, &otPB);
- if (otErr != kOTNoError)
- {
-
- DebugStr("\p Failed to send data");
- }
-
- // set up a watchdog timer for 3 seconds
- timer = TickCount() + 3 * 60;
- // assume an incoming packet will be received
- processIncoming = true;
-
- while((OTLook(ep) != T_DATA) && processIncoming)
- {
- if (timer < TickCount())
- {
- printf("\n\n No Echo reply received");
- processIncoming = false; // no packet recieved
- }
- }
-
- if (processIncoming)
- {
- printf("\n\n incoming echo response to multinode");
- otPB.addr.maxlen = sizeof(recvAddr);
- otPB.addr.len = 0;
- otPB.addr.buf = (UInt8*)&recvAddr;
- otPB.opt.maxlen = 0;
- otPB.opt.len = 0;
- otPB.opt.buf = 0;
- otPB.udata.maxlen = sizeof(packet);
- otPB.udata.len = 0;
- otPB.udata.buf = (UInt8*)packet;
-
- otErr = OTRcvUData(ep, &otPB, &flags);
- if (otErr == kOTNoError)
- printf("\n\n incoming packet processed OK");
- else
- printf("\n\n error occurred processing incoming packet");
-
- }
-
- OTCloseProvider(ep);
-
- return(0);
- }
-
-
-