예제 #1
0
/* send a NEW-ENVIRON value */
void telnet_newenviron_value(telnet_t *telnet, unsigned char type,
		const char *string) {
	telnet_send(telnet, (const char*)&type, 1);

	if (string != 0) {
		telnet_send(telnet, string, strlen(string));
	}
}
예제 #2
0
파일: clc.c 프로젝트: elanthis/clc
/* send NAWS update */
static void send_naws (void) {
	unsigned short w = htons(COLS), h = htons(LINES);

	/* send NAWS if enabled */
	if (terminal.flags & TERM_FLAG_NAWS) {
		telnet_begin_sb(telnet, TELOPT_NAWS);
		telnet_send(telnet, (char*)&w, 2);
		telnet_send(telnet, (char*)&h, 2);
		telnet_finish_sb(telnet);
	}
}
예제 #3
0
/* send formatted data through telnet_send */
int telnet_raw_vprintf(telnet_t *telnet, const char *fmt, va_list va) {
	char buffer[1024];
	char *output = buffer;
	int rs;

	/* format; allocate more space if necessary */
	va_list va2;
	va_copy(va2, va);
	rs = vsnprintf(buffer, sizeof(buffer), fmt, va);
	if (rs >= sizeof(buffer)) {
		output = (char*)malloc(rs + 1);
		if (output == 0) {
			_error(telnet, __LINE__, __func__, TELNET_ENOMEM, 0,
					"malloc() failed: %s", strerror(errno));
			return -1;
		}
		rs = vsnprintf(output, rs + 1, fmt, va2);
	}
	va_end(va2);
	va_end(va);

	/* send out the formatted data */
	telnet_send(telnet, output, rs);

	/* release allocated memory, if any */
	if (output != buffer) {
		free(output);
	}

	return rs;
}
예제 #4
0
/* send complete subnegotiation */
void telnet_subnegotiation(telnet_t *telnet, unsigned char telopt,
		const char *buffer, size_t size) {
	unsigned char bytes[5];
	bytes[0] = TELNET_IAC;
	bytes[1] = TELNET_SB;
	bytes[2] = telopt;
	bytes[3] = TELNET_IAC;
	bytes[4] = TELNET_SE;

	_sendu(telnet, bytes, 3);
	telnet_send(telnet, buffer, size);
	_sendu(telnet, bytes + 3, 2);

#if defined(HAVE_ZLIB)
	/* if we're a proxy and we just sent the COMPRESS2 marker, we must
	 * make sure all further data is compressed if not already.
	 */
	if (telnet->flags & TELNET_FLAG_PROXY &&
			telopt == TELNET_TELOPT_COMPRESS2) {
		telnet_event_t ev;

		if (_init_zlib(telnet, 1, 1) != TELNET_EOK)
			return;

		/* notify app that compression was enabled */
		ev.type = TELNET_EV_COMPRESS;
		ev.compress.state = 1;
		telnet->eh(telnet, &ev, telnet->ud);
	}
#endif /* defined(HAVE_ZLIB) */
}
예제 #5
0
/**
 * A callback function to be invoked when a line has been entered on the telnet client.
 * Here we want to pass that line to the JS parser for processing.
 */
static void telnetLineCB(char *line) {
  jsiConsolePrintf("LineCB: %s", line);
  // Pass the line to the interactive module ...

  jshPushIOCharEvents(jsiGetConsoleDevice(), line, strlen(line));
  //jspEvaluate(line);
  //jsiDumpState();
  telnet_send("JS> ");
} // End of lineCB
예제 #6
0
/*---------------------------------------------------------------------------*/
static void
send_line(struct telnet_state *s, char *data, int len)
{
  if(!sending) {
    strncpy(outputline, data, MIN(sizeof(outputline), len));
    telnet_send(s, data, len);
    sending = 1;
  } else {
    shell_output_str(&tcpsend_command, "Cannot send data, still sending previous data", "");
  }
}
예제 #7
0
static void _input(char *buffer, int size) {
	static char crlf[] = { '\r', '\n' };
	int i;

	for (i = 0; i != size; ++i) {
		/* if we got a CR or LF, replace with CRLF
		 * NOTE that usually you'd get a CR in UNIX, but in raw
		 * mode we get LF instead (not sure why)
		 */
		if (buffer[i] == '\r' || buffer[i] == '\n') {
			if (do_echo)
				printf("\r\n");
			telnet_send(telnet, crlf, 2);
		} else {
			if (do_echo)
				putchar(buffer[i]);
			telnet_send(telnet, buffer + i, 1);
		}
	}
	fflush(stdout);
}
예제 #8
0
void TelnetConnection::writeMessage() {
    std::string *msg;
    if (mSendQueue.pop(msg)) {
        {boost::lock_guard<boost::mutex> guard(mTelnetMutex);
            telnet_send(mTelnet, msg->c_str(), msg->size());
        }
        delete msg;
    }
    else {
        mCurrentlySending.clear();
    }
}
예제 #9
0
/* Telnet server loop, used to send buffered output in the RB */
static void telnet_run(void)
{
	while (true) {
		k_sem_take(&send_lock, K_FOREVER);

		if (!telnet_send()) {
			telnet_end_client_connection();
		}

		telnet_reply_command();
	}
}
예제 #10
0
static void _draw(int width, int height, telnet_t *telnet)
{
	int i;

	int tl,hl,tr,vl,bl,br;

	int buffer_size;
	char *buffer;

	tl = 218;
	hl = 196;
	tr = 191;
	vl = 179;
	bl = 192;
	br = 217;

	buffer_size = width*height + 1;

	buffer = (char *)malloc(buffer_size);
	memset(buffer, 0, buffer_size);
	buffer = "┌─";

/*	for(i=0; i < buffer_size; i++)
	{
		if(i==0)
		{
			buffer[i] = 14;
			break;
		}
		else if(i==1)
		{
			buffer[i] = tl;
			break;
		}
		else if(i<width)
		{
			buffer[i] = hl;
			break;
		}
		else if(i==width)
		{
			buffer[i] = tr;
			break;
		}
	}*/

	telnet_send(telnet, buffer, sizeof(buffer));
	free(buffer);

	return;
}
예제 #11
0
파일: telnet.c 프로젝트: arychen/GlobalCall
/* send complete subnegotiation */
void telnet_subnegotiation(telnet_t *telnet, unsigned char telopt,
		const char *buffer, size_t size) 
{
	unsigned char bytes[5];
	bytes[0] = TELNET_IAC;
	bytes[1] = TELNET_SB;
	bytes[2] = telopt;
	bytes[3] = TELNET_IAC;
	bytes[4] = TELNET_SE;

	_sendu(telnet, bytes, 3);
	telnet_send(telnet, buffer, size);
	_sendu(telnet, bytes + 3, 2);

}
예제 #12
0
/* send formatted data through telnet_send */
int telnet_raw_printf(telnet_t *telnet, const char *fmt, ...) {
	char buffer[4096];
	va_list va;
	int rs;

	/* format */
	va_start(va, fmt);
	rs = vsnprintf(buffer, sizeof(buffer), fmt, va);
	va_end(va);

	/* send */
	telnet_send(telnet, buffer, rs);

	return rs;
}
예제 #13
0
void *telnet_write_loop(void *args) {
	connection_t *con = ((struct loop_args *)args)->con;
	char *out_buf = (char *)calloc(1, MAX_LINE), c;
	size_t i;
	while (1) {
		i = 0;
		printf("> ");
		while ((c = getchar()) != '\n') {
			out_buf[i++] = c;
		}
		out_buf[i] = '\0';
		if (!strcmp(out_buf, "exit")) break;
		telnet_send(con, out_buf);
	}
	printf("Connection closed by client\n");
	free(out_buf);
	return NULL;
}
예제 #14
0
/* send a ZMP argument */
void telnet_zmp_arg(telnet_t *telnet, const char* arg) {
	telnet_send(telnet, arg, strlen(arg) + 1);
}
예제 #15
0
/* begin NEW-ENVIRON subnegotation */
void telnet_begin_newenviron(telnet_t *telnet, unsigned char cmd) {
	telnet_begin_sb(telnet, TELNET_TELOPT_NEW_ENVIRON);
	telnet_send(telnet, (const char *)&cmd, 1);
}
예제 #16
0
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(simpletelnet_process, ev, data)
{
  struct ctk_widget *w;
  int sendlen;

  PROCESS_BEGIN();
  
  ctk_window_new(&telnetwindow, TELNET_WINDOW_WIDTH, TELNET_WINDOW_HEIGHT, "Simple telnet");
  
  strcpy(telnetport, "23");
  
  CTK_WIDGET_ADD(&telnetwindow, &telnethostlabel);
  CTK_WIDGET_ADD(&telnetwindow, &telnetportlabel);
  CTK_WIDGET_ADD(&telnetwindow, &telnethosttextentry);
  CTK_WIDGET_ADD(&telnetwindow, &telnetporttextentry);
  CTK_WIDGET_ADD(&telnetwindow, &telnetconnectbutton);
  CTK_WIDGET_ADD(&telnetwindow, &telnetdisconnectbutton);
  CTK_WIDGET_ADD(&telnetwindow, &telnetlinetextentry);
  CTK_WIDGET_ADD(&telnetwindow, &telnetsendbutton);
  
  CTK_WIDGET_ADD(&telnetwindow, &telnetsep1);
  CTK_WIDGET_ADD(&telnetwindow, &telnettextarea);
  
  CTK_WIDGET_ADD(&telnetwindow, &telnetsep2);
  CTK_WIDGET_ADD(&telnetwindow, &telnetstatus);
  
  CTK_WIDGET_FOCUS(&telnetwindow, &telnethosttextentry);
  
  ctk_window_open(&telnetwindow);

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == ctk_signal_button_activate) {
      
      w = (struct ctk_widget *)data;
      if(w == (struct ctk_widget *)&telnetsendbutton) {
	strcpy(sendline, telnetline);
	sendlen = (int)strlen(sendline);
	petsciiconv_toascii(sendline, sendlen);
	sendline[sendlen++] = ISO_CR;
	sendline[sendlen++] = ISO_NL;
	if(telnet_send(&ts_appstate, sendline, sendlen)) {
	  /* Could not send. */
	  ctk_label_set_text(&telnetstatus, "Could not send");
	  ctk_window_redraw(&telnetwindow);
	  /*      } else {*/
	  /* Could send */
	}
      } else if(w == (struct ctk_widget *)&telnetdisconnectbutton) {
	telnet_close(&ts_appstate);
	show("Closing...");
      } else if(w == (struct ctk_widget *)&telnetconnectbutton) {
	connect();
	ctk_window_redraw(&telnetwindow);
      }
#if UIP_UDP
    } else if(ev == resolv_event_found) {
      if(strcmp(data, telnethost) == 0) {
	if(resolv_lookup(telnethost) != NULL) {
	  connect();
	} else {
	  show("Host not found");
	}
      }
#endif /* UIP_UDP */
    } else if(
#if CTK_CONF_WINDOWCLOSE
	      ev == ctk_signal_window_close ||
#endif /* CTK_CONF_WINDOWCLOSE */
	      ev == PROCESS_EVENT_EXIT) {
      process_exit(&simpletelnet_process);
      ctk_window_close(&telnetwindow);
      LOADER_UNLOAD();
    } else if(ev == tcpip_event) {
      telnet_app(data);
    }
  }
  PROCESS_END();
}