![]() |
Send() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Public Function |
Declared in: UDPSocket.h |
virtual BOOL Send( unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort, const char* pBuffer, unsigned short usBufferLength);
Send UDP datagrams usSourcePort - Applicatable for raw sockets only Return value: Positive - The number of bytes received. Zero - Socket has been closed. Negative - Error
try { //Quit if not ok if (!CheckSocketValid()) return FALSE; //Are we raw? if (IsRaw()) { //We can construct the UDP here UDPHeader aHeader; //Set the ports aHeader.usSourcePort=htons(usSourcePort); aHeader.usDestinationPort=htons(usDestinationPort); //Set the length aHeader.usLength=htons(UDPHeaderLength); //Check sum aHeader.usChecksum=0; //Result flag int iResult; //Do we have a buffer ? if (usBufferLength) { //Create the buffer unsigned long ulTotalLength; ulTotalLength=UDPHeaderLength+usBufferLength; //Allocatet the buffer char* pNewBuffer; pNewBuffer=new char[ulTotalLength]; //Protect the buffer CArray_ptr<char> pProtection(pNewBuffer); //Set the length aHeader.usLength=htons(ulTotalLength); //Copy the UDP header memcpy(pNewBuffer, &aHeader, UDPHeaderLength); //Copy the data memcpy(pNewBuffer+UDPHeaderLength, pBuffer, usBufferLength); //Update it aHeader.usChecksum=CalculatePseudoChecksum(pNewBuffer, ulTotalLength, aDestinationAddress, ulTotalLength); //Set the new checksum (if applicateable) FinalUDPHeader(&aHeader); //Recopy it memcpy(pNewBuffer, &aHeader, UDPHeaderLength); //Send it iResult=CSpoofSocket::Send(aDestinationAddress, pNewBuffer, ulTotalLength, usDestinationPort); } else { //Update it aHeader.usChecksum=CalculatePseudoChecksum((char*)&aHeader, UDPHeaderLength, aDestinationAddress, UDPHeaderLength); //Set the new checksum (if applicateable) FinalUDPHeader(&aHeader); //Send it iResult=CSpoofSocket::Send(aDestinationAddress, (char*)&aHeader, UDPHeaderLength, usDestinationPort); } //Done return iResult; } else //Try a regular send return CSpoofSocket::Send(aDestinationAddress, pBuffer, usBufferLength, usDestinationPort); } ERROR_HANDLER_RETURN("Send",FALSE)
![]() |
Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003. |