Creating raw socket on ESXi is not receiving any data

64 Views Asked by At

I am working on a project that requires me to open a raw socket on a ESXi host. I have been able to successfully get this to build on Ubuntu and run on Ubuntu. When transferring to ESXi 6.7 it will run however I do not get any data from recv().

int main()
{
    int saddr_size , data_size;
    struct sockaddr saddr;  
    unsigned char buffer[512];

    //Create a raw socket
    sock_raw = socket(AF_PACKET, SOCK_RAW | SOCK_NONBLOCK, htons(ETH_P_ALL));
    if(sock_raw < 0)
    {
        printf("Socket Error\n");
        return 1;
    }
    while(1)
    {
        saddr_size = sizeof saddr;
        //Receive a packet
        data_size = recvfrom(sock_raw, buffer, 512, 0, &saddr, &saddr_size);
        if(data_size < 0 )
        {
            printf("Recvfrom() error, failed to get packets\n");
            return 1;
        }
        //Now process the packet
    }
    close(sock_raw);
    printf("Finished");
    return 0;
}

I have tried putting debug prints and noticed that it is looping through the recvfrom() function but just never getting any data. It will return -1 and errno set to EAGAIN. While it is running I will scan it with a TCP Connect scan to ensure it is getting packets sent to it. I have also swapped out ETH_P_ALL for IPPROTO_TCP and get the same results. Does ESXi have some setting I need to change? I have tried static and dynamic builds.

0

There are 0 best solutions below