try
{
//Quit if not ok
if (!CheckSocketValid())
return FALSE;
//Create the local address
sockaddr_in soSrc;
//Set to 0
memset(&soSrc,0,sizeof(soSrc));
soSrc.sin_family=AF_INET;
//Populate the connection data
if (aSourceAddress)
soSrc.sin_addr.s_addr=aSourceAddress;
else
soSrc.sin_addr.s_addr=ADDR_ANY ;
soSrc.sin_port=htons(usPort);
//Now we need to bind it
if (bind(GetHandle(),
(sockaddr*)&soSrc,
sizeof(soSrc)))
{
//Error
SetLastError("Bind");
//Exit
return FALSE;
}
else
//Save the address
m_aConnectedTo=soSrc;
//If already has a source address then don't change it
if (!m_ulSourceAddress)
//Save it as the source address (spoofing options only)
m_ulSourceAddress=aSourceAddress;
return TRUE;
}
ERROR_HANDLER_RETURN("Bind",FALSE)