![]() |
Send() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Public Function |
Declared in: UDPSocket.h |
BOOL Send( int iSourcePort, LPCSTR lpDestinationAddress, int iDestinationPort, const char* buf, int BufLength);
Send data
try { //Quit if not ok if (!CheckSocketValid()) return FALSE; //We can construct the UDP here LPUDPHeader lpUDP; lpUDP=new UDPHeader; //Set the ports lpUDP->SourcePort=htons(iSourcePort); lpUDP->DestinationPort=htons(iDestinationPort); //Set the length lpUDP->Length=htons(UDPHeaderLength); //Check sum lpUDP->Checksum=0; BOOL bResult; if (BufLength) { //Create the buffer int iTotalLength; iTotalLength=UDPHeaderLength+BufLength; char* tmpBuf; tmpBuf=new char[iTotalLength]; //Set the length lpUDP->Length=htons(iTotalLength); memcpy(tmpBuf,lpUDP,UDPHeaderLength); memcpy(tmpBuf+UDPHeaderLength,buf,BufLength); //Update it lpUDP->Checksum=CalculatePseudoChecksum(tmpBuf,iTotalLength,lpDestinationAddress,iTotalLength); //Recopy it memcpy(tmpBuf,lpUDP,UDPHeaderLength); //Set the new checksum (if applicateable) FinalUDPHeader(lpUDP); //Send it bResult=CSpoofSocket::Send(lpDestinationAddress,tmpBuf,iTotalLength,iDestinationPort); //Delete delete tmpBuf; } else { //Update it lpUDP->Checksum=CalculatePseudoChecksum((char*)lpUDP,UDPHeaderLength,lpDestinationAddress,UDPHeaderLength); //Set the new checksum (if applicateable) FinalUDPHeader(lpUDP); //Send it bResult=CSpoofSocket::Send(lpDestinationAddress,(char*)lpUDP,UDPHeaderLength,iDestinationPort); } //Clean up delete lpUDP; return bResult; } ERROR_HANDLER_RETURN("Send",FALSE)
![]() |
Site content copyright © 2001 Barak Weichselbaum. See the About page for additional notices. This page last updated: 27 Jun 2001. |