KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > dcerpc > DcerpcBind


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

19
20 package jcifs.dcerpc;
21
22 import jcifs.dcerpc.ndr.*;
23
24 public class DcerpcBind extends DcerpcMessage {
25
26     static final String JavaDoc[] result_message = {
27         "0",
28         "DCERPC_BIND_ERR_ABSTRACT_SYNTAX_NOT_SUPPORTED",
29         "DCERPC_BIND_ERR_PROPOSED_TRANSFER_SYNTAXES_NOT_SUPPORTED",
30         "DCERPC_BIND_ERR_LOCAL_LIMIT_EXCEEDED"
31     };
32
33     static String JavaDoc getResultMessage(int result) {
34         return result < 4 ?
35                 result_message[result] :
36                 "0x" + jcifs.util.Hexdump.toHexString(result, 4);
37     }
38     public DcerpcException getResult() {
39         if (result != 0)
40             return new DcerpcException(getResultMessage(result));
41         return null;
42     }
43
44     DcerpcBinding binding;
45     int max_xmit, max_recv;
46
47     DcerpcBind(DcerpcBinding binding, DcerpcHandle handle) {
48         this.binding = binding;
49         max_xmit = handle.max_xmit;
50         max_recv = handle.max_recv;
51         ptype = 11;
52         flags = DCERPC_FIRST_FRAG | DCERPC_LAST_FRAG;
53     }
54
55     public int getOpnum() {
56         return 0;
57     }
58     public void encode_in(NdrBuffer buf) throws NdrException {
59         buf.enc_ndr_short(max_xmit);
60         buf.enc_ndr_short(max_recv);
61         buf.enc_ndr_long(0); /* assoc. group */
62         buf.enc_ndr_small(1); /* num context items */
63         buf.enc_ndr_small(0); /* reserved */
64         buf.enc_ndr_short(0); /* reserved2 */
65         buf.enc_ndr_short(0); /* context id */
66         buf.enc_ndr_small(1); /* number of items */
67         buf.enc_ndr_small(0); /* reserved */
68         binding.uuid.encode(buf);
69         buf.enc_ndr_short(binding.major);
70         buf.enc_ndr_short(binding.minor);
71         DCERPC_UUID_SYNTAX_NDR.encode(buf);
72         buf.enc_ndr_long(2); /* syntax version */
73     }
74     public void decode_out(NdrBuffer buf) throws NdrException {
75         buf.dec_ndr_short(); /* max transmit frag size */
76         buf.dec_ndr_short(); /* max receive frag size */
77         buf.dec_ndr_long(); /* assoc. group */
78         int n = buf.dec_ndr_short(); /* secondary addr len */
79         buf.advance(n); /* secondary addr */
80         buf.align(4);
81         buf.dec_ndr_small(); /* num results */
82         buf.align(4);
83         result = buf.dec_ndr_short();
84         buf.dec_ndr_short();
85         buf.advance(20); /* transfer syntax / version */
86     }
87 }
88
Popular Tags