Functions and Include Related to Socket Programming
LAST EDIT: 15 Tevet 5761, 2001/12/30
These are functions that don't directly work with sockets, but that
one often needs when programming sockets.
NOTE: some of these functions have since been added to the
document describing the socket functions in pseudo-code.
- HOSTS: Converting between host name and IP address
- IP address manipulation:
- inet_ntoa: convert IP address from binary format to text string:
- inet_addr: convert IP address from text string to binary format.
- PORTS: Mapping service names to ports (e.g., on which port is TFTP?)
- INTERRUPTS: Signals and alarms
- TIME: Getting and displaying the current time: the gettimeofday and
ctime functions. In alarm.c.
- CHILD PROCESSES
- fork function. Demonstrated in wait.c.
- wait function: if the child dies before the parent calls the
wait function, the child becomes a zombie (or defunct). The
program wait.c lets you demonstrate
- select: when waiting for input from more than one possible
source. This is one way for a server to handle more than one client
at a time.
In POSIX-compliant systems, there is a similar function called
- VARARGS/STDARG: how to write functions that accept a variable number of
The famous printf function is a example of a
function that needs one of these mechanisms, because it does not know in
advance how many arguments it will be passed, nor what type they
varargs is an older mechanism, and is supported both by
SunOS cc and GNU C (gcc). Do man varargs for more
information. stdarg has similar syntax.
It is part of the ANSI C standard, and
thus is supported by GNU C. However, it is NOT supported by SunOS cc.
- BYTE MANIPULATION: these are similar to functions
strncpy, strncmp, etc. However the str* functions
are for text. The following are either for text or for binary data:
- bzero: initialize a block of bytes to zero
- bcopy: copies a block of bytes to another address
- bcmp: compares 2 blocks of bytes
- memset: initialize a block of memory to a given
value. This is more flexible than bzero above,
because you can choose the initial value.
- memcpy: similar to bcopy.
- memove: similar to memcpy.
- memcp: similar to bcmp.
Here are some include files you might find useful in writing programs
for this lab. Most of them are under the directory /usr/include, but
some might be under /usr/local/include. These files are for SunOS; I
can't guarantee that they exist on other flavors of UNIX.
In addition, I do not necessarily mention include files that are
mentioned in the man pages of the various functions you might call.
- #include <arpa/tftp.h>
- #include <sys/socket.h>
- #include <sys/param.h>