1 17 package org.alfresco.filesys.smb.server.win32; 18 19 import java.io.IOException ; 20 21 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 22 import org.alfresco.filesys.netbios.win32.NetBIOS; 23 import org.alfresco.filesys.netbios.win32.Win32NetBIOS; 24 import org.alfresco.filesys.smb.server.PacketHandler; 25 import org.alfresco.filesys.smb.server.SMBSrvPacket; 26 27 35 public class Win32NetBIOSPacketHandler extends PacketHandler 36 { 37 38 42 private static final int ReceiveErrorMask = 0xFF000000; 43 private static final int ReceiveLengthMask = 0x0000FFFF; 44 45 47 private int m_lana; 48 49 51 private int m_lsn; 52 53 60 public Win32NetBIOSPacketHandler(int lana, int lsn, String callerName) 61 { 62 super(SMBSrvPacket.PROTOCOL_WIN32NETBIOS, "Win32NB", "WNB", callerName); 63 64 m_lana = lana; 65 m_lsn = lsn; 66 } 67 68 73 public final int getLANA() 74 { 75 return m_lana; 76 } 77 78 83 public final int getLSN() 84 { 85 return m_lsn; 86 } 87 88 95 public int readPacket(SMBSrvPacket pkt) throws IOException 96 { 97 98 103 int pktLen = pkt.getBuffer().length; 104 if (pktLen > NetBIOS.MaxReceiveSize) 105 pktLen = NetBIOS.MaxReceiveSize; 106 107 int rxLen = Win32NetBIOS.Receive(m_lana, m_lsn, pkt.getBuffer(), 4, pktLen - 4); 108 109 if ((rxLen & ReceiveErrorMask) != 0) 110 { 111 112 114 int sts = (rxLen & ReceiveErrorMask) >> 24; 115 116 if (sts == NetBIOS.NRC_Incomp) 117 { 118 119 122 if (pkt.getBuffer().length < RFCNetBIOSProtocol.MaxPacketSize) 123 { 124 125 127 byte[] newbuf = new byte[RFCNetBIOSProtocol.MaxPacketSize]; 128 129 131 System.arraycopy(pkt.getBuffer(), 4, newbuf, 4, pktLen - 4); 132 133 135 pkt.setBuffer(newbuf); 136 137 139 } 141 142 144 rxLen = (rxLen & ReceiveLengthMask); 145 146 151 int rxLen2 = Win32NetBIOS.Receive(m_lana, m_lsn, pkt.getBuffer(), rxLen + 4, 32768); 152 153 if ((rxLen2 & ReceiveErrorMask) != 0) 154 { 155 sts = (rxLen2 & ReceiveErrorMask) >> 24; 156 throw new IOException ("Win32 NetBIOS multi-part receive failed, sts=0x" + sts + ", err=" 157 + NetBIOS.getErrorString(sts)); 158 } 159 160 162 rxLen += rxLen2; 163 } 164 else 165 { 166 167 169 return -1; 170 } 171 } 172 173 175 return rxLen; 176 } 177 178 185 public void writePacket(SMBSrvPacket pkt, int len) throws IOException 186 { 187 188 193 int sts = Win32NetBIOS.Send(m_lana, m_lsn, pkt.getBuffer(), 4, len); 194 195 } 197 198 201 public void closeHandler() 202 { 203 super.closeHandler(); 204 205 207 Win32NetBIOS.Hangup(m_lana, m_lsn); 208 } 209 } 210 | Popular Tags |