t_alloc(3N)
NAME
t_alloc − allocate a library structure
SYNOPSIS
cc [ flag ... ] file ... −lnsl [ library ... ]
#include <xti.h>
void ∗t_alloc(int fd, int struct_type, int fields);
DESCRIPTION
This routine is part of the XTI interfaces which evolved from the TLI interfaces. XTI represents the future evolution of these interfaces. However, TLI interfaces are supported for compatibility. When using a TLI routine that has the same name as an XTI routine, a different header file, tiuser.h , must be used. Refer to the section, TLI COMPATIBILITY , for a description of differences between the two interfaces.
The t_alloc() function dynamically allocates memory for the various transport function argument structures as specified below. This function will allocate memory for the specified structure, and will also allocate memory for buffers referenced by the structure.
The structure to allocate is specified by the struct_type parameter, which can be one of the following:
T_BIND struct t_bind
T_CALL struct t_call
T_OPTMGMT struct t_optmgmt
T_DIS struct t_discon
T_UNITDATA struct t_unitdata
T_UDERROR struct t_uderr
T_INFO struct t_info
Each of the allocated structures may subsequently be used as an argument to one or more transport functions.
All of the structures (but not those generated using T_INFO ) will contain at least one field of type struct netbuf. For each field of the netbuf type, the user may specify that the buffer for that field should be allocated as well.
The length of the buffer allocated will be equal to or greater than the appropriate size as returned in the info argument of t_open(3N) or t_getinfo(3N). The relevant fields of the info argument are described in the following list.
The fields argument determines which buffers to allocate. Its value can be specified using bitwise- OR operations with the following values:
T_ADDR The addr field of t_bind, t_call, t_unitdata, or t_uderr structures.
T_OPT The opt field of t_optmgmt, t_call, t_unitdata, or t_uderr structures.
T_UDATA The udata field of t_call, t_discon, or t_unitdata structures.
T_ALL All relevant fields of struct_type. Fields which are not supported by the transport provider specified by fd will not be allocated.
For each relevant field specified in the parameter fields, t_alloc() allocates memory for the buffer associated with the field, it initializes the len field to zero, and it initializes the buf pointer and maxlen field accordingly. Irrelevant or unknown values passed in fields are ignored.
Since the length of the buffer allocated will be based on the same size information that is returned to the user on a call to t_open() or t_getinfo(), fd must refer to the transport endpoint through which the newly allocated structure will be passed. (However, when a T_INFO structure is being allocated, fd may be set to any value.) In this way the appropriate size information can be accessed. If the size value associated with any specified field is −1 or −2 (see t_open(3N) or t_getinfo(3N)), t_alloc() will be unable to determine the size of the buffer to allocate and will fail, setting t_errno to TSYSERR and errno to EINVAL . For any field not specified in fields, buf will be set to the null pointer and len and maxlen will be set to zero.
Use of t_alloc() to allocate structures will help ensure the compatibility of user programs with future releases of the transport interface functions.
VALID STATES
Legitimate states (see t_getstate(3N)) for a call to this routine are every one except T_UNINIT .
RETURN VALUES
On successful completion, t_alloc() returns a pointer to the newly allocated structure. On failure, a null pointer is returned, t_errno is set to indicate the error, and possibly errno is set.
ERRORS
On failure, t_errno will be set to one of the following:
TBADF The struct_type parameter was specified as something other than T_INFO and the specified file descriptor does not refer to a transport endpoint.
TSYSERR A system error has occurred during execution of this function. Accordingly, errno will have been set to the specific error.
TNOSTRUCTYPE
Unsupported struct_type requested. This can include a request for a structure type which is inconsistent with the transport provider type specified: either connection-mode or connectionless-mode.
TPROTO This error indicates that a communication problem has been detected between XTI and the transport provider for which there is no other suitable XTI t_errno value.
TLI COMPATIBILITY
The XTI and TLI interface definitions have common names but use different header files. This, and other semantic differences between the two interfaces are described in the subsections below.
Interface Header
The XTI interfaces use the header file, xti.h . TLI interfaces should not use this header. They should use the header:
#include <tiuser.h>
Error Description Values
The t_errno values that can be set by the XTI interface and cannot be set by the TLI interface are:
TPROTO
TNOSTRUCTYPE
Special Buffer Sizes
Assume that the value associated with any field of struct t_info (argument returned by t_open() or t_getinfo()) that describes buffer limits is −1. Then the underlying service provider can support a buffer of unlimited size. If this is the case, t_alloc() will allocate a buffer with the default size 1024 bytes, which may be handled as described in the next paragraph.
If the underlying service provider supports a buffer of unlimited size in the netbuf structure (see t_connect(3N)), t_alloc() will return a buffer of size 1024 bytes. If a larger size buffer is required, it will need to be allocated separately using a memory allocation routine such as malloc(3C). The buf and maxlen fields of the netbuf data structure can then be updated with the address of the new buffer and the 1024 byte buffer originally allocated by t_alloc() can be freed using free(3C).
Assume that the value associated with any field of struct t_info (argument returned by t_open() or t_getinfo() ) that describes nbuffer limits is −2. Then t_alloc() will set the buffer pointer to NULL and the buffer maximum size to 0 , and then will return success (see t_open(3N) or t_getinfo(3N)).
For more information refer to the Transport Interfaces Programming Guide.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| MT-Level | MT-Safe |
SEE ALSO
free(3C), malloc(3C), t_connect(3N), t_free(3N), t_getinfo(3N), t_getstate(3N), t_open(3N), attributes(5)
Transport Interfaces Programming Guide
SunOS 5.6 — Last change: 10 Feb 1997