home *** CD-ROM | disk | FTP | other *** search
- /*
- UDP.c
-
- Code to implement the UDP functions.
-
- 01/30/94 dn - Created.
- 11/28/94 mc - Converted to CodeWarrior
- 12/04/95 dn - Prep'd for Apprentice 4
- */
-
- #include <MyTCPIncludes.h>
-
- /*
- UDP_Create
-
- Opens a UDP stream. It must be called before any UDP datagrams can be sent or received on a particular
- UDP port. UDP_Create returns a stream pointer that must be used in all subsequent UDP calls that operate
- on this UDP stream.
- */
- OSErr UDP_Create(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- pb->csCode=UDPCreate;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_Read
-
- Retrieves a datagram that has been received on the UDP stream defined by the stream pointer. Some
- number of datagrams are buffered internally within UDP even when no UDP_Read commands are outstanding,
- so it is not necessary to keep a UDP_Read command outstanding at all times. The exact number of datagrams
- that can be buffered within the MacTCP driver depends on the size of the receive buffer area given to
- MacTCP in the UDP_Create call and the size of the datagrams received.
- */
- OSErr UDP_Read(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPRead;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_BfrReturn
-
- Returns a receive buffer to the UDP driver that had been passed to you because of a successful
- UDP_Read call that returned a nonzero amount of data.
- */
- OSErr UDP_BfrReturn(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPBfrReturn;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_Write
-
- Sends a datagram on a UDP stream.
- */
- OSErr UDP_Write(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPWrite;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_Release
-
- Closes a UDP stream. Any outstanding commands on that stream are terminated with an error. The
- ownership of the receive buffer area is used to create the UDP stream passes back to you.
- */
- OSErr UDP_Release(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPRelease;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_MaxMTUSize
-
- Returns the maximum size of UDP data that can be sent in a single datagram without fragmentation.
- This number does not include the IP and UDP headers. The value is relative to the destination address. If
- the address is on the local network, the network MTU size is returned; otherwise, a value of 548 is
- returned.
- */
- OSErr UDP_MaxMTUSize(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPMaxMTUSize;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_Status
-
- Undocumented. This routine is not documented in the MacTCP Developers Guide. It is included for
- the completeness of the library. I would assume that it works similar to the TCPStatus command.
- */
- OSErr UDP_Status(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPStatus;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_MultiCreate
-
- Opens UDP connections on a consecutive series of ports. This routine is similar to UDP_Create except
- that it takes a starting and ending port instead of a single UDP port. The starting port must not be zero.
- The connection is established on a range of ports, from the starting port to the ending port, inclusive.
- The UDP_MultiSend routine must be used with this type of connection stream. Reading datagrams from
- this type of stream is identical to UDP_Read, except that the receiving port may change from datagram
- to datagram.
- */
- OSErr UDP_MultiCreate(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- if (pb->csParam.create.localPort==0)
- return udpPortNil;
-
- pb->csCode=UDPMultiCreate;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_MultiSend
-
- Sends a datagram from a specified port. (See UDP_Write)
- */
- OSErr UDP_MultiSend(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPMultiSend;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-
- /*
- UDP_MultiRead
-
- Receives data from a port created with the UDP_MultiCreate command. The port and host address on which
- the packet was received is specified in the destination port and destination host parameter-block fields.
- */
- OSErr UDP_MultiRead(UDPiopb* pb,Boolean async){
- if (pb==(UDPiopb*)0)
- return udpNilPB;
-
- if (pb->ioCRefNum==0)
- return udpNilRefNum;
-
- if (pb->udpStream==(StreamPtr)0)
- return udpNilStream;
-
- pb->csCode=UDPMultiRead;
-
- return SyncAsync((ParmBlkPtr)pb,async);
- }
-