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

void Probe::send (  )  [inherited]

Send this probe.

Send the probe.

TrException Something wrong happened.

Definition at line 67 of file Probe.cc.

References Probe::getDatagram(), IP4Header::getDestAddress(), Datagram::getHeader(), and Header::getHeaderType().

  // Get the IP4 header (first header)
  IP4Header* ip4 = (IP4Header*)getHeader(0);

  // Create the socket and set some IP options
  int sock = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
  if (sock < 0)
    throw TrException(str_log(ERROR, "Can't create the socket : %s",

  // Tell the OS to not append a IP header to the datagram
  int one = 1;
  if (setsockopt (sock, IPPROTO_IP, IP_HDRINCL, &one, sizeof (one)) < 0)
    throw TrException(str_log(ERROR, "Can't set socket option IP_HDRINCL :%s",

  /* Get the second header (UDP, TCP, ICMP) */
  Header* seg = getHeader(1);

  // Send the message/probe
  struct sockaddr_in buff;
  buff.sin_family       = AF_INET;
  switch (seg->getHeaderType()) {
    case Header::ICMP:
      buff.sin_port = 0;
    case Header::UDP:
      buff.sin_port = ((UDPHeader*)seg)->getDestPort();
    case Header::TCP:
      buff.sin_port = ((TCPHeader*)seg)->getDestPort();
  buff.sin_addr.s_addr  = ip4->getDestAddress();
  uint8* datagram;
  int    length;
  getDatagram(&datagram, &length);
  dumpRawData(DUMP, datagram, length);
  int res = sendto(sock,datagram,length,0,(sockaddr*)&buff,sizeof(sockaddr_in));
  if (res < 0) throw TrException(str_log(ERROR,
            "Can't send the probe : %s", strerror(errno)));

      delete datagram;

  // Close the socket
  res = close(sock);
  if (res < 0) throw TrException(str_log(ERROR,
            "Can't close the socket : %s", strerror(errno)));

Generated by  Doxygen 1.6.0   Back to index