KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > netbios > SessionRequestPacket


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.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23
24 public class SessionRequestPacket extends SessionServicePacket {
25
26     private Name calledName, callingName;
27
28     SessionRequestPacket() {
29         calledName = new Name();
30         callingName = new Name();
31     }
32     public SessionRequestPacket( Name calledName, Name callingName ) {
33         type = SESSION_REQUEST;
34         this.calledName = calledName;
35         this.callingName = callingName;
36     }
37     int writeTrailerWireFormat( byte[] dst, int dstIndex ) {
38         int start = dstIndex;
39         dstIndex += calledName.writeWireFormat( dst, dstIndex );
40         dstIndex += callingName.writeWireFormat( dst, dstIndex );
41         return dstIndex - start;
42     }
43     int readTrailerWireFormat( InputStream JavaDoc in,
44                             byte[] buffer,
45                             int bufferIndex )
46                             throws IOException JavaDoc {
47         int start = bufferIndex;
48         if( in.read( buffer, bufferIndex, length ) != length ) {
49             throw new IOException JavaDoc( "invalid session request wire format" );
50         }
51         bufferIndex += calledName.readWireFormat( buffer, bufferIndex );
52         bufferIndex += callingName.readWireFormat( buffer, bufferIndex );
53         return bufferIndex - start;
54     }
55 }
56
Popular Tags