DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Developing applications over NetBIOS using XTI

Example code for obtaining session and adapter status

1  #include <stropts.h>
2  #include <xti.h>
3  #include <sys/nb/nb_ioctl.h>

4 #define ASTAT_BUFSIZE 4096 5 #define SSTAT_BUFSIZE 4096

6 extern print_astatus(struct strioctl *); 7 extern print_sstatus(struct strioctl *);

8 demo_ioctl_user_function(int fd, char *name) 9 { 10 struct strioctl cmdbuf; 11 union { 12 struct astat adapter_status; 13 char name[NB_NAMELEN]; 14 } astat_buf; 15 struct sstat session_status;

16 cmdbuf.ic_cmd = NBIOCTL_ASTAT; 17 cmdbuf.ic_timout = 0; 18 cmdbuf.ic_dp = (char *)&astat_buf; 19 cmdbuf.ic_len = ASTAT_BUFSIZE;

20 memcpy(&astat_buf.name[0], name, NB_NAMELEN);

21 if (ioctl(fd, I_STR, &cmdbuf) < 0) { 22 perror("Error getting Adapter Status"); 23 exit(1); 24 } 25 print_astatus(&cmdbuf);

26 cmdbuf.ic_cmd = NBIOCTL_SSTAT; 27 cmdbuf.ic_timout = 0; 28 cmdbuf.ic_dp = (char *)&session_status; 29 cmdbuf.ic_len = SSTAT_BUFSIZE;

30 if (ioctl(fd, I_STR, &cmdbuf) < 0) { 31 perror("Error getting session status"); 32 exit(2); 33 } 34 print_sstatus(&cmdbuf); 35 }


line 1
includes the header file that defines constants and data structures you use to obtain session and adapter status.

lines 4-5
define the size of the buffers for the session and adapter status information. Define a buffer that is large enough to hold the largest possible session table on your system.

lines 6-7
declare functions in other source files that presumably format and display the session and adapter status information. They are shown here only as an illustration of one possible use of the status information.

line 8
declares the profile of the example function. The name parameter points to the name that identifies the ``adapter'' of interest for obtaining adapter status information. Any NetBIOS name registered in the name table for a given adapter can be used. The name parameter must point to an array of char of length NB_NAMELEN.

lines 10-14
declare the variable astat_buf, a buffer used to hold the name that is passed as a parameter in the ioctl call. This same buffer is used to hold the adapter status information returned by the NetBIOS transport. Because the same buffer is interpreted in two different ways, it is declared to be a union.

line 15
declares the variable session_status, a buffer to hold the session status information returned by the NetBIOS transport.

line 16
assigns the command field with a value indicating that adapter status is to be returned.

line 17
assigns the time out field with a zero, indicating that the ioctl call should block until the NetBIOS provider returns the requested information.

line 18
assigns the pointer field with the address of the data buffer. This buffer is initialized in line 18 with the NetBIOS name passed into the function on line 6. When the ioctl call returns successfully, this same buffer contains the adapter status information (the name passed in is overwritten in the process).

line 19
lets the NetBIOS driver know how large the buffer is.

line 20
copies the NetBIOS name passed into the function on line 6 to the data buffer astat_buf.

line 21
issues the request for adapter status.

lines 26-29
are similar to lines 16-19. However, the command field is set to retrieve session status, the pointer field is set to point to the session status buffer, and the length field is set to the length of the session status buffer.

line 30
issues the request for session status.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004