To determine the values of the M-, D-, and Q-bits in received frames, call the X25_HEADER ioctl before the virtual circuit has been created.
ints, need_header; error = ioctl(s, X25_HEADER, &need_header);
If need_header is set to one, subsequent recvs will return the data preceded by a one-byte header that contains the values of the M-, Q-, and D-bits encoded as bit shifts as follows:
#define M_BIT 0 /* number of bits to shift for M-bit */ #define D_BIT 2 /* number of bits to shift for D-bit */ #define Q_BIT 3 /* number of bits to shift for Q-bit */
For example, to check for the presence of the Q-bit in a packet, the following sequence might be used:
char buf[1025]; int s, need_header = 1, count, error; error = ioctl(s, X25_HEADER, &need_header); . . . count = recv(s, buf, sizeof(buf), 0); if (count > 0 && (buf[0] & (1 << Q_BIT))) /* then Q bit is on */
The X25_HEADER ioctl must be issued either before the connect call (for outgoing calls), or before the accept call (for incoming calls). For PVCs, the X25_HEADER ioctl must be issued before the X25_SETUP_PVC ioctl. For the duration of the call, the X25_HEADER ioctl must not be used to change the header setting. For example, if a message is received when the header setting is on and the user turns it off before reading the message, the user will receive a one-byte header along with the message, even though he is not expecting it.
If the header is requested, X.25 does not wait for a complete X.25 message to be assembled before returning any data to the user. Rather, partial messages (indicated by the presence of M_BIT) are returned to the user as they become available. Note that the buffer supplied in the recv call must be large enough to accommodate the extra byte of header information.