/* servermain.c - a server main program running under unix that uses the socket interface to tcp or udp */ /* there are two optional command line parameters: 1 the port number of the server 2 the name of the interface to serve */ #include #include #include #include #include "server.h" #define default_server_port 0 #define default_interface_name NULL int main( int argc, char *argv[] ) { int server_port; char *interface_name; argv++; /* point at first parameter (if any) */ /* get the server's port number from optional first parameter */ if( argc <= 1 ) server_port = default_server_port; else if( (server_port = atoi(*argv)) < 0 ) { fprintf(stderr, "port number '%s' cannot be negative\n", *argv); exit(EXIT_FAILURE); } else argv++; /* point at second parameter (if any) */ if( argc <= 2 ) interface_name = default_interface_name; else interface_name = *argv++; /* point at third parameter (if any) */ /* now let the common server do the real work */ server(server_port, interface_name, argc-3, argv); exit(EXIT_SUCCESS); }