![]() |
Send() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
| Public Function |
Declared in: UDPSocket.h |
Declaration
BOOL Send(
int iSourcePort,
LPCSTR lpDestinationAddress,
int iDestinationPort,
const char* buf,
int BufLength);
DescriptionSend data
Function Body
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)
See Also
This web site was generated
using Surveyor V4.50.811.1. Click
here
for more information. |
Site content copyright © 2001 Barak Weichselbaum. See the About page for additional notices. This page last updated: 27 Jun 2001. |