[Javanetsim-cvs] javaNetSim/core/protocolsuite/tcp_ip SNMP.java,1.9,1.10 Telnet_client.java,1.1,1.2
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-02-23 23:25:25
|
Update of /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23168/core/protocolsuite/tcp_ip Modified Files: SNMP.java Telnet_client.java Telnet_server.java Log Message: Index: Telnet_client.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_client.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Telnet_client.java 22 Feb 2006 18:57:43 -0000 1.1 --- Telnet_client.java 23 Feb 2006 23:25:19 -0000 1.2 *************** *** 176,179 **** --- 176,182 ---- Simulation.addLayerInfo(protInfo);*/ + if(Data.compareTo("\nQUIT")==0) { + Close(); + } terminal.recvData(Data); *************** *** 219,223 **** SendData("\n"); ! terminal.recvData("Connected!"); //connected.... --- 222,226 ---- SendData("\n"); ! //terminal.recvData("Connected!\n"); //connected.... Index: Telnet_server.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/Telnet_server.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Telnet_server.java 22 Feb 2006 19:56:58 -0000 1.2 --- Telnet_server.java 23 Feb 2006 23:25:19 -0000 1.3 *************** *** 31,34 **** --- 31,41 ---- private byte ConnectionAttempts=5; private int counts; + private String cmdline=""; + private boolean isenter=true; + private boolean islogin=false; + private boolean ispass=false; + private String password = "123"; + private String login = "root"; + private String userlogin = ""; /** Creates a new instance of Telnet Server */ *************** *** 134,138 **** public void RecvData(String Data) throws LowLinkException, TransportLayerException { //processing the protocol doings. - //server processing recieve --- 141,144 ---- *************** *** 150,161 **** protInfo2.setDescription("Sending echo message '" + Data + "' to client."); Simulation.addLayerInfo(protInfo2); ! try { ! SendData(Data); ! }catch(Exception e){ ///*TODO*: here to catch } - - } --- 156,244 ---- protInfo2.setDescription("Sending echo message '" + Data + "' to client."); Simulation.addLayerInfo(protInfo2); ! ! String outData=""; ! if(isenter && Data.compareTo("\n")==0) { ! outData = "\nlogin: "; ! islogin = true; ! isenter = false; ! } ! else { ! int ch = (char)Data.charAt(0); ! switch(ch) { ! case 0x03: ! case 0x04: { ! outData = "\nQUIT"; ! break; ! } ! case 0x08: { ! outData="\b"; ! cmdline = cmdline.substring(0,cmdline.length()-1); ! break; ! } ! case 0xA: { ! if(islogin) { ! islogin = false; ! userlogin = cmdline; ! ispass = true; ! outData = "\npassword: "; ! } ! else if(ispass) { ! ispass = false; ! if(userlogin.compareTo(login)==0 && cmdline.compareTo(password)==0) { ! outData = "\nWelcome to " + mParentStack.getParentNodeName() + "\n"; ! } ! else { ! try { ! SendData("\nLogin or password is incorrect"); ! outData = "\nQUIT"; ! } ! catch(Exception e) { ! //************* ! } ! } ! } ! else { ! cmdline = removeSpaces(cmdline); ! outData = "\n" + runcmd(cmdline); ! } ! cmdline = ""; ! break; ! } ! // case 0x1B: outData="ESC"; break; ! case 0x20: { ! if(ispass) { ! outData="*"; ! } ! else { ! outData=" "; ! } ! break; ! } ! default: ! if(ch>=0x30 && ch<0x80) ! { ! if(ispass) { ! outData = "*"; ! } ! else { ! outData = String.valueOf(Data.charAt(0)); ! } ! cmdline+=String.valueOf(Data.charAt(0)); ! } ! else { ! outData = "<" + (ch<16?"0":"") + Integer.toHexString(ch) + ">"; ! } ! } ! } try { ! SendData(outData); ! if(outData.compareTo("\nQUIT")==0) { ! Close(); ! isenter = true; ! } ! } ! catch(Exception e){ ///*TODO*: here to catch } } *************** *** 183,186 **** --- 266,281 ---- } + private String runcmd(String cmd) { + if(cmd.compareToIgnoreCase("quit")==0) { + return "QUIT"; + } + return "bad command\n"; + } + + private String removeSpaces(String s) { + while(s.startsWith(" ")) s = s.substring(1); + while(s.endsWith(" ")) s = s.substring(0, s.length()-1); + return s; + } } Index: SNMP.java =================================================================== RCS file: /cvsroot/javanetsim/javaNetSim/core/protocolsuite/tcp_ip/SNMP.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** SNMP.java 22 Feb 2006 20:04:27 -0000 1.9 --- SNMP.java 23 Feb 2006 23:25:19 -0000 1.10 *************** *** 54,59 **** public final static int SNMP_ERROR_noError = 0; public final static int SNMP_ERROR_noSuchName = 2; ! public final static int SNMP_ERROR_badValue = 3; // == SNMP_ERROR_wrongValue ??? public final static int SNMP_ERROR_readOnly = 4; public final static int SNMP_ERROR_genErr = 5; --- 54,60 ---- public final static int SNMP_ERROR_noError = 0; + public final static int SNMP_ERROR_tooBig = 1; public final static int SNMP_ERROR_noSuchName = 2; ! public final static int SNMP_ERROR_badValue = 3; public final static int SNMP_ERROR_readOnly = 4; public final static int SNMP_ERROR_genErr = 5; *************** *** 62,66 **** public final static int SNMP_ERROR_wrongLength = 8; public final static int SNMP_ERROR_wrongEncoding = 9; ! public final static int SNMP_ERROR_wrongValue = 10; // this constant maybe uses instead SNMP_ERROR_badValue public final static int SNMP_GET = 1; public final static int SNMP_GETNEXT = 2; --- 63,67 ---- public final static int SNMP_ERROR_wrongLength = 8; public final static int SNMP_ERROR_wrongEncoding = 9; ! public final static int SNMP_ERROR_wrongValue = 10; //unused public final static int SNMP_GET = 1; public final static int SNMP_GETNEXT = 2; *************** *** 488,492 **** */ public boolean getResponse(String Host, int port, Vector<String> r,Vector<String> v,int es,int ei) throws LowLinkException, TransportLayerException, CommunicationException, InvalidNetworkLayerDeviceException { ! String pack = createSNMPHeader(getNextID(),SNMP_RESPONSE); pack += createSNMPError(es,ei); String tmp = createSNMPVarsValues(r,v); --- 489,493 ---- */ public boolean getResponse(String Host, int port, Vector<String> r,Vector<String> v,int es,int ei) throws LowLinkException, TransportLayerException, CommunicationException, InvalidNetworkLayerDeviceException { ! String pack = createSNMPHeader(m_id,SNMP_RESPONSE); pack += createSNMPError(es,ei); String tmp = createSNMPVarsValues(r,v); *************** *** 1190,1198 **** if(var.compareToIgnoreCase("test.test_1")==0) { if(val.compareTo("B")==0 || val.compareTo("C")==0) return 0; ! else return SNMP_ERROR_wrongValue; } else if(var.compareToIgnoreCase("test.test_2")==0) { if(Integer.parseInt(val,10)>0 && Integer.parseInt(val,10)<99) return 0; ! else return SNMP_ERROR_wrongValue; } else if(var.compareToIgnoreCase("IP.DefaultGateway")==0) { --- 1191,1199 ---- if(var.compareToIgnoreCase("test.test_1")==0) { if(val.compareTo("B")==0 || val.compareTo("C")==0) return 0; ! else return SNMP_ERROR_badValue; } else if(var.compareToIgnoreCase("test.test_2")==0) { if(Integer.parseInt(val,10)>0 && Integer.parseInt(val,10)<99) return 0; ! else return SNMP_ERROR_badValue; } else if(var.compareToIgnoreCase("IP.DefaultGateway")==0) { *************** *** 1234,1238 **** } catch(Exception e) { ! System.out.print(e.toString()); } return 0; --- 1235,1240 ---- } catch(Exception e) { ! //System.out.print(e.toString()); ! return SNMP_ERROR_badValue; } return 0; |