Exemplo n.º 1
0
IPSTACK *  IPSRefresh(IPSTACK * pIpStack, const LLADP * pLLAdp, IPSTATUS * pStatus)
{
    AssignStatusSafely(pStatus, ipsSuccess);
    if(pIpStack == NULL)
    {
        pIpStack = IPSGetIpStackFromAdaptor(pLLAdp, ippnTCP, pStatus);
    }
    else
    {
        pIpStack =  IPSSwapSrcAndDest(pIpStack);        
    }

    if(pIpStack != NULL)
    {
        // the payload may have a pointer in it that we are going to clear
        // that pointer may or may not be from the heap; but if it is not from
        // the heap, the pointer will be outside of the heap ranage and be ignored
        // by the heap manager with no damage.
        if(pIpStack->fFreePayloadToAdp)
        {
            RRHPFree(pIpStack->pLLAdp->pNwAdp->hAdpHeap, pIpStack->pPayload);
        }
        pIpStack->cbPayload             = 0;
        pIpStack->pPayload              = NULL;

        switch(pIpStack->protocol)
        {
            case ippnUDP:
                pIpStack->pUDPHdr->cbHdrData    = sizeof(UDPHDR);
                pIpStack->pUDPHdr->checksum     = 0;
                break;

            case ippnTCP:
                pIpStack->pTCPHdr->u16Flags     = 0;
                pIpStack->pTCPHdr->dataOffset   = sizeof(TCPHDR)/sizeof(uint32_t);
                pIpStack->pTCPHdr->urgentPtr    = 0;
                pIpStack->pTCPHdr->checksum     = 0;
                break;

            default:
                break;
        }
    }

    return(pIpStack);
}
Exemplo n.º 2
0
bool ICMPv4Send(const LLADP * pLLAdp, IPv4 * pIPv4Dest, void * pICMPDgm, uint32_t cbICMPDgm, IPSTATUS * pStatus)
{
	IPSTACK * pIpStack;

	if( (pIpStack = IPSGetIpStackFromAdaptor(pLLAdp, ippnICMP, pStatus)) == NULL)
	{
		return(false);
	}

   	pIpStack->cbPayload          	= cbICMPDgm;
   	pIpStack->pPayload             	= pICMPDgm;

  	pIpStack->pICMPHdr->checksum 	= 0;

	pIpStack->pIPv4Hdr->cbTotal		+= cbICMPDgm;
	pIpStack->pIPv4Hdr->ipDest.u32	= pIPv4Dest->u32;

    return(ILSend(pIpStack, pStatus));
}
Exemplo n.º 3
0
bool UDPSend(HSOCKET hSocket, const uint8_t * pbDatagram, uint16_t cbDatagram, IPSTATUS * pStatus)
{
    UDPSOCKET * pSocket     = (UDPSOCKET *) hSocket;
    IPSTACK *   pIpStack    = NULL;

    if(pSocket->s.portRemote == portListen || pSocket->s.portRemote == portInvalid)
    {
        AssignStatusSafely(pStatus, ipsSocketNotResolved);
        return(false);
    }
    else if((pIpStack = IPSGetIpStackFromAdaptor(pSocket->s.pLLAdp, ippnUDP, pStatus)) == NULL)
    {
        return(false);
    }
    else if(UDPRawSend(pSocket->s.pLLAdp, pIpStack, (void *) &pSocket->s.ipRemote, pSocket->s.portRemote,  pSocket->s.portLocal, pbDatagram, cbDatagram, true, pStatus))
    {
         return(true);
    }
    else
    {
        IPSRelease(pIpStack);
        return(false);
    }
}