void RawSocketPacketInterface::initialise (net::InetAddress target)
{
    m_target = target;

    // get the local ip to fill in header
    net::InetAddress local = getSourceAddress();

    m_socket = new net::Socket (SOCK_RAW, IPPROTO_IP);
    m_socket->setOption (IPPROTO_IP, IP_HDRINCL, TRUE);
    m_socket->bind (local);
    m_socket->ioctl (SIO_RCVALL, true);
}
예제 #2
0
string Packet::toString() const{
	// Serialize this object for the network

	string delimiter = "\n";

	stringstream serialization;
	
	serialization << getType();

	serialization << delimiter;

	struct tm *nowtm;
	char tmbuf[64] ;
	
	nowtm = localtime(&timeSent);
	strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
	
	string timeString (tmbuf);

	serialization << timeString;

	serialization << delimiter;

	serialization << getLifeTime(); 

	serialization << delimiter;

	serialization << getPacketNumber();

	serialization << delimiter;

	serialization << getHopCount();

	serialization << delimiter;
	
	serialization << getSourceAddress();

	serialization << delimiter;

	serialization << getDestinationAddress();

	serialization << delimiter;

	serialization << getPayload();

	return serialization.str();
}