PROGRAM_NAME='telnet_negotiate' (***********************************************************) (* FILE CREATED ON: 10/14/2010 AT: 14:46:44 *) (***********************************************************) (* FILE_LAST_MODIFIED_ON: 11/01/2010 AT: 14:11:12 *) (***********************************************************) // // Based on RFC854 and the telnet options documentation at // http://www.iana.org/assignments/telnet-options // // Copyright by Chris Hill. You may use this function // in your code, but you must retain this notice. // define_constant // interpret as command: integer IAC = $ff // commands: integer WILL = $fb integer WONT = $fc integer DO = $fd integer DONT = $fe // options: integer echo = $01 define_function telnet_negotiate(char my_arg[], dev target_dev) { local_var char data[64] local_var char this_msg[3] local_var char cmd[1] local_var char option[1] data = my_arg while(left_string(data,1) != "IAC") get_buffer_char(data) while(find_string(data,"IAC",1) && length_string(data >= 3)) { this_msg = left_string(data,3) cmd = mid_string(this_msg,2,1) option = right_string(this_msg,1) remove_string(data,"this_msg",1) // Be a curmudgeon and refuse everything but echo: switch(cmd) { case WILL : { if(option == echo) send_string target_dev,"IAC,DO,option" else send_string target_dev,"IAC,DONT,option" } case DO : send_string target_dev,"IAC,WONT,option" } } }