ddp(3)

NAME
AppleTalk Datagram Delivery Protocol (DDP) interface

SYNOPSIS
#include <at/appletalk.h>
#include <at/ddp.h>

int ddp_open(at_socket *socket);

int ddp_close(int sd);

DESCRIPTION

The ddp_open routine opens a static or dynamic DDP socket and returns an AppleTalk socket descriptor that can be used to read and write DDP datagrams.

socket
    A pointer to the DDP socket number to open. If the AppleTalk socket number is 0, or if socket is NULL, a DDP socket is dynamically assigned. If non-NULL, the socket number is returned in socket.

An error condition will result if there are no more dynamic DDP sockets available, if the maximum number of open files has been exceeded at a process or system level, or if the network is offline.

Only the superuser can open a static DDP socket.

The ddp_close routine closes the DDP socket identified by the AppleTalk socket descriptor sd.

Datagrams are always read and written with the long DDP header format, using standard read(2) and write(2) system calls. If the datagram is directed to a LocalTalk™ interface on the same network, the DDP protocol module will send it with a short DDP header. The long header DDP datagram is defined by the following structure in <at/ddp.h>.

    typedef struct {
            u_short     unused : 2,
                        hopcount : 4,
                        length : 10;
            u_short     checksum;
            at_net      dst_net;
            at_net      src_net;
            at_node     dst_node;
            at_node     src_node;
            at_socket   dst_socket;
            at_socket   src_socket;
            u_char      type;
            u_char      data[AT_DDP_DATA_SIZE];
    } at_ddp_t;

When a datagram is written, only the fields checksum, dst_net, dst_node, dst_socket, type, and data need to be set. The length field is the DDP packet length and hop count field. The hop count is in the 6 most significant bits of this field; the length is in the 10 least significant bits.

The checksum field contains the DDP checksum. When datagrams are writen, a checksum is computed only if this field is nonzero.

Datagrams can be sent and received asynchronously using the standard operating system facilities: select(2N); fcntl(2) specifying O_NDELAY; or FIONREAD, FIONBIO, and FIOASYNC ioctls (see ioctl(2)).

ERRORS
All routines return -1 on error with detailed error code in errno:

[EACCES]
    A nonsuperuser attempted to open a static AppleTalk socket (ddp_open).

[EADDRINUSE]
    The static socket is in use, or all dynamic sockets are in use (ddp_open).

[EINVAL]
    An attempt was made to open an invalid AppleTalk socket number (ddp_open).

[EMSGSIZE]
    A datagram is too large.

[ENETDOWN]
    The network interface is down (all).

[ENOBUFS]
    DDP out of buffers, unable to return configuration information.

Routines also return any additional error codes returned by the underlying LAP module and by standard operating system calls: open(2), close(2), read(2), write(2), and ioctl(2).

SEE ALSO
close(2), fcntl(2), ioctl(2), open(2), read(2), select(2N), write(2), atp(3), ddp(3), nbp(3), pap(3), rmtp(3), fcntl(5), termio(7); Inside AppleTalk.