#include #include #include #include #include #include #include #include "sockets.h" /*Input: Accepts no user input, gets struct and int listen_sd from main * Output: NONE * Return: int value for listen_sd * Notes: starts socket setup */ int _socket( struct protoent * p_ptr , int * listen_sd) { *listen_sd = socket ( PF_INET, SOCK_STREAM, p_ptr->p_proto ); return *listen_sd; } /*Input: Accepts no user input, gets sockaddr for server and int * listen_sd and rc from main * Output: NONE * Return: int value for rc * Notes: calls bind command */ int _bind( struct sockaddr_in serv , int * rc , int * listen_sd) { *rc = bind( * listen_sd , ( struct sockaddr * ) &serv, sizeof(struct sockaddr_in) ); return *rc; } /*Input: Accepts no user input, gets struct and int listen_sd and rc from main * Output: NONE * Return: int value for rc * Notes: calls listen command */ int _listen( int * listen_sd , int * rc ) { *rc = listen ( *listen_sd, 10 ); return *rc; } /*Input: Accepts no user input, gets struct and int listen_sd and io_sd, * as well as sockaddr for client from main * Output: NONE * Return: int value for io_sd * Notes: accepts client connection */ int _accept( int * listen_sd, int * io_sd , struct sockaddr_in client, socklen_t cli_length) { *io_sd = accept ( *listen_sd, ( struct sockaddr * ) &client, &cli_length ); return *io_sd; } /*Input: Accepts no user input, gets int listen_sd, and char arr * buf from main * Return: int value of x which is number bytes read successfully * Notes: reads data entered by a client */ int _read ( int * io_sd , char buf ) { int tmp; tmp = read( * io_sd , buf , sizeof(char)*80 ); return tmp; } /*Input: Accepts no user input, gets int listen_sd, and tmp and char arr * buf from main * Output: value in buf to appropriate client * Return: NONE * Notes: uses write to write to clients screen info read from other * client's screen */ void _write ( int * io_sd , char buf , int * tmp) { write( *io_sd , buf , *tmp ); }