exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

ltelnet.c

ltelnet.c
Posted Jul 17, 2002
Authored by Nicola Piazzolla

Ltelnet is a simple linux telnet client written in c.

systems | linux, unix
SHA-256 | e3f894f887b86e05fae960ee2296814fc7e81273c4836b04f82423ee9d96b2cb

ltelnet.c

Change Mirror Download
//  LTelnet       Linux Telnet Client  


/* Ltelnet.c is a Linux Telnet Client written in C
Copyright (C) 2002 Nicola Piazzolla

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


LICENSE: GNU/GPL (http://www.gnu.org/licenses/gpl.html)


Written by kc

Readme : gcc ltelnet.c -o ltelnet



*/




#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>


#define HELP 'h'
#define VERSION 'v'


#define _DEFAULT_PORT 23

#define MAX_LINES 1000

int check (int sock); // Function : Send & receive

int connects (char *hostname, int PORT); // Connect to the server.



int
main (int argc, char **argv)
{

char char_opt[] = { HELP, VERSION };

int ch;
extern int optind;

if (argc == 1)
{
printf ("Type %s -h\n", argv[0]);
}

while ((ch = getopt (argc, argv, char_opt)) != -1)
{

switch (ch)
{





case VERSION:
printf ("Ltelnet is a Linux Client Telnet\n");
printf ("Version : 1.4.5\n");
printf ("Written by Nicola Piazzolla\n");
printf ("Reports bugs at kcc@users.sourceforge.net\n");

break;





case HELP:

printf ("Ltelnet is a Linux Telnet Client\n");

printf ("Usage : Type ' %s host [ port ]'\n", argv[0]);
printf ("Options :\n");
printf (" -h : This Help\n");
printf (" -v : Version\n");


break;



}

}

if (optind < argc)
{


if (argc == 2)
{

connects (argv[optind], _DEFAULT_PORT);
}

else if (argc == 3)
{

connects (argv[optind], atoi (argv[2]));

}
}





return 0;
}


int
connects (char *hostname, int PORT)
{

struct sockaddr_in server;
struct hostent *he;
int tcp_socket;
int fd;


he = gethostbyname (hostname);

if (!he)
{
fprintf (stderr, "Host unknown\n");
return -1;
}

server.sin_port = htons (PORT);
server.sin_family = AF_INET;

memcpy (&server.sin_addr.s_addr, he->h_addr, he->h_length);

tcp_socket = socket (AF_INET, SOCK_STREAM, 0);

fd = connect (tcp_socket, (struct sockaddr *) &server, sizeof (server));



if (fd == 0)
{
printf ("Login..\n");


if (check (tcp_socket) != -1)
fprintf (stderr, "Error\n");


}
else

printf ("Impossible to connect\n");

return -1;
}









int
check (int sock)
{

pid_t pid;
char reading[MAX_LINES];
int fd, fd1;
char writing[MAX_LINES];

pid = fork ();

if (pid == 0)
{

while (1)
{
memset (reading, '\0', sizeof (reading)); // Son :)
fd = read (sock, reading, MAX_LINES);

if (fd == 0)
exit (-1);


printf ("%s", reading);
}
}


else
{
while (1)
{ // The father :)


fgets (writing, MAX_LINES, stdin);

fd1 = write (sock, writing, strlen (writing));

}
}

close (sock);


return -1;

}
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    18 Files
  • 19
    Nov 19th
    7 Files
  • 20
    Nov 20th
    13 Files
  • 21
    Nov 21st
    6 Files
  • 22
    Nov 22nd
    48 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    60 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    44 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close