
tcpserv.c File Reference
Server module. More...
Go to the source code of this file.
int main (int argc, char *argv[])
Main entry in server module.
int listenfd
passive socket's file descriptor.
int connfd
active socket's file descriptor for child process.
int chopt
dummy variable for options test.
int port_served = 0
port to connect.
int childpid
pid of the child process.
socklen_t clilen
size of the client's address structure.
char progname [MAXLINE]
program's name.
struct sockaddr_in cliaddr
structure of client's socket address.
struct sockaddr_in servaddr
structure of server's socket address.
Server module.
Usage
example: ./tcpserv -a
Features
Check the arguments supplied by the user
Retrieve the program's name
Check if 2 arguments were supplied, if not display help message and quit
Check if the option supplied is a valid one, if not display help message and quit
Compute the real port number
Check if port was supplied with a dash before it, if not display help message and quit
Print an help message on the terminal io
Create an active socket
Fill in the address structure, if address supplied not valid, display help message and quit
Bind the socket
Convert the active socket into passive socket
Set up a signal to catch SIGCHILD
Loop and wait for clients to connect
Handle client connection
Fork a process which handles the client's request
Parent closes the connected socket
Definition in file tcpserv.c.
int main (int argc, char *argv[])
Main entry in server module.
Definition at line 41 of file tcpserv.c.
References: childpid, cliaddr, clilen, connfd, chopt, listenfd, port_served, progname[MAXLINE], servaddr
Bind(), Close(), err_sys(), Fork(), Listen(), servusage(), sig_chld(), Signal(), Socket() .