Transport users must initialize XTI/TLI endpoints before transferring data. They must choose the appropriate connectionless service provider using t_open(3NSL) and establish its identity using t_bind(3NSL).
Use t_optmgmt(3NSL) to negotiate protocol options. Like connection mode service, each transport provider specifies the options, if any, it supports. Option negotiation is a protocol-specific activity. In Example 3-1, the server waits for incoming queries, and processes and responds to each query. The example also shows the definitions and initiation sequence of the server.
#include <stdio.h> #include <fcntl.h> #include <xti.h> /* TLI applications use <tiuser.h> */ #define SRV_ADDR 2 /* server's well known address */ main() { int fd; int flags; struct t_bind *bind; struct t_unitdata *ud; struct t_uderr *uderr; extern int t_errno; if ((fd = t_open("/dev/exmp", O_RDWR, (struct t_info *) NULL)) == -1) { t_error("unable to open /dev/exmp"); exit(1); } if ((bind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR)) == (struct t_bind *) NULL) { t_error("t_alloc of t_bind structure failed"); exit(2); } bind->addr.len = sizeof(int); *(int *)bind->addr.buf = SRV_ADDR; bind->qlen = 0; if (t_bind(fd, bind, bind) == -1) { t_error("t_bind failed"); exit(3); } /* * TLI interface applications need the following code which * is no longer needed for XTI interface applications. * ------------------------------------- * Verify if the bound address correct? * * if (bind -> addr.len != sizeof(int) || * *(int *)bind->addr.buf != SRV_ADDR) { * fprintf(stderr, "t_bind bound wrong address\n"); * exit(4); * } * --------------------------------------- */
The server establishes a transport endpoint with the desired transport provider using t_open(3NSL). Each provider has an associated service type, so the user can choose a particular service by opening the appropriate transport provider file. This connectionless mode server ignores the characteristics of the provider returned by t_open(3NSL) by setting the third argument to NULL. The transaction server assumes the transport provider has the following characteristics:
The transport address is an integer value that uniquely identifies each user.
The transport provider supports the T_CLTS service type (connectionless transport service, or datagram).
The transport provider does not require any protocol-specific options.
The connectionless server binds a transport address to the endpoint so that potential clients can access the server. A t_bind structure is allocated using t_alloc(3NSL) and the buf and len fields of the address are set accordingly.
One difference between a connection mode server and a connectionless mode server is that the qlen field of the t_bind structure is 0 for connectionless mode service. There are no connection requests to queue.
XTI/TLI interfaces define an inherent client-server relationship between two users while establishing a transport connection in the connection mode service. No such relationship exists in connectionless mode service.
TLI requires that the server check the bound address returned by t_bind(3NSL) to ensure that it is the same as the one supplied. t_bind(3NSL) can also bind the endpoint to a separate, free address if the one requested is busy.