Logo Search packages:      
Sourcecode: paris-traceroute version File versions  Download package

Server::Server ( Options *  opts,
const char *  protocol 
)

Create a new Server to listen incoming message.

Parameters:
client The class to notify when a message arrives.
addr The server will listen for incoming messages from this address (in network endianess).
port The server will listen for incoming messages on this port.
protocol The protocol to listen ("icmp", "tcp").
Exceptions:
TrException An error occured.

Definition at line 39 of file Server.cc.

References Util::protocol2int().

                                                   {
  // Initialisation
  this->client   = new Tracert*[opts->threads_count];
  this->client[0]   = NULL;
  this->client_id =  new int[opts->threads_count];
  this->opts     = opts;

  stop_thread    = true;

  // Create the socket
  sock_server = socket(PF_INET, SOCK_RAW, Util::protocol2int(protocol));
  if (sock_server < 0) throw TrException(str_log(ERROR,
                  "Cannot create the server : %s", strerror(errno)));

// WHAT FOR ???
#if 0
  // Set timeout on the socket : 5000 usec
  struct timeval tv;
  tv.tv_sec  = 0;
  tv.tv_usec = 5000;
  int res = setsockopt(sock_server,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(timeval));
  if (res < 0) throw TrException(str_log(ERROR, "Set timeout failed : %s",
                                                strerror(errno)));
#endif

  // Bind it
  sockaddr_in saddr;
  memset(&saddr, 0, sizeof(sockaddr_in));
  saddr.sin_family      = AF_INET;
  saddr.sin_port        = htons(opts->src_port);
  int res = bind(sock_server, (sockaddr*)&saddr, sizeof(sockaddr_in));
  if (res < 0) throw TrException(str_log(ERROR,
                  "Cannot bind the server : %s", strerror(errno)));

  // Create a mutex
  res = pthread_mutex_init(&lock, NULL);
  if (res != 0) throw TrException(str_log(ERROR, "Create a mutex"));
}


Generated by  Doxygen 1.6.0   Back to index