mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
260
source/java/org/alfresco/filesys/netbios/win32/NetBIOS.java
Normal file
260
source/java/org/alfresco/filesys/netbios/win32/NetBIOS.java
Normal file
@@ -0,0 +1,260 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.netbios.win32;
|
||||
|
||||
/**
|
||||
* NetBIOS API Constants Class
|
||||
*/
|
||||
public class NetBIOS
|
||||
{
|
||||
// NetBIOS command codes
|
||||
|
||||
public final static int NCBCall = 0x10;
|
||||
public final static int NCBListen = 0x11;
|
||||
public final static int NCBHangup = 0x12;
|
||||
public final static int NCBSend = 0x14;
|
||||
public final static int NCBRecv = 0x15;
|
||||
public final static int NCBRecvAny = 0x16;
|
||||
public final static int NCBChainSend = 0x17;
|
||||
public final static int NCBDGSend = 0x20;
|
||||
public final static int NCBDGRecv = 0x21;
|
||||
public final static int NCBDGSendBc = 0x22;
|
||||
public final static int NCBDGRecvBc = 0x23;
|
||||
public final static int NCBAddName = 0x30;
|
||||
public final static int NCBDelName = 0x31;
|
||||
public final static int NCBReset = 0x32;
|
||||
public final static int NCBAStat = 0x33;
|
||||
public final static int NCBSStat = 0x34;
|
||||
public final static int NCBCancel = 0x35;
|
||||
public final static int NCBAddGrName = 0x36;
|
||||
public final static int NCBEnum = 0x37;
|
||||
public final static int NCBUnlink = 0x70;
|
||||
public final static int NCBSendNA = 0x71;
|
||||
public final static int NCBChainSendNA = 0x72;
|
||||
public final static int NCBLANStAlert = 0x73;
|
||||
public final static int NCBAction = 0x77;
|
||||
public final static int NCBFindName = 0x78;
|
||||
public final static int NCBTrace = 0x79;
|
||||
|
||||
public final static int Asynch = 0x80;
|
||||
|
||||
// Status codes
|
||||
|
||||
public final static int NRC_GoodRet = 0x00;
|
||||
public final static int NRC_BufLen = 0x01;
|
||||
public final static int NRC_IllCmd = 0x03;
|
||||
public final static int NRC_CmdTmo = 0x05;
|
||||
public final static int NRC_Incomp = 0x06;
|
||||
public final static int NRC_Baddr = 0x07;
|
||||
public final static int NRC_SNumOut = 0x08;
|
||||
public final static int NRC_NoRes = 0x09;
|
||||
public final static int NRC_SClosed = 0x0A;
|
||||
public final static int NRC_CmdCan = 0x0B;
|
||||
public final static int NRC_DupName = 0x0D;
|
||||
public final static int NRC_NamTFul = 0x0E;
|
||||
public final static int NRC_ActSes = 0x0F;
|
||||
public final static int NRC_LocTFul = 0x11;
|
||||
public final static int NRC_RemTFul = 0x12;
|
||||
public final static int NRC_IllNN = 0x13;
|
||||
public final static int NRC_NoCall = 0x14;
|
||||
public final static int NRC_NoWild = 0x15;
|
||||
public final static int NRC_InUse = 0x16;
|
||||
public final static int NRC_NamErr = 0x17;
|
||||
public final static int NRC_SAbort = 0x18;
|
||||
public final static int NRC_NamConf = 0x19;
|
||||
public final static int NRC_IfBusy = 0x21;
|
||||
public final static int NRC_TooMany = 0x22;
|
||||
public final static int NRC_Bridge = 0x23;
|
||||
public final static int NRC_CanOccr = 0x24;
|
||||
public final static int NRC_Cancel = 0x26;
|
||||
public final static int NRC_DupEnv = 0x30;
|
||||
public final static int NRC_EnvNotDef = 0x34;
|
||||
public final static int NRC_OSResNotAv = 0x35;
|
||||
public final static int NRC_MaxApps = 0x36;
|
||||
public final static int NRC_NoSaps = 0x37;
|
||||
public final static int NRC_NoResources = 0x38;
|
||||
public final static int NRC_InvAddress = 0x39;
|
||||
public final static int NRC_InvDDid = 0x3B;
|
||||
public final static int NRC_LockFail = 0x3C;
|
||||
public final static int NRC_OpenErr = 0x3F;
|
||||
public final static int NRC_System = 0x40;
|
||||
public final static int NRC_Pending = 0xFF;
|
||||
|
||||
// Various constants
|
||||
|
||||
public final static int NCBNameSize = 16;
|
||||
public final static int MaxLANA = 254;
|
||||
|
||||
public final static int NameFlagsMask = 0x87;
|
||||
|
||||
public final static int GroupName = 0x80;
|
||||
public final static int UniqueName = 0x00;
|
||||
public final static int Registering = 0x00;
|
||||
public final static int Registered = 0x04;
|
||||
public final static int Deregistered = 0x05;
|
||||
public final static int Duplicate = 0x06;
|
||||
public final static int DuplicateDereg = 0x07;
|
||||
public final static int ListenOutstanding = 0x01;
|
||||
public final static int CallPending = 0x02;
|
||||
public final static int SessionEstablished = 0x03;
|
||||
public final static int HangupPending = 0x04;
|
||||
public final static int HangupComplete = 0x05;
|
||||
public final static int SessionAborted = 0x06;
|
||||
|
||||
public final static String AllTransports = "M\0\0\0";
|
||||
|
||||
// Maximum receive size (16bits)
|
||||
//
|
||||
// Multiple receives must be issued to receive data packets over this size
|
||||
|
||||
public final static int MaxReceiveSize = 0xFFFF;
|
||||
|
||||
/**
|
||||
* Return the status string for a NetBIOS error code
|
||||
*
|
||||
* @param nbError int
|
||||
* @return String
|
||||
*/
|
||||
public final static String getErrorString(int nbError)
|
||||
{
|
||||
|
||||
String str = "";
|
||||
|
||||
switch (nbError)
|
||||
{
|
||||
case NRC_GoodRet:
|
||||
str = "Success status";
|
||||
break;
|
||||
case NRC_BufLen:
|
||||
str = "Illegal buffer length";
|
||||
break;
|
||||
case NRC_IllCmd:
|
||||
str = "Illegal command";
|
||||
break;
|
||||
case NRC_CmdTmo:
|
||||
str = "Command timed out";
|
||||
break;
|
||||
case NRC_Incomp:
|
||||
str = "Message incomplete, issue another command";
|
||||
break;
|
||||
case NRC_Baddr:
|
||||
str = "Illegal buffer address";
|
||||
break;
|
||||
case NRC_SNumOut:
|
||||
str = "Session number out of range";
|
||||
break;
|
||||
case NRC_NoRes:
|
||||
str = "No resource available";
|
||||
break;
|
||||
case NRC_SClosed:
|
||||
str = "Session closed";
|
||||
break;
|
||||
case NRC_CmdCan:
|
||||
str = "Command cancelled";
|
||||
break;
|
||||
case NRC_DupName:
|
||||
str = "Duplicate name";
|
||||
break;
|
||||
case NRC_NamTFul:
|
||||
str = "Name table full";
|
||||
break;
|
||||
case NRC_ActSes:
|
||||
str = "No deletions, name has active sessions";
|
||||
break;
|
||||
case NRC_LocTFul:
|
||||
str = "Local session table full";
|
||||
break;
|
||||
case NRC_RemTFul:
|
||||
str = "Remote session table full";
|
||||
break;
|
||||
case NRC_IllNN:
|
||||
str = "Illegal name number";
|
||||
break;
|
||||
case NRC_NoCall:
|
||||
str = "No callname";
|
||||
break;
|
||||
case NRC_NoWild:
|
||||
str = "Cannot put * in ncb_name";
|
||||
break;
|
||||
case NRC_InUse:
|
||||
str = "Name in use on remote adapter";
|
||||
break;
|
||||
case NRC_NamErr:
|
||||
str = "Name deleted";
|
||||
break;
|
||||
case NRC_SAbort:
|
||||
str = "Session ended abnormally";
|
||||
break;
|
||||
case NRC_NamConf:
|
||||
str = "Name conflict detected";
|
||||
break;
|
||||
case NRC_IfBusy:
|
||||
str = "Interface busy, IRET before retrying";
|
||||
break;
|
||||
case NRC_TooMany:
|
||||
str = "Too many commands outstanding, try later";
|
||||
break;
|
||||
case NRC_Bridge:
|
||||
str = "ncb_lana_num field invalid";
|
||||
break;
|
||||
case NRC_CanOccr:
|
||||
str = "Command completed whilst cancel occurring";
|
||||
break;
|
||||
case NRC_Cancel:
|
||||
str = "Command not valid to cancel";
|
||||
break;
|
||||
case NRC_DupEnv:
|
||||
str = "Name defined by another local process";
|
||||
break;
|
||||
case NRC_EnvNotDef:
|
||||
str = "Environment undefined, RESET required";
|
||||
break;
|
||||
case NRC_OSResNotAv:
|
||||
str = "Require OS resources exhausted";
|
||||
break;
|
||||
case NRC_MaxApps:
|
||||
str = "Max number of applications exceeded";
|
||||
break;
|
||||
case NRC_NoSaps:
|
||||
str = "No saps available for NetBIOS";
|
||||
break;
|
||||
case NRC_NoResources:
|
||||
str = "Requested resources not available";
|
||||
break;
|
||||
case NRC_InvAddress:
|
||||
str = "Invalid ncb address or length";
|
||||
break;
|
||||
case NRC_InvDDid:
|
||||
str = "Ivalid NCB DDID";
|
||||
break;
|
||||
case NRC_LockFail:
|
||||
str = "Lock of user area failed";
|
||||
break;
|
||||
case NRC_OpenErr:
|
||||
str = "NetBIOS not loaded";
|
||||
break;
|
||||
case NRC_System:
|
||||
str = "System error";
|
||||
break;
|
||||
case NRC_Pending:
|
||||
str = "Asyncrhonous command pending";
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
@@ -0,0 +1,400 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.netbios.win32;
|
||||
|
||||
import org.alfresco.filesys.netbios.NetBIOSName;
|
||||
|
||||
/**
|
||||
* NetBIOS Socket Class
|
||||
*
|
||||
* <p>Contains the details of a Winsock NetBIOS socket that was opened using native code.
|
||||
*
|
||||
* @author GKSpencer
|
||||
*/
|
||||
public class NetBIOSSocket
|
||||
{
|
||||
// Socket types
|
||||
|
||||
private static final int TypeNormal = 0;
|
||||
private static final int TypeListener = 1;
|
||||
private static final int TypeDatagram = 2;
|
||||
|
||||
// Flag to indicate if the NetBIOS socket interface has been initialized
|
||||
|
||||
private static boolean _nbSocketInit;
|
||||
|
||||
// NetBIOS LANA that the socket is associated with
|
||||
|
||||
private int m_lana;
|
||||
|
||||
// Socket pointer (Windows SOCKET)
|
||||
|
||||
private int m_socket;
|
||||
|
||||
// NetBIOS name, either listening name or callers name
|
||||
|
||||
private NetBIOSName m_nbName;
|
||||
|
||||
// Socket type
|
||||
|
||||
private int m_socketType;
|
||||
|
||||
/**
|
||||
* Initialize the Winsock NetBIOS interface
|
||||
*/
|
||||
public static final void initializeSockets()
|
||||
throws WinsockNetBIOSException {
|
||||
|
||||
// Check if the NetBIOS socket interface has been initialized
|
||||
|
||||
if ( _nbSocketInit == false)
|
||||
{
|
||||
// Initialize the NetBIOS socket interface
|
||||
|
||||
Win32NetBIOS.InitializeSockets();
|
||||
|
||||
// Indicate that the NetBIOS socket interface is initialized
|
||||
|
||||
_nbSocketInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the Winsock NetBIOS interface
|
||||
*/
|
||||
public static final void shutdownSockets()
|
||||
{
|
||||
// Check if the NetBIOS socket interface has been initialized
|
||||
|
||||
if ( _nbSocketInit == true)
|
||||
{
|
||||
// Indicate that the NetBIOS socket interface is not initialized
|
||||
|
||||
_nbSocketInit = false;
|
||||
|
||||
// Initialize the NetBIOS socket interface
|
||||
|
||||
Win32NetBIOS.ShutdownSockets();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the Winsock NetBIOS interface is initialized
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static final boolean isInitialized()
|
||||
{
|
||||
return _nbSocketInit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a NetBIOS socket to listen for incoming sessions on the specified LANA
|
||||
*
|
||||
* @param lana int
|
||||
* @param nbName NetBIOSName
|
||||
* @return NetBIOSSocket
|
||||
* @exception NetBIOSSocketException
|
||||
* @exception WinsockNetBIOSException
|
||||
*/
|
||||
public static final NetBIOSSocket createListenerSocket(int lana, NetBIOSName nbName)
|
||||
throws WinsockNetBIOSException, NetBIOSSocketException
|
||||
{
|
||||
// Initialize the Winsock NetBIOS interface
|
||||
|
||||
initializeSockets();
|
||||
|
||||
// Create a new NetBIOS socket
|
||||
|
||||
int sockPtr = Win32NetBIOS.CreateSocket(lana);
|
||||
if ( sockPtr == 0)
|
||||
throw new NetBIOSSocketException("Failed to create NetBIOS socket");
|
||||
|
||||
// Bind the socket to a NetBIOS name
|
||||
|
||||
if ( Win32NetBIOS.BindSocket( sockPtr, nbName.getNetBIOSName()) != 0)
|
||||
throw new NetBIOSSocketException("Failed to bind NetBIOS socket");
|
||||
|
||||
// Return the NetBIOS socket
|
||||
|
||||
return new NetBIOSSocket(lana, sockPtr, nbName, TypeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a NetBIOS datagram socket to send out mailslot announcements on the specified LANA
|
||||
*
|
||||
* @param lana int
|
||||
* @return NetBIOSSocket
|
||||
* @exception NetBIOSSocketException
|
||||
* @exception WinsockNetBIOSException
|
||||
*/
|
||||
public static final NetBIOSSocket createDatagramSocket(int lana)
|
||||
throws WinsockNetBIOSException, NetBIOSSocketException
|
||||
{
|
||||
// Initialize the Winsock NetBIOS interface
|
||||
|
||||
initializeSockets();
|
||||
|
||||
// Create a new NetBIOS socket
|
||||
|
||||
int sockPtr = Win32NetBIOS.CreateDatagramSocket(lana);
|
||||
if ( sockPtr == 0)
|
||||
throw new NetBIOSSocketException("Failed to create NetBIOS datagram socket");
|
||||
|
||||
// Return the NetBIOS socket
|
||||
|
||||
return new NetBIOSSocket(lana, sockPtr, null, TypeDatagram);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param lana int
|
||||
* @param sockPtr int
|
||||
* @param nbName NetBIOSName
|
||||
* @param sockerType int
|
||||
*/
|
||||
private NetBIOSSocket(int lana, int sockPtr, NetBIOSName nbName, int socketType)
|
||||
{
|
||||
m_lana = lana;
|
||||
m_nbName = nbName;
|
||||
m_socket = sockPtr;
|
||||
|
||||
m_socketType = socketType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the NetBIOS LANA the socket is associated with
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public final int getLana()
|
||||
{
|
||||
return m_lana;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this is a datagram socket
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isDatagramSocket()
|
||||
{
|
||||
return m_socketType == TypeDatagram ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this is a listener type socket
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isListener()
|
||||
{
|
||||
return m_socketType == TypeListener ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the socket is valid
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean hasSocket()
|
||||
{
|
||||
return m_socket != 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the socket pointer
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public final int getSocket()
|
||||
{
|
||||
return m_socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the NetBIOS name. For a listening socket this is the local name, for a session
|
||||
* socket this is the remote callers name.
|
||||
*
|
||||
* @return NetBIOSName
|
||||
*/
|
||||
public final NetBIOSName getName()
|
||||
{
|
||||
return m_nbName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to the session socket
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException
|
||||
*/
|
||||
public final int write(byte[] buf, int off, int len)
|
||||
throws WinsockNetBIOSException
|
||||
{
|
||||
// Check if this is a datagram socket
|
||||
|
||||
if ( isDatagramSocket())
|
||||
throw new WinsockNetBIOSException("Write not allowed for datagram socket");
|
||||
|
||||
return Win32NetBIOS.SendSocket( getSocket(), buf, off, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read data from the session socket
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param maxLen int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException
|
||||
*/
|
||||
public final int read(byte[] buf, int off, int maxLen)
|
||||
throws WinsockNetBIOSException
|
||||
{
|
||||
// Check if this is a datagram socket
|
||||
|
||||
if ( isDatagramSocket())
|
||||
throw new WinsockNetBIOSException("Read not allowed for datagram socket");
|
||||
|
||||
return Win32NetBIOS.ReceiveSocket( getSocket(), buf, off, maxLen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a datagram to a group name
|
||||
*
|
||||
* @param toName NetBIOSName
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException
|
||||
*/
|
||||
public final int sendDatagram(NetBIOSName toName, byte[] buf, int off, int len)
|
||||
throws WinsockNetBIOSException
|
||||
{
|
||||
// Check if this is a datagram socket
|
||||
|
||||
if ( isDatagramSocket() == false)
|
||||
throw new WinsockNetBIOSException("Not a datagram type socket");
|
||||
|
||||
return Win32NetBIOS.SendSocketDatagram( getSocket(), toName.getNetBIOSName(), buf, off, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen for an incoming session connection and create a session socket for the new session
|
||||
*
|
||||
* @return NetBIOSSocket
|
||||
* @exception NetBIOSSocketException
|
||||
* @exception winsockNetBIOSException
|
||||
*/
|
||||
public final NetBIOSSocket listen()
|
||||
throws WinsockNetBIOSException, NetBIOSSocketException
|
||||
{
|
||||
// Check if this socket is a listener socket, and the socket is valid
|
||||
|
||||
if ( isListener() == false)
|
||||
throw new NetBIOSSocketException("Not a listener type socket");
|
||||
|
||||
if ( hasSocket() == false)
|
||||
throw new NetBIOSSocketException("NetBIOS socket not valid");
|
||||
|
||||
// Wait for an incoming session request
|
||||
|
||||
byte[] callerName = new byte[NetBIOSName.NameLength];
|
||||
|
||||
int sessSockPtr = Win32NetBIOS.ListenSocket( getSocket(), callerName);
|
||||
if ( sessSockPtr == 0)
|
||||
throw new NetBIOSSocketException("NetBIOS socket listen failed");
|
||||
|
||||
// Return the new NetBIOS socket session
|
||||
|
||||
return new NetBIOSSocket(getLana(), sessSockPtr, new NetBIOSName(callerName, 0), TypeNormal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the socket
|
||||
*/
|
||||
public final void closeSocket()
|
||||
{
|
||||
// Close the native socket, if valid
|
||||
|
||||
if ( hasSocket())
|
||||
{
|
||||
Win32NetBIOS.CloseSocket( getSocket());
|
||||
setSocket(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the socket pointer
|
||||
*
|
||||
* @param sockPtr int
|
||||
*/
|
||||
protected final void setSocket(int sockPtr)
|
||||
{
|
||||
m_socket = sockPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the NetBIOS socket details as a string
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
str.append("[LANA:");
|
||||
str.append(getLana());
|
||||
str.append(",Name:");
|
||||
if ( getName() != null)
|
||||
str.append(getName());
|
||||
else
|
||||
str.append("<None>");
|
||||
|
||||
str.append(",Socket:");
|
||||
if ( hasSocket())
|
||||
{
|
||||
str.append("0x");
|
||||
str.append(Integer.toHexString(getSocket()));
|
||||
}
|
||||
else
|
||||
str.append("<None>");
|
||||
|
||||
switch( m_socketType)
|
||||
{
|
||||
case TypeNormal:
|
||||
str.append("Session");
|
||||
break;
|
||||
case TypeListener:
|
||||
str.append("Listener");
|
||||
break;
|
||||
case TypeDatagram:
|
||||
str.append("Datagram");
|
||||
break;
|
||||
}
|
||||
|
||||
str.append("]");
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.netbios.win32;
|
||||
|
||||
/**
|
||||
* NetBIOS Socket Exception Class
|
||||
*
|
||||
* @author GKSpencer
|
||||
*/
|
||||
public class NetBIOSSocketException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 2363178480979507007L;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param msg String
|
||||
*/
|
||||
public NetBIOSSocketException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
}
|
||||
}
|
713
source/java/org/alfresco/filesys/netbios/win32/Win32NetBIOS.java
Normal file
713
source/java/org/alfresco/filesys/netbios/win32/Win32NetBIOS.java
Normal file
@@ -0,0 +1,713 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.netbios.win32;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.alfresco.filesys.netbios.NetBIOSName;
|
||||
import org.alfresco.filesys.util.DataBuffer;
|
||||
import org.alfresco.filesys.util.IPAddress;
|
||||
|
||||
/**
|
||||
* Win32 NetBIOS Native Call Wrapper Class
|
||||
*/
|
||||
public class Win32NetBIOS
|
||||
{
|
||||
|
||||
// Constants
|
||||
//
|
||||
// FIND_NAME_BUFFER structure length
|
||||
|
||||
protected final static int FindNameBufferLen = 33;
|
||||
|
||||
// Exception if the native code DLL load failed
|
||||
|
||||
private static Throwable m_loadDLLException;
|
||||
|
||||
/**
|
||||
* Check if the native code was loaded successfully
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static final boolean isInitialized()
|
||||
{
|
||||
return m_loadDLLException == null ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the native code load exception
|
||||
*
|
||||
* @return Throwable
|
||||
*/
|
||||
public static final Throwable getInitializationException()
|
||||
{
|
||||
return m_loadDLLException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if NetBIOS is enabled on any network adapters
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static final boolean isAvailable() {
|
||||
|
||||
// Check if the DLL was loaded successfully
|
||||
|
||||
if ( isInitialized() == false)
|
||||
return false;
|
||||
|
||||
// Check if there are any valid LANAs, if not then NetBIOS is not enabled or network
|
||||
// adapters that have NetBIOS enabled are not currently enabled
|
||||
|
||||
int[] lanas = LanaEnum();
|
||||
if ( lanas != null && lanas.length > 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a NetBIOS name to the local name table
|
||||
*
|
||||
* @param lana int
|
||||
* @param name byte[]
|
||||
* @return int
|
||||
*/
|
||||
public static native int AddName(int lana, byte[] name);
|
||||
|
||||
/**
|
||||
* Add a group NetBIOS name to the local name table
|
||||
*
|
||||
* @param lana int
|
||||
* @param name byte[]
|
||||
* @return int
|
||||
*/
|
||||
public static native int AddGroupName(int lana, byte[] name);
|
||||
|
||||
/**
|
||||
* Find a NetBIOS name, return the name buffer
|
||||
*
|
||||
* @param lana int
|
||||
* @param name byte[]
|
||||
* @param nameBuf byte[]
|
||||
* @param bufLen int
|
||||
* @return int
|
||||
*/
|
||||
public static native int FindNameRaw(int lana, byte[] name, byte[] nameBuf, int bufLen);
|
||||
|
||||
/**
|
||||
* Find a NetBIOS name
|
||||
*
|
||||
* @param lana int
|
||||
* @param name NetBIOSName
|
||||
* @return int
|
||||
*/
|
||||
public static int FindName(int lana, NetBIOSName nbName)
|
||||
{
|
||||
|
||||
// Allocate a buffer to receive the name details
|
||||
|
||||
byte[] nameBuf = new byte[nbName.isGroupName() ? 65535 : 4096];
|
||||
|
||||
// Get the raw NetBIOS name data
|
||||
|
||||
int sts = FindNameRaw(lana, nbName.getNetBIOSName(), nameBuf, nameBuf.length);
|
||||
|
||||
if (sts != NetBIOS.NRC_GoodRet)
|
||||
return -sts;
|
||||
|
||||
// Unpack the FIND_NAME_HEADER structure
|
||||
|
||||
DataBuffer buf = new DataBuffer(nameBuf, 0, nameBuf.length);
|
||||
|
||||
int nodeCount = buf.getShort();
|
||||
buf.skipBytes(1);
|
||||
boolean isGroupName = buf.getByte() == 0 ? false : true;
|
||||
|
||||
// Unpack the FIND_NAME_BUFFER structures
|
||||
|
||||
int curPos = buf.getPosition();
|
||||
|
||||
for (int i = 0; i < nodeCount; i++)
|
||||
{
|
||||
|
||||
// FIND_NAME_BUFFER:
|
||||
// UCHAR length
|
||||
// UCHAR access_control
|
||||
// UCHAR frame_control
|
||||
// UCHAR destination_addr[6]
|
||||
// UCHAR source_addr[6]
|
||||
// UCHAR routing_info[18]
|
||||
|
||||
// Skip to the source_addr field
|
||||
|
||||
buf.skipBytes(9);
|
||||
|
||||
// Source address field format should be 0.0.n.n.n.n for TCP/IP address
|
||||
|
||||
if (buf.getByte() == 0 && buf.getByte() == 0)
|
||||
{
|
||||
|
||||
// Looks like a TCP/IP format address, unpack it
|
||||
|
||||
byte[] ipAddr = new byte[4];
|
||||
|
||||
ipAddr[0] = (byte) buf.getByte();
|
||||
ipAddr[1] = (byte) buf.getByte();
|
||||
ipAddr[2] = (byte) buf.getByte();
|
||||
ipAddr[3] = (byte) buf.getByte();
|
||||
|
||||
// Add the address to the list of TCP/IP addresses for the NetBIOS name
|
||||
|
||||
nbName.addIPAddress(ipAddr);
|
||||
|
||||
// Skip to the start of the next FIND_NAME_BUFFER structure
|
||||
|
||||
curPos += FindNameBufferLen;
|
||||
buf.setPosition(curPos);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the node count
|
||||
|
||||
return nodeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a NetBIOS name from the local name table
|
||||
*
|
||||
* @param lana int
|
||||
* @param name byte[]
|
||||
* @return int
|
||||
*/
|
||||
public static native int DeleteName(int lana, byte[] name);
|
||||
|
||||
/**
|
||||
* Enumerate the available LANAs
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public static int[] LanaEnumerate()
|
||||
{
|
||||
// Make sure that there is an active network adapter as making calls to the LanaEnum native call
|
||||
// causes problems when there are no active network adapters.
|
||||
|
||||
boolean adapterAvail = false;
|
||||
|
||||
try
|
||||
{
|
||||
// Enumerate the available network adapters and check for an active adapter, not including
|
||||
// the loopback adapter
|
||||
|
||||
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
while ( nis.hasMoreElements() && adapterAvail == false)
|
||||
{
|
||||
NetworkInterface ni = nis.nextElement();
|
||||
if ( ni.getName().equals("lo") == false)
|
||||
{
|
||||
// Make sure the adapter has a valid IP address
|
||||
|
||||
Enumeration<InetAddress> addrs = ni.getInetAddresses();
|
||||
if ( addrs.hasMoreElements())
|
||||
adapterAvail = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch ( SocketException ex)
|
||||
{
|
||||
}
|
||||
|
||||
// Check if there are network adapter(s) available
|
||||
|
||||
if ( adapterAvail == false)
|
||||
return null;
|
||||
|
||||
// Call the native code to return the available LANA list
|
||||
|
||||
return LanaEnum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerate the available LANAs
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
private static native int[] LanaEnum();
|
||||
|
||||
/**
|
||||
* Reset the NetBIOS environment
|
||||
*
|
||||
* @param lana int
|
||||
* @return int
|
||||
*/
|
||||
public static native int Reset(int lana);
|
||||
|
||||
/**
|
||||
* Listen for an incoming session request
|
||||
*
|
||||
* @param lana int
|
||||
* @param toName byte[]
|
||||
* @param fromName byte[]
|
||||
* @param callerName byte[]
|
||||
* @return int
|
||||
*/
|
||||
public static native int Listen(int lana, byte[] toName, byte[] fromName, byte[] callerName);
|
||||
|
||||
/**
|
||||
* Receive a data packet on a session
|
||||
*
|
||||
* @param lana int
|
||||
* @param lsn int
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param maxLen int
|
||||
* @return int
|
||||
*/
|
||||
public static native int Receive(int lana, int lsn, byte[] buf, int off, int maxLen);
|
||||
|
||||
/**
|
||||
* Send a data packet on a session
|
||||
*
|
||||
* @param lana int
|
||||
* @param lsn int
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
*/
|
||||
public static native int Send(int lana, int lsn, byte[] buf, int off, int len);
|
||||
|
||||
/**
|
||||
* Send a datagram to a specified name
|
||||
*
|
||||
* @param lana int
|
||||
* @param srcNum int
|
||||
* @param destName byte[]
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
*/
|
||||
public static native int SendDatagram(int lana, int srcNum, byte[] destName, byte[] buf, int off, int len);
|
||||
|
||||
/**
|
||||
* Send a broadcast datagram
|
||||
*
|
||||
* @param lana
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
*/
|
||||
public static native int SendBroadcastDatagram(int lana, byte[] buf, int off, int len);
|
||||
|
||||
/**
|
||||
* Receive a datagram on a specified name
|
||||
*
|
||||
* @param lana int
|
||||
* @param nameNum int
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param maxLen int
|
||||
* @return int
|
||||
*/
|
||||
public static native int ReceiveDatagram(int lana, int nameNum, byte[] buf, int off, int maxLen);
|
||||
|
||||
/**
|
||||
* Receive a broadcast datagram
|
||||
*
|
||||
* @param lana int
|
||||
* @param nameNum int
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param maxLen int
|
||||
* @return int
|
||||
*/
|
||||
public static native int ReceiveBroadcastDatagram(int lana, int nameNum, byte[] buf, int off, int maxLen);
|
||||
|
||||
/**
|
||||
* Hangup a session
|
||||
*
|
||||
* @param lsn int
|
||||
* @return int
|
||||
*/
|
||||
public static native int Hangup(int lana, int lsn);
|
||||
|
||||
/**
|
||||
* Return the local computers NetBIOS name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static native String GetLocalNetBIOSName();
|
||||
|
||||
/**
|
||||
* Return the local domain name
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static native String GetLocalDomainName();
|
||||
|
||||
/**
|
||||
* Return a comma delimeted list of WINS server TCP/IP addresses, or null if no WINS servers are
|
||||
* configured.
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static native String getWINSServerList();
|
||||
|
||||
/**
|
||||
* Find the TCP/IP address for a LANA
|
||||
*
|
||||
* @param lana int
|
||||
* @return String
|
||||
*/
|
||||
public static final String getIPAddressForLANA(int lana)
|
||||
{
|
||||
|
||||
// Get the local NetBIOS name
|
||||
|
||||
String localName = GetLocalNetBIOSName();
|
||||
if (localName == null)
|
||||
return null;
|
||||
|
||||
// Create a NetBIOS name for the local name
|
||||
|
||||
NetBIOSName nbName = new NetBIOSName(localName, NetBIOSName.WorkStation, false);
|
||||
|
||||
// Get the local NetBIOS name details
|
||||
|
||||
int sts = FindName(lana, nbName);
|
||||
|
||||
if (sts == -NetBIOS.NRC_EnvNotDef)
|
||||
{
|
||||
|
||||
// Reset the LANA then try the name lookup again
|
||||
|
||||
Reset(lana);
|
||||
sts = FindName(lana, nbName);
|
||||
}
|
||||
|
||||
// Check if the name lookup was successful
|
||||
|
||||
String ipAddr = null;
|
||||
|
||||
if (sts >= 0)
|
||||
{
|
||||
|
||||
// Get the first IP address from the list
|
||||
|
||||
ipAddr = nbName.getIPAddressString(0);
|
||||
}
|
||||
|
||||
// Return the TCP/IP address for the LANA
|
||||
|
||||
return ipAddr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the adapter name for a LANA
|
||||
*
|
||||
* @param lana int
|
||||
* @return String
|
||||
*/
|
||||
public static final String getAdapterNameForLANA(int lana)
|
||||
{
|
||||
|
||||
// Get the TCP/IP address for a LANA
|
||||
|
||||
String ipAddr = getIPAddressForLANA(lana);
|
||||
if (ipAddr == null)
|
||||
return null;
|
||||
|
||||
// Get the list of available network adapters
|
||||
|
||||
Hashtable<String, NetworkInterface> adapters = getNetworkAdapterList();
|
||||
String adapterName = null;
|
||||
|
||||
if (adapters != null)
|
||||
{
|
||||
|
||||
// Find the network adapter for the TCP/IP address
|
||||
|
||||
NetworkInterface ni = adapters.get(ipAddr);
|
||||
if (ni != null)
|
||||
adapterName = ni.getDisplayName();
|
||||
}
|
||||
|
||||
// Return the adapter name for the LANA
|
||||
|
||||
return adapterName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the LANA for a TCP/IP address
|
||||
*
|
||||
* @param addr String
|
||||
* @return int
|
||||
*/
|
||||
public static final int getLANAForIPAddress(String addr)
|
||||
{
|
||||
|
||||
// Check if the address is a numeric TCP/IP address
|
||||
|
||||
if (IPAddress.isNumericAddress(addr) == false)
|
||||
return -1;
|
||||
|
||||
// Get a list of the available NetBIOS LANAs
|
||||
|
||||
int[] lanas = LanaEnum();
|
||||
if (lanas == null || lanas.length == 0)
|
||||
return -1;
|
||||
|
||||
// Search for the LANA with the matching TCP/IP address
|
||||
|
||||
for (int i = 0; i < lanas.length; i++)
|
||||
{
|
||||
|
||||
// Get the current LANAs TCP/IP address
|
||||
|
||||
String curAddr = getIPAddressForLANA(lanas[i]);
|
||||
if (curAddr != null && curAddr.equals(addr))
|
||||
return lanas[i];
|
||||
}
|
||||
|
||||
// Failed to find the LANA for the specified TCP/IP address
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the LANA for a network adapter
|
||||
*
|
||||
* @param name String
|
||||
* @return int
|
||||
*/
|
||||
public static final int getLANAForAdapterName(String name)
|
||||
{
|
||||
|
||||
// Get the list of available network adapters
|
||||
|
||||
Hashtable<String, NetworkInterface> niList = getNetworkAdapterList();
|
||||
|
||||
// Search for the address of the specified network adapter
|
||||
|
||||
Enumeration<String> niEnum = niList.keys();
|
||||
|
||||
while (niEnum.hasMoreElements())
|
||||
{
|
||||
|
||||
// Get the current TCP/IP address
|
||||
|
||||
String ipAddr = niEnum.nextElement();
|
||||
NetworkInterface ni = niList.get(ipAddr);
|
||||
|
||||
if (ni.getDisplayName().equalsIgnoreCase(name))
|
||||
{
|
||||
|
||||
// Return the LANA for the network adapters TCP/IP address
|
||||
|
||||
return getLANAForIPAddress(ipAddr);
|
||||
}
|
||||
}
|
||||
|
||||
// Failed to find matching network adapter
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a hashtable of NetworkInterfaces indexed by TCP/IP address
|
||||
*
|
||||
* @return Hashtable<String,NetworkInterface>
|
||||
*/
|
||||
private static final Hashtable<String, NetworkInterface> getNetworkAdapterList()
|
||||
{
|
||||
|
||||
// Get a list of the local network adapters
|
||||
|
||||
Hashtable<String, NetworkInterface> niList = new Hashtable<String, NetworkInterface>();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Enumerate the available network adapters
|
||||
|
||||
Enumeration<NetworkInterface> niEnum = NetworkInterface.getNetworkInterfaces();
|
||||
|
||||
while (niEnum.hasMoreElements())
|
||||
{
|
||||
|
||||
// Get the current network interface details
|
||||
|
||||
NetworkInterface ni = niEnum.nextElement();
|
||||
Enumeration<InetAddress> addrEnum = ni.getInetAddresses();
|
||||
|
||||
while (addrEnum.hasMoreElements())
|
||||
{
|
||||
|
||||
// Get the address and add the adapter to the list indexed via the numeric IP
|
||||
// address string
|
||||
|
||||
InetAddress addr = addrEnum.nextElement();
|
||||
niList.put(addr.getHostAddress(), ni);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
// Return the network adapter list
|
||||
|
||||
return niList;
|
||||
}
|
||||
|
||||
//---------- Winsock based NetBIOS interface ----------//
|
||||
|
||||
/**
|
||||
* Initialize the NetBIOS socket interface
|
||||
*
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native void InitializeSockets()
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Shutdown the NetBIOS socket interface
|
||||
*/
|
||||
protected static native void ShutdownSockets();
|
||||
|
||||
/**
|
||||
* Create a NetBIOS socket
|
||||
*
|
||||
* @param lana int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int CreateSocket(int lana)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Create a NetBIOS datagram socket
|
||||
*
|
||||
* @param lana int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int CreateDatagramSocket(int lana)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Bind a NetBIOS socket to a name to listen for incoming sessions
|
||||
*
|
||||
* @param sockPtr int
|
||||
* @param name byte[]
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int BindSocket(int sockPtr, byte[] name)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Listen for an incoming connection
|
||||
*
|
||||
* @param sockPtr int
|
||||
* @param callerName byte[]
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int ListenSocket(int sockPtr, byte[] callerName)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Close a NetBIOS socket
|
||||
*
|
||||
* @param sockPtr int
|
||||
*/
|
||||
protected static native void CloseSocket(int sockPtr);
|
||||
|
||||
/**
|
||||
* Send data on a session socket
|
||||
*
|
||||
* @param sockPtr int
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int SendSocket(int sockPtr, byte[] buf, int off, int len)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Receive data on a session socket
|
||||
*
|
||||
* @param sockPtr int
|
||||
* @param toName byte[]
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param maxLen int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int ReceiveSocket(int sockPtr, byte[] buf, int off, int maxLen)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Send data on a datagram socket
|
||||
*
|
||||
* @param sockPtr int
|
||||
* @param toName byte[]
|
||||
* @param buf byte[]
|
||||
* @param off int
|
||||
* @param len int
|
||||
* @return int
|
||||
* @exception WinsockNetBIOSException If a Winsock error occurs
|
||||
*/
|
||||
protected static native int SendSocketDatagram(int sockPtr, byte[] toName, byte[] buf, int off, int len)
|
||||
throws WinsockNetBIOSException;
|
||||
|
||||
/**
|
||||
* Wait for a network address change event, block until a change occurs or the Winsock NetBIOS
|
||||
* interface is shut down
|
||||
*/
|
||||
public static native void waitForNetworkAddressChange();
|
||||
|
||||
/**
|
||||
* Static initializer used to load the native code library
|
||||
*/
|
||||
static
|
||||
{
|
||||
|
||||
// Load the Win32 NetBIOS interface library
|
||||
|
||||
try
|
||||
{
|
||||
System.loadLibrary("Win32NetBIOS");
|
||||
}
|
||||
catch (Throwable ex)
|
||||
{
|
||||
// Save the native code load exception
|
||||
|
||||
m_loadDLLException = ex;
|
||||
}
|
||||
}
|
||||
}
|
223
source/java/org/alfresco/filesys/netbios/win32/WinsockError.java
Normal file
223
source/java/org/alfresco/filesys/netbios/win32/WinsockError.java
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.netbios.win32;
|
||||
|
||||
/**
|
||||
* Winsock Error Codes Class
|
||||
*
|
||||
* <p>Contains a list of the error codes that the Win32 Winsock calls may generate, and a method to convert
|
||||
* to an error text string.
|
||||
*
|
||||
* @author GKSpencer
|
||||
*/
|
||||
public class WinsockError
|
||||
{
|
||||
// Winsock error code constants
|
||||
|
||||
public static final int WsaEIntr = 10004;
|
||||
public static final int WsaEAcces = 10013;
|
||||
public static final int WsaEFault = 10014;
|
||||
public static final int WsaEInval = 10022;
|
||||
public static final int WsaEMfile = 10024;
|
||||
public static final int WsaEWouldBlock = 10035;
|
||||
public static final int WsaEInProgress = 10036;
|
||||
public static final int WsaEAlready = 10037;
|
||||
public static final int WsaENotSock = 10038;
|
||||
public static final int WsaEDestAddrReq = 10039;
|
||||
public static final int WsaEMsgSize = 10040;
|
||||
public static final int WsaEPrototype = 10041;
|
||||
public static final int WsaENoProtoOpt = 10042;
|
||||
public static final int WsaEProtoNoSupp = 10043;
|
||||
public static final int WsaESocktNoSupp = 10044;
|
||||
public static final int WsaEOpNotSupp = 10045;
|
||||
public static final int WsaEPFNoSupport = 10046;
|
||||
public static final int WsaEAFNoSupport = 10047;
|
||||
public static final int WsaEAddrInUse = 10048;
|
||||
public static final int WsaEAddrNotAvail= 10049;
|
||||
public static final int WsaENetDown = 10050;
|
||||
public static final int WsaENetUnReach = 10051;
|
||||
public static final int WsaENetReset = 10052;
|
||||
public static final int WsaEConnAborted = 10053;
|
||||
public static final int WsaEConnReset = 10054;
|
||||
public static final int WsaENoBufs = 10055;
|
||||
public static final int WsaEIsConn = 10056;
|
||||
public static final int WsaENotConn = 10057;
|
||||
public static final int WsaEShutdown = 10058;
|
||||
public static final int WsaETimedout = 10060;
|
||||
public static final int WsaEConnRefused = 10061;
|
||||
public static final int WsaEHostDown = 10064;
|
||||
public static final int WsaEHostUnreach = 10065;
|
||||
public static final int WsaEProcLim = 10067;
|
||||
public static final int WsaSysNotReady = 10091;
|
||||
public static final int WsaVerNotSupp = 10092;
|
||||
public static final int WsaNotInit = 10093;
|
||||
public static final int WsaEDiscon = 10101;
|
||||
public static final int WsaTypeNotFound = 10109;
|
||||
public static final int WsaHostNotFound = 11001;
|
||||
public static final int WsaTryAgain = 11002;
|
||||
public static final int WsaNoRecovery = 11003;
|
||||
public static final int WsaNoData = 11004;
|
||||
|
||||
/**
|
||||
* Convert a Winsock error code to a text string
|
||||
*
|
||||
* @param sts int
|
||||
* @return String
|
||||
*/
|
||||
public static final String asString(int sts)
|
||||
{
|
||||
String errText = null;
|
||||
|
||||
switch ( sts)
|
||||
{
|
||||
case WsaEIntr:
|
||||
errText = "Interrupted function call";
|
||||
break;
|
||||
case WsaEAcces:
|
||||
errText = "Permission denied";
|
||||
break;
|
||||
case WsaEFault:
|
||||
errText = "Bad address";
|
||||
break;
|
||||
case WsaEInval:
|
||||
errText = "Invalid argument";
|
||||
break;
|
||||
case WsaEMfile:
|
||||
errText = "Too many open files";
|
||||
break;
|
||||
case WsaEWouldBlock:
|
||||
errText = "Resource temporarily unavailable";
|
||||
break;
|
||||
case WsaEInProgress:
|
||||
errText = "Operation now in progress";
|
||||
break;
|
||||
case WsaEAlready:
|
||||
errText = "Operation already in progress";
|
||||
break;
|
||||
case WsaENotSock:
|
||||
errText = "Socket operation on nonsocket";
|
||||
break;
|
||||
case WsaEDestAddrReq:
|
||||
errText = "Destination address required";
|
||||
break;
|
||||
case WsaEMsgSize:
|
||||
errText = "Message too long";
|
||||
break;
|
||||
case WsaEPrototype:
|
||||
errText = "Protocol wrong type for socket";
|
||||
break;
|
||||
case WsaENoProtoOpt:
|
||||
errText = "Bad protocol option";
|
||||
break;
|
||||
case WsaEProtoNoSupp:
|
||||
errText = "Protocol not supported";
|
||||
break;
|
||||
case WsaESocktNoSupp:
|
||||
errText = "Socket type not supported";
|
||||
break;
|
||||
case WsaEOpNotSupp:
|
||||
errText = "Operation not supported";
|
||||
break;
|
||||
case WsaEPFNoSupport:
|
||||
errText = "Protocol family not supported";
|
||||
break;
|
||||
case WsaEAFNoSupport:
|
||||
errText = "Address family not supported by protocol family";
|
||||
break;
|
||||
case WsaEAddrInUse:
|
||||
errText = "Address already in use";
|
||||
break;
|
||||
case WsaEAddrNotAvail:
|
||||
errText = "Cannot assign requested address";
|
||||
break;
|
||||
case WsaENetDown:
|
||||
errText = "Network is down";
|
||||
break;
|
||||
case WsaENetUnReach:
|
||||
errText = "Network is unreachable";
|
||||
break;
|
||||
case WsaENetReset:
|
||||
errText = "Network dropped connection on reset";
|
||||
break;
|
||||
case WsaEConnAborted:
|
||||
errText = "Software caused connection abort";
|
||||
break;
|
||||
case WsaEConnReset:
|
||||
errText = "Connection reset by peer";
|
||||
break;
|
||||
case WsaENoBufs:
|
||||
errText = "No buffer space available";
|
||||
break;
|
||||
case WsaEIsConn:
|
||||
errText = "Socket is already connected";
|
||||
break;
|
||||
case WsaENotConn:
|
||||
errText = "Socket is not connected";
|
||||
break;
|
||||
case WsaEShutdown:
|
||||
errText = "Cannot send after socket shutdown";
|
||||
break;
|
||||
case WsaETimedout:
|
||||
errText = "Connection timed out";
|
||||
break;
|
||||
case WsaEConnRefused:
|
||||
errText = "Connection refused";
|
||||
break;
|
||||
case WsaEHostDown:
|
||||
errText = "Host is down";
|
||||
break;
|
||||
case WsaEHostUnreach:
|
||||
errText = "No route to host";
|
||||
break;
|
||||
case WsaEProcLim:
|
||||
errText = "Too many processes";
|
||||
break;
|
||||
case WsaSysNotReady:
|
||||
errText = "Network subsystem is unavailable";
|
||||
break;
|
||||
case WsaVerNotSupp:
|
||||
errText = "Winsock.dll version out of range";
|
||||
break;
|
||||
case WsaNotInit:
|
||||
errText = "Successful WSAStartup not yet performed";
|
||||
break;
|
||||
case WsaEDiscon:
|
||||
errText = "Graceful shutdown in progress";
|
||||
break;
|
||||
case WsaTypeNotFound:
|
||||
errText = "Class type not found";
|
||||
break;
|
||||
case WsaHostNotFound:
|
||||
errText = "Host not found";
|
||||
break;
|
||||
case WsaTryAgain:
|
||||
errText = "Nonauthoritative host not found";
|
||||
break;
|
||||
case WsaNoRecovery:
|
||||
errText = "This is a nonrecoverable error";
|
||||
break;
|
||||
case WsaNoData:
|
||||
errText = "Valid name, no data record of requested type";
|
||||
break;
|
||||
default:
|
||||
errText = "Unknown Winsock error 0x" + Integer.toHexString(sts);
|
||||
break;
|
||||
}
|
||||
|
||||
return errText;
|
||||
}
|
||||
}
|
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.netbios.win32;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Winsock NetBIOS Exception Class
|
||||
*
|
||||
* <p>Contains the Winsock error code from the failed Winsock call.
|
||||
*
|
||||
* @author GKSpencer
|
||||
*/
|
||||
public class WinsockNetBIOSException extends IOException
|
||||
{
|
||||
private static final long serialVersionUID = 5933702607108016674L;
|
||||
|
||||
// Winsock error code
|
||||
|
||||
private int m_errCode;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public WinsockNetBIOSException()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param msg String
|
||||
*/
|
||||
public WinsockNetBIOSException(String msg)
|
||||
{
|
||||
super(msg);
|
||||
|
||||
// Split out the error code
|
||||
|
||||
if ( msg != null)
|
||||
{
|
||||
int pos = msg.indexOf(":");
|
||||
if ( pos != -1)
|
||||
m_errCode = Integer.valueOf(msg.substring(0, pos));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param sts int
|
||||
*/
|
||||
public WinsockNetBIOSException(int sts)
|
||||
{
|
||||
super();
|
||||
|
||||
m_errCode = sts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Winsock error code
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public final int getErrorCode()
|
||||
{
|
||||
return m_errCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the error code
|
||||
*
|
||||
* @param sts int
|
||||
*/
|
||||
public final void setErrorCode(int sts)
|
||||
{
|
||||
m_errCode = sts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the error message string
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
StringBuilder msg = new StringBuilder();
|
||||
|
||||
msg.append( super.getMessage());
|
||||
String winsockErr = WinsockError.asString(getErrorCode());
|
||||
if ( winsockErr != null)
|
||||
{
|
||||
msg.append(" - ");
|
||||
msg.append(winsockErr);
|
||||
}
|
||||
|
||||
return msg.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user