
wrapsock.c File Reference
Functions module. More...
Go to the source code of this file.
static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
Static function to handle errors.
static ssize_t mg_read (int fd, char *ptr)
Static function to catch errors while reading a stream.
void cliusage (char *progname)
Display an help message and quit, used in client when options are wrong.
void Inet_pton (int family, const char *strptr, void *addrptr)
Check if the address supplied by the user in client is valid, if not display an help message and quit.
void Connect (int fd, const struct sockaddr *sa, socklen_t salen)
Connect the client to the server's listening socket, if not display an help message and quit.
void str_cli (FILE *fp, int sockfd)
Attempt to write the client's request to the socket.
void servusage (char *progname)
Display an help message and quit, used in server when options are wrong.
void Bind (int fd, const struct sockaddr *sa, socklen_t salen)
Bind the name defined in the address structure to the socket, used in server.
void Listen (int fd, int backlog)
Listen for connection on the socket, used in server.
Sigfunc * Signal (int signo, Sigfunc *func)
Signal function to catch a SIGCHLD.
pid_t Fork (void)
Fork a child, if it fails display an error message and quit.
void Close (int fd)
Close the socket, if it fails display an error message and quit.
void str_serv1 (int sockfd)
Writes the result of request to the socket, for all types of requests.
void str_serv2 (int sockfd)
Writes the result of request to the socket, for numeric requests.
void str_serv3 (int sockfd)
Writes the result of request to the socket, for word requests.
int Socket (int family, int type, int protocol)
Create a socket.
char * Fgets (char *ptr, int n, FILE *stream)
Wrapper for fgets
ssize_t mg_readline (int fd, void *vptr, size_t maxlen)
Read a string character after character from a stream.
ssize_t Readline (int fd, void *ptr, size_t maxlen)
Wrapper for mg_readline.
void Fputs (const char *ptr, FILE *stream)
Wrapper for fputs.
ssize_t writen (int fd, const void *vptr, size_t n)
Write a string character after character to a stream.
void Writen (int fd, void *ptr, size_t nbytes)
Wrapper for writen.
int Select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Wait for read/write descriptors ready.
void Shutdown (int fd, int how)
Initiate a normal termination sequence.
void sig_chld (int signo)action to take when child terminates.
Sigfunc * mg_signal (int signo, Sigfunc *func)
Handle signals.
void err_sys (const char *fmt,...)
Handle errors generated by the system.
void err_quit (const char *fmt,...)
Handle errors not generated by the system.
int daemon_proc
in case launched at startup (not tested)
Functions for tcpcli, tcpserv.
Definition in file wrapsock.c.
static void err_doit (int errnoflag, int level, const char *fmt, va_list ap)
Static function to handle errors.
Definition at line 31 of file wrapsock.c.
Referenced by: err_quit(), and err_sys().
static ssize_t mg_read (int fd, char *ptr)
Static function to catch errors while reading a stream.
Definition at line 81 of file wrapsock.c.
Referenced by mg_readline().
void cliusage (char *progname)
Display an help message and quit, used in client when options are wrong.
Definition at line 118 of file wrapsock.c.
References: err_quit().
Referenced by: lines 81, 109, 123, 137and 148 of file tcpcli.c.
void Inet_pton (int family, const char *strptr, void *addrptr)
Check if the address supplied by the user in client is valid, if not display an help message and quit.
Definition at line 143 of file wrapsock.c.
References: err_quit(), and err_sys().
Referenced by: line 176 of file tcpcli.c.
void Connect (int fd, const struct sockaddr *sa, socklen_t salen)
Connect the client to the server's listening socket, if not display an help message and quit.
Definition at line 166 of file wrapsock.c.
References: err_sys().
Referenced by: line 180 of file tcpcli.c.
void str_cli (FILE *fp, int sockfd)
Attempt to write the client's request to the socket.
Definition at line 179 of file wrapsock.c.
References: err_quit(), Fgets(), Fputs(), Readline(), Select(), Shutdown(), and Writen().
Referenced by: line 184 of file tcpcli.c.
void servusage (char *progname)
Display an help message and quit, used in server when options are wrong.
Definition at line 263 of file wrapsock.c.
References: err_quit().
Referenced by: lines 99, 127, and 139 of file tcpserv.c.
void Bind (int fd, const struct sockaddr *sa, socklen_t salen)
Bind the name defined in the address structure to the socket, used in server.
Definition at line 287 of file wrapsock.c.
References: err_sys().
Referenced by: line 167 of file tcpserv.c.
void Listen (int fd, int backlog)
Listen for connection on the socket, used in server.
Definition at line 301 of file wrapsock.c.
References: err_sys().
Referenced by: line 171 of file tcpserv.c.
Sigfunc * Signal (int signo, Sigfunc *func)
Signal function to catch a SIGCHLD.
Definition at line 315 of file wrapsock.c.
References: err_sys(), mg_signal().
Referenced by: line 175 of file tcpserv.c.
pid_t Fork (void)
Fork a child, if it fails display an error message and quit.
Definition at line 332 of file wrapsock.c.
References: err_sys().
Referenced by: line198 of file tcpserv.c.
void Close (int fd)
Close the socket, if it fails display an error message and quit.
Definition at line 349 of file wrapsock.c.
References: err_sys().
Referenced by: lines 203, and 230 of file tcpserv.c.
void str_serv1 (int sockfd)
Writes the result of request to the socket, for all types of requests.
Definition at line 362 of file wrapsock.c.
References: Readline(), and Writen().
Referenced by: line 210 of file tcpserv.c.
void str_serv2 (int sockfd)
Writes the result of request to the socket, for numeric requests.
Definition at line 449 of file wrapsock.c.
References: Readline(), and Writen().
Referenced by: line 215 of file tcpserv.c.
void str_serv3 (int sockfd)
Writes the result of request to the socket, for word requests.
Definition at line 526 of file wrapsock.c.
References: Readline(), and Writen().
Referenced by: line 220 of file tcpserv.c.
int Socket (int family, int type, int protocol)
Create a socket.
Definition at line 577 of file wrapsock.c.
References: err_sys().
Referenced by: line 156 of file tcpserv.c, and 166 of file tcpcli.c.
char * Fgets (char *ptr, int n, FILE *stream)
Wrapper for fgets
Definition at line 597 of file wrapsock.c.
References: err_sys().
Referenced by: str_cli().
ssize_t mg_readline (int fd, void *vptr, size_t maxlen)
Read a string character after character from a stream.
Definition at line 617 of file wrapsock.c.
References: mg_read().
Referenced by: Readline().
ssize_t Readline (int fd, void *ptr, size_t maxlen)
Wrapper for mg_readline.
Definition at line 663 of file wrapsock.c.
References: err_sys(), and mg_readline().
Referenced by: str_cli(), str_serv1(), str_serv2(), and str_serv3().
void Fputs (const char *ptr, FILE *stream)
Wrapper for fputs.
Definition at line 681 of file wrapsock.c.
References: err_sys().
Referenced by: str_cli().
ssize_t writen (int fd, const void *vptr, size_t n)
Write a string character after character to a stream.
Definition at line 697 of file wrapsock.c.
Referenced by: Writen().
void Writen (int fd, void *ptr, size_t nbytes)
Wrapper for writen.
Definition at line 733 of file wrapsock.c.
References: err_sys(), and writen().
Referenced by: str_cli(), str_serv1(), str_serv2(), and str_serv3().
int Select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
Wait for read/write descriptors ready.
Definition at line 751 of file wrapsock.c.
References: err_sys().
Referenced by: str_cli().
void Shutdown (int fd, int how)
Initiate a normal termination sequence.
Definition at line 769 of file wrapsock.c.
References: err_sys().
Referenced by: str_cli().
void sig_chld (int signo)
action to take when child terminates.
Definition at line 783 of file wrapsock.c.
Referenced by: line 175 of file tcpserv.c.
Sigfunc * mg_signal (int signo, Sigfunc *func)
Handle signals.
Definition at line 804 of file wrapsock.c.
Referenced by: Signal().
void err_sys (const char *fmt,...)
Handle errors generated by the system.
Definition at line 835 of file wrapsock.c.
References: err_doit().
Referenced by: Bind(), Close(), Connect(), Fgets(), 193 of file tcpserv.c, Fork(), Fputs(), Inet_pton(), Listen(), Readline(), Select(), Shutdown(), Signal(), Socket(), and Writen().
void err_quit (const char *fmt,...)
Handle errors not generated by the system.
Definition at line 854 of file wrapsock.c.
References: err_doit().
Referenced by: cliusage(), Inet_pton(), servusage(), and str_cli().
int daemon_proc
in case launched at startup (not tested)