meta data for this page

This is an old revision of the document!

Network programming @ Noppa | @ wiki - Updated: — Jussi Laakkonen 2010/08/30 14:48

Generic instructions and requirements

  • INDIVIDUAL WORK – NO COPYING – NO GROUPWORK (discuss but do not share code)
    • Except the first assignment which can be done in groups of 2/3
    • If you're caught from copying from others or from Internet/books your grade is 0.
  • Use C-language and GCC compiler (see man gcc)
    • Eliminate warning-messages (use -Wall for gcc)
  • Program can be run in Linux (on computers in classroom 6325)
  • Do not use external libraries (use only system libraries)
  • Use iterative approach (no threads or fork() unless requested)
  • Use a make file (see man make or use a Makefile template)
    • Compile: make build
    • Clean: make clean
  • Comment and document your code
    • Comments directly to source code files
    • Add name, student number and email into beginning of EVERY file.
  • Use good structure for your code
    • Divide code to functions based on responsibilities.
    • Divide functions to different files based on responsibilities.
    • C-code in .c files and header descriptions in .h files.
    • !!!!!!! NO GOTO STRUCTURES !!!!!!!
  • Write a readme file, which contains:
    • How to run the program. Follow the given instructions on every assignment
    • Description of the task (what has been done)
    • List what references were used (books, Internet pages/tutorials, etc.)
    • Features that were implemented
    • Description of division of code into separate files
    • Own ides (text) or solutions (code) for improving the task
      • Own improvements must clearly be a new feature, i.e. separate feature that enhances functionalities of the application.
      • Must be documented! No documentation about own feature(s) → no additional points
  • Check for error conditions
    • Debug with GDB (see man gdb)
    • Check that there are no memory leaks (use Valgrind, see man valgrind)
    • REMEMBER TO CLOSE SOCKETS when they're not used
    • Free the memory that was allocated.

Using Multiple files


  • main.c - main file, contains implementations of main() and run()-functions.
#include "main.h"
int main(int argc, char *argv[])
 return 0;
void run(int _type)
  if(check(_type) < 0) printf("Error\n");
  else printf("Success\n");
  • main.h - header for main.c, contains prototype for run()-function.
#include <stdio.h>
void run();
  • file.c - additional file, contains implementation of check()-function.
#include "file.h"
int check(int _type)
  if(_type == RIGHT) return 1;
  else return -1;
  • file.h - header for file.c, contains prototype for check()-function.
#define RIGHT 0
int check(int);

To use the function defined in file.h and implemented in file.c in the main.c following steps are needed:

  1. Include the file.h in main.c (or in main.h)
    • main.c after modifications:
      #include "main.h"
      #include "file.h
      int main(int argc, char *argv[])
       return 0;
      void run(int _type)
        if(check(_type) < 0) printf("Error\n");
        else printf("Success\n");
    • After this the compiler and linker can find the function check() used in run() since it is defined in one of the headers included.
  2. Add file.c into the Makefile of the application as source (remember to separate multiple files with spaces), in this case
    SOURCES=main.c file.c