Socket Program: TCP Shell

xiaoxiao2021-03-06  92

Socket Programming Example: TCP Shell is very simple and easy to discover, and as a Socket programming example learning.

/ * ================================================================================================================================================================ ===================================================================================================== Unyun (unywn4th@usa.net) ========================================== ============================================ * / #include #include #include #include #include #include #include #include #include < Netinet / in .h> #include #include #include #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_proc Ess; int corre_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);}} (socket_type == Sock_Stream) {if (listen (listen) == - 1) {Perror ("listen"); exit (1);}}} void sock_puts (sockfd, str) int INT Sockfd; char * STR; {char x [2000], * BUF; SIZE_T BYTES_SENT = 0; int this_write, count; sprintf (x, "/ r% s", str); count = strlen (x); buf = x; while (bytes_sent

转载请注明原文地址:https://www.9cbs.com/read-122238.html

New Post(0)