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

UDPProbe::UDPProbe ( const char *  src_addr,
int  src_port,
uint32  dst_addr,
int  dst_port,
uint8  ttl,
uint8  tos,
int  data_len,
uint16  proc_id,
uint16  id 
)

Create a new UDP probe.

Each probe are defined by 7 parameters:

  • The tuple which define an UDP-connection: (source address, source port, destination address, destination port
  • The ttl to use with this Probe
  • The length of data to send with the Probe
  • An identifier to differentiate each Probe and their replies

Parameters:
src_addr Source address (in dotted notation)
src_port Source port
dst_addr Destination address (in dotted notation)
dst_port Destination port
ttl The Time to Live
length Append length bytes of data after the headers (min 2)
id Identifier
Exceptions:
TrException The source or destination address is invalid.

Definition at line 25 of file UDPProbe.cc.

References Datagram::addHeader(), Util::computeChecksum(), UDPHeader::pack(), Datagram::packData(), IP4Header::packPseudo(), UDPHeader::setChecksum(), Datagram::setData(), UDPHeader::setDatagramLength(), IP4Header::setDestAddress(), UDPHeader::setDestPort(), IP4Header::setIPId(), IP4Header::setProtocol(), IP4Header::setSourceAddress(), UDPHeader::setSourcePort(), IP4Header::setToS(), IP4Header::setTotalLength(), and IP4Header::setTTL().

                                       : Probe() {
  // Set data_len to a minimum of 2
  if (data_len < 2) data_len = 2;

  // Create the IP4 header of the Probe
  IP4Header* ip4 = new IP4Header();
  addHeader(ip4);

  // Set source address
  ip4->setSourceAddress(src_addr);

  // Set destination address
  ip4->setDestAddress(dst_addr);

  // Set TTL
  ip4->setTTL(ttl);

      ip4->setIPId(id);

  // Set ToS
  ip4->setToS(tos);

  // Set Protocol to UDP (17)
  ip4->setProtocol("udp");

  // Set the total length of this UDP datagram (IP + UDP + data)
  ip4->setTotalLength(20 + 8 + data_len);

  // Create UDP header of the Probe
  UDPHeader* udp = new UDPHeader();
  addHeader(udp);

  // Set source port
      udp->setSourcePort(src_port);

  // Set destination port
#ifdef DEVANOMALIES
      udp->setDestPort(id);
#else
  udp->setDestPort(dst_port);
#endif

#ifdef DEVANOMALIES
      udp->setChecksum(id);
#endif

  // Set the datagram length (UDP header(8) + len(data))
  int datagram_len = 8 + data_len;
  udp->setDatagramLength(datagram_len);

  // Add the message id followed by (data_len - 2) zero's as data
  uint8* d = new uint8[data_len];
  memset(d, 0, data_len);
#ifndef DEVANOMALIES
  memcpy(d, &id, 2);
#endif
  setData(d, data_len);

  // Compute and set the UDP checksum
  int dgram_checksum_len = datagram_len + 12;
  uint8* dgram_checksum = new uint8[dgram_checksum_len];
  ip4->packPseudo(datagram_len, dgram_checksum, dgram_checksum_len, 0);
  udp->pack(dgram_checksum, dgram_checksum_len, 12);
  packData(dgram_checksum, dgram_checksum_len, 20);
  
  uint16 udp_checksum = Util::computeChecksum((uint16*)dgram_checksum,
                                          dgram_checksum_len);
#ifdef DEVANOMALIES
      memcpy(d, &udp_checksum, 2);
      setData(d, data_len);
#else
  udp->setChecksum(udp_checksum);
#endif
      
      delete[] d;             
  delete[] dgram_checksum;
}


Generated by  Doxygen 1.6.0   Back to index