In the same way as sending data, data reception is straightforward. When data is received with the D-bit set, action may be required by the application. When the initial Call Request is sent, it may request that data confirmation be at the application-to-application level. If application-to-application confirmation is agreed upon, then on receiving a packet with the D-bit set, an application must send a Data Acknowledgment (N_DAck) message.
This example prints out incoming data as a string, if the Q-bit is not set:
S_X25_HDR *hdrptr;
struct xdataf *dat_msg;
struct xdatacf *dack;
for(;;) {
if (getmsg(x25_fd, &ctlblk, &datblk, &getflags) < 0) {
perror("Getmsg fail");
exit(1);
}
hdrptr = (S_X25_HDR *) ctlbuf;
if (hdrptr->xl_type == XL_CTL) {
/* Deal with protocol message as required -
* see below
*/
}
if (hdrptr->xl_type == XL_DAT) {
dat_msg = (struct xdataf *) ctlbuf;
switch (dat_msg->xl_command) {
case N_Data:
if (dat_msg->More)
printf("M-bit set \n");
if (dat_msg->setQbit)
printf("Q-bit set \n");
else {
if (dat_msg->setDbit)
printf("D-bit set \n");
for (i = 1;i<datblk.len; i++)
printf("%c", datbuf[i]);
/*
* If application to application
* Dbit confirmation was negotiated
* at call setup time,
* send an N_DAck
*/
if (app_to_app && dat_msg->setDbit) {
dack = (struct xdatacf *)malloc(sizeof(struct xdatacf));
memset((char *)dack 0, sizeof(struct xdatacf));
dack- >xl_command = N_DAck;
dack->xl_type = XL_DAT;
ctlblk->len = sizeof(struct xdatacf);
ctlblk->buf = (char *)dack;
datblk->len = 0;
datblk->buf = (char *)0;
putmsg(x25_fd, &ctlblk, &datblk, &getflags);
}
} /* end else */
break;
case N_EData:
printf("***Expedited data received \n");
/* Must deal with it */
break;
case N_DAck:
printf("***Data Acknowledgment received \n");
break;
default:
break;
} /* end switch */
} /* end if */
} /* end for */