1 17 package org.alfresco.filesys.smb.mailslot; 18 19 import java.net.InetAddress ; 20 import java.net.UnknownHostException ; 21 22 import org.alfresco.filesys.netbios.NetBIOSDatagram; 23 import org.alfresco.filesys.netbios.NetBIOSDatagramSocket; 24 import org.alfresco.filesys.netbios.NetBIOSName; 25 import org.alfresco.filesys.netbios.NetworkSettings; 26 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 27 28 33 public class TcpipNetBIOSHostAnnouncer extends HostAnnouncer 34 { 35 36 38 public static final int PORT = RFCNetBIOSProtocol.DATAGRAM; 39 public static final int INTERVAL = 1; 41 43 private InetAddress m_bindAddress; 44 private int m_port; 45 46 48 private InetAddress m_bcastAddr; 49 private int m_bcastPort = RFCNetBIOSProtocol.DATAGRAM; 50 51 53 private NetBIOSDatagram m_nbdgram; 54 55 58 public TcpipNetBIOSHostAnnouncer() 59 { 60 61 63 setPort(PORT); 64 setInterval(INTERVAL); 65 } 66 67 75 public TcpipNetBIOSHostAnnouncer(String name, String domain, int intval, int port) 76 { 77 78 80 addHostName(name); 81 setDomain(domain); 82 setInterval(intval); 83 84 86 if (port == 0) 87 setPort(PORT); 88 else 89 setPort(port); 90 } 91 92 97 public final InetAddress getBindAddress() 98 { 99 return m_bindAddress; 100 } 101 102 107 public final int getPort() 108 { 109 return m_port; 110 } 111 112 117 public final boolean hasBindAddress() 118 { 119 return m_bindAddress != null ? true : false; 120 } 121 122 128 public final void setBroadcastAddress(String addr) throws UnknownHostException 129 { 130 m_bcastAddr = InetAddress.getByName(addr); 131 } 132 133 140 public final void setBroadcastAddress(String addr, int port) throws UnknownHostException 141 { 142 m_bcastAddr = InetAddress.getByName(addr); 143 m_bcastPort = port; 144 } 145 146 151 protected void initialize() throws Exception 152 { 153 154 156 if (hasBindAddress() == false) 157 setName("TCPHostAnnouncer"); 158 else 159 setName("TCPHostAnnouncer_" + getBindAddress().getHostAddress()); 160 161 163 if (numberOfNames() == 0) 164 { 165 166 168 addHostName(InetAddress.getLocalHost().getHostName()); 169 } 170 171 173 m_nbdgram = new NetBIOSDatagram(512); 174 175 177 if (m_bcastAddr == null) 178 m_bcastAddr = InetAddress.getByName(NetworkSettings.GenerateBroadcastMask(null)); 179 } 180 181 186 public boolean isNetworkEnabled() 187 { 188 return true; 189 } 190 191 199 protected void sendAnnouncement(String hostName, byte[] buf, int offset, int len) throws Exception 200 { 201 202 204 m_nbdgram.SendDatagram(NetBIOSDatagram.DIRECT_GROUP, hostName, NetBIOSName.FileServer, getDomain(), 205 NetBIOSName.MasterBrowser, buf, len, offset); 206 } 207 208 213 public final void setBindAddress(InetAddress addr) 214 { 215 m_bindAddress = addr; 216 NetBIOSDatagramSocket.setBindAddress(addr); 217 } 218 219 224 public final void setPort(int port) 225 { 226 m_port = port; 227 NetBIOSDatagramSocket.setDefaultPort(port); 228 } 229 } | Popular Tags |