To find out which logical channel is associated with a connection, do the following:
int s, lcn; error = ioctl(s, X25_RD_LCGN, &lcn);
Here, s is the socket associated with the connection (or virtual circuit). On return from the call, lcn is set to the logical channel number associated with socket s. If the returned value of lcn is 0, there is no connected virtual circuit associated with the socket.