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.

  1. HOSTS: Converting between host name and IP address

  2. IP address manipulation:

  3. PORTS: Mapping service names to ports (e.g., on which port is TFTP?)

  4. INTERRUPTS: Signals and alarms

  5. TIME: Getting and displaying the current time: the gettimeofday and ctime functions. In alarm.c.


  7. 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 pselect.

  8. VARARGS/STDARG: how to write functions that accept a variable number of arguments. 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 will be.

    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.

  9. 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:
    1. b*
      • bzero: initialize a block of bytes to zero
      • bcopy: copies a block of bytes to another address
      • bcmp: compares 2 blocks of bytes
    2. mem*
      • 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.