KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > netbios > NodeStatusResponse


1 /* jcifs smb client library in Java
2  * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package jcifs.netbios;
20
21 import java.io.UnsupportedEncodingException JavaDoc;
22
23 class NodeStatusResponse extends NameServicePacket {
24
25     private NbtAddress queryAddress;
26
27     private int numberOfNames;
28     private byte[] macAddress;
29     private byte[] stats;
30
31     NbtAddress[] addressArray;
32
33     /* It is a little awkward but prudent to pass the quering address
34      * so that it may be included in the list of results. IOW we do
35      * not want to create a new NbtAddress object for this particular
36      * address from which the query is constructed, we want to populate
37      * the data of the existing address that should be one of several
38      * returned by the node status.
39      */

40
41     NodeStatusResponse( NbtAddress queryAddress ) {
42         this.queryAddress = queryAddress;
43         recordName = new Name();
44         macAddress = new byte[6];
45     }
46
47     int writeBodyWireFormat( byte[] dst, int dstIndex ) {
48         return 0;
49     }
50     int readBodyWireFormat( byte[] src, int srcIndex ) {
51         return readResourceRecordWireFormat( src, srcIndex );
52     }
53     int writeRDataWireFormat( byte[] dst, int dstIndex ) {
54         return 0;
55     }
56     int readRDataWireFormat( byte[] src, int srcIndex ) {
57         int start = srcIndex;
58         numberOfNames = src[srcIndex] & 0xFF;
59         int namesLength = numberOfNames * 18;
60         int statsLength = rDataLength - namesLength - 1;
61         numberOfNames = src[srcIndex++] & 0xFF;
62         // gotta read the mac first so we can populate addressArray with it
63
System.arraycopy( src, srcIndex + namesLength, macAddress, 0, 6 );
64         srcIndex += readNodeNameArray( src, srcIndex );
65         stats = new byte[statsLength];
66         System.arraycopy( src, srcIndex, stats, 0, statsLength );
67         srcIndex += statsLength;
68         return srcIndex - start;
69     }
70     private int readNodeNameArray( byte[] src, int srcIndex ) {
71         int start = srcIndex;
72
73         addressArray = new NbtAddress[numberOfNames];
74
75         String JavaDoc n;
76         int hexCode;
77         String JavaDoc scope = queryAddress.hostName.scope;
78         boolean groupName;
79         int ownerNodeType;
80         boolean isBeingDeleted;
81         boolean isInConflict;
82         boolean isActive;
83         boolean isPermanent;
84         int j;
85         boolean addrFound = false;
86
87         try {
88             for( int i = 0; i < numberOfNames; srcIndex += 18, i++ ) {
89                 for( j = srcIndex + 14; src[j] == 0x20; j-- )
90                     ;
91                 n = new String JavaDoc( src, srcIndex, j - srcIndex + 1, Name.OEM_ENCODING );
92                 hexCode = src[srcIndex + 15] & 0xFF;
93                 groupName = (( src[srcIndex + 16] & 0x80 ) == 0x80 ) ? true : false;
94                 ownerNodeType = ( src[srcIndex + 16] & 0x60 ) >> 5;
95                 isBeingDeleted = (( src[srcIndex + 16] & 0x10 ) == 0x10 ) ? true : false;
96                 isInConflict = (( src[srcIndex + 16] & 0x08 ) == 0x08 ) ? true : false;
97                 isActive = (( src[srcIndex + 16] & 0x04 ) == 0x04 ) ? true : false;
98                 isPermanent = (( src[srcIndex + 16] & 0x02 ) == 0x02 ) ? true : false;
99     
100     /* The NbtAddress object used to query this node will be in the list
101      * returned by the Node Status. A new NbtAddress object should not be
102      * created for it because the original is potentially being actively
103      * referenced by other objects. We must populate the existing object's
104      * data explicitly (and carefully).
105      */

106                 if( !addrFound && queryAddress.hostName.hexCode == hexCode &&
107                         ( queryAddress.hostName == NbtAddress.UNKNOWN_NAME ||
108                         queryAddress.hostName.name.equals( n ))) {
109     
110                     if( queryAddress.hostName == NbtAddress.UNKNOWN_NAME ) {
111                         queryAddress.hostName = new Name( n, hexCode, scope );
112                     }
113                     queryAddress.groupName = groupName;
114                     queryAddress.nodeType = ownerNodeType;
115                     queryAddress.isBeingDeleted = isBeingDeleted;
116                     queryAddress.isInConflict = isInConflict;
117                     queryAddress.isActive = isActive;
118                     queryAddress.isPermanent = isPermanent;
119                     queryAddress.macAddress = macAddress;
120                     queryAddress.isDataFromNodeStatus = true;
121                     addrFound = true;
122                     addressArray[i] = queryAddress;
123                 } else {
124                     addressArray[i] = new NbtAddress( new Name( n, hexCode, scope ),
125                                             queryAddress.address,
126                                             groupName,
127                                             ownerNodeType,
128                                             isBeingDeleted,
129                                             isInConflict,
130                                             isActive,
131                                             isPermanent,
132                                             macAddress );
133                 }
134             }
135         } catch( UnsupportedEncodingException JavaDoc uee ) {
136         }
137         return srcIndex - start;
138     }
139     public String JavaDoc toString() {
140         return new String JavaDoc( "NodeStatusResponse[" +
141             super.toString() + "]" );
142     }
143 }
144
145
Popular Tags