<commit_before>/*
 * A simple Telnet clone designed for easy remote access
 * 
 *
 * By <NAME> <<EMAIL>>
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

/* POSIX */
#include <sys/types.h>  /* For data types */
#include <sys/socket.h> /* For socket(), connect(), send(), and recv() */
#include <netdb.h> 	/* For gethostbyname() */
#include <arpa/inet.h> 	/* For inet_addr() */
#include <unistd.h> 	/* For close() */
#include <netinet/in.h> /* For sockaddr_in */
#include <limits.h>

#define DEBUG 		/* Enable to print debug messages, can be enabled at 
			 * compile time via -DDEBUG
			 */
#define ADDR 12 	/* Length of an IPv4 address plus null */
#define MAX 1024 	/* Largest message that can be recived */
#define SHELL "/bin/sh" /* Program to use as shell */
#define PORT "8888"	/* The port netshelld will listen on*/

#ifdef DEBUG
#define DBG(string) printf(string)
#endif

/* Function run by child proccesses to network the shell */
void child(int sfd) {
	dup2(sfd,0);
	dup2(sfd,1);
	char* args[] = {SHELL};
	execv(SHELL,args);
}

int main (void) {
	/*
	struct protoent *pro;
	pro = getprotobyname("tcp");
	int protocol;
	if (pro == NULL) protocol = 0;
	else protocol = pro->p_proto;
	/* Create an socket to listen on 
	int srv;
	/* int srv = socket(AF_INET,SOCK_STREAM,protocol); 
	if (srv == -1) perror("Socket");
	*/
	int srv;
	struct addrinfo hints;
	struct addrinfo addr;
	memset(&hints,0,sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_ADDRCONFIG;
	struct addrinfo *ptr = &addr;
	int gai = getaddrinfo("localhost","telnet",&hints,&ptr);
	if (gai != 0) DBG(gai_strerror(gai));
	/* borrow socket check from libsocket */
	struct addrinfo *check;
	for (check = ptr; check != NULL; check = check->ai_next) {
		srv = socket(check->ai_family,check->ai_socktype,check->ai_protocol);
		if (srv < 0) continue;
		if (-1 != connect(srv,check->ai_addr,check->ai_addrlen)) break;
	}
	listen(srv,10);<commit_msg>Listen on a defined port instead of telnet<commit_after>/*
 * A simple Telnet clone designed for easy remote access
 * 
 *
 * By <NAME> <<EMAIL>>
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

/* POSIX */
#include <sys/types.h>  /* For data types */
#include <sys/socket.h> /* For socket(), connect(), send(), and recv() */
#include <netdb.h> 	/* For gethostbyname() */
#include <arpa/inet.h> 	/* For inet_addr() */
#include <unistd.h> 	/* For close() */
#include <netinet/in.h> /* For sockaddr_in */
#include <limits.h>

#define DEBUG 		/* Enable to print debug messages, can be enabled at 
			 * compile time via -DDEBUG
			 */
#define ADDR 12 	/* Length of an IPv4 address plus null */
#define MAX 1024 	/* Largest message that can be recived */
#define SHELL "/bin/sh" /* Program to use as shell */
#define PORT "8888"	/* The port netshelld will listen on */

#ifdef DEBUG
#define DBG(string) printf(string)
#endif

/* Function run by child proccesses to network the shell */
void child(int sfd) {
	dup2(sfd,0);
	dup2(sfd,1);
	char* args[] = {SHELL};
	execv(SHELL,args);
}

int main (void) {
	/*
	struct protoent *pro;
	pro = getprotobyname("tcp");
	int protocol;
	if (pro == NULL) protocol = 0;
	else protocol = pro->p_proto;
	/* Create an socket to listen on 
	int srv;
	/* int srv = socket(AF_INET,SOCK_STREAM,protocol); 
	if (srv == -1) perror("Socket");
	*/
	int srv;
	struct addrinfo hints;
	struct addrinfo addr;
	memset(&hints,0,sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_ADDRCONFIG;
	struct addrinfo *ptr = &addr;
	int gai = getaddrinfo("localhost",PORT,&hints,&ptr);
	if (gai != 0) DBG(gai_strerror(gai));
	/* borrow socket check from libsocket */
	struct addrinfo *check;
	for (check = ptr; check != NULL; check = check->ai_next) {
		srv = socket(check->ai_family,check->ai_socktype,check->ai_protocol);
		if (srv < 0) continue;
		if (-1 != connect(srv,check->ai_addr,check->ai_addrlen)) break;
	}
	listen(srv,10);
{'fraction_non_alphanumeric': 0.1601193436101442, 'fraction_numerical': 0.011437095972153158, 'mean_word_length': 3.924112607099143, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7336427', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1500, 'n_words': 432}