Class CSpoofSocket::
Create()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: ConstructStaticIPHeaderNext page: CSpoofSocket    Show member index
Public Function Declared in:
SpoofSocket.h

'Declaration' icon -- Shortcut to top of page. Declaration

BOOL Create(
    int iProtocol);

'Description' icon -- Shortcut to top of page. Description

Create a socket

'Function Body' icon -- Shortcut to top of page. Function Body

//Close the socket if open
if (ValidSocket())
    Close();

try
{
    //Are we overlapped
    if (!m_bOverlapped)
    {
        //Here we create the raw socket
        if (m_bRaw || iProtocol==IPPROTO_ICMP)
            m_aSpoofSocket=socket(AF_INET,
                                  SOCK_RAW,
                                  iProtocol);
        else
            if (iProtocol==IPPROTO_TCP)
                m_aSpoofSocket=socket(AF_INET,
                                      SOCK_STREAM,
                                      iProtocol);
            else if (iProtocol==IPPROTO_UDP)
                m_aSpoofSocket=socket(AF_INET,
                                      SOCK_DGRAM,
                                      iProtocol);
    }
    else
    {
        //Here we create the raw socket
        if (m_bRaw || iProtocol==IPPROTO_ICMP)
            m_aSpoofSocket=WSASocket(AF_INET,
                                     SOCK_RAW,
                                     iProtocol,
                                     NULL,
                                     NULL,
                                     WSA_FLAG_OVERLAPPED);
        else
            if (iProtocol==IPPROTO_TCP)
                m_aSpoofSocket=WSASocket(AF_INET,
                                         SOCK_STREAM,
                                         iProtocol,
                                         NULL,
                                         NULL,
                                         WSA_FLAG_OVERLAPPED);
            else if (iProtocol==IPPROTO_UDP)
                m_aSpoofSocket=WSASocket(AF_INET,
                                         SOCK_DGRAM,
                                         iProtocol,
                                         NULL,
                                         NULL,
                                         WSA_FLAG_OVERLAPPED);
    }

    //Check for socket validity
    if (m_aSpoofSocket==INVALID_SOCKET)
    {
        //Error
        SetLastError("Create");

        //Done
        return FALSE;
    }

    if (m_bRaw)
    {
        //Set that the application will send the IP header
        unsigned int iTrue=1;

        if(setsockopt(m_aSpoofSocket,
                      IPPROTO_IP,
                      IP_HDRINCL,
                      (char*)&iTrue,
                      sizeof(iTrue))==GetErrorCode())
        {
            //Check for options error
            SetLastError("Create");

            //Exit
            return FALSE;
        }
    }

    //Done
    return TRUE;
}
ERROR_HANDLER_RETURN("Create",FALSE)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CSpoofBase  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!This web site was generated using Surveyor V4.50.811.1.  Click here for more information. Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003.