xdp-tutorial icon indicating copy to clipboard operation
xdp-tutorial copied to clipboard

Send data with an socket to an port running locally

Open Fabian-Ser opened this issue 2 years ago • 1 comments

Hi all,

I am trying to send data via an socket to an socket sever (running on an port)

My current code looks like this now:

short SocketCreate(void)
{
    short hSocket;
    bpf_printk("Create the socket\n");
    hSocket = socket(AF_INET, SOCK_STREAM, 0);
    return hSocket;
}

int SocketConnect(int hSocket)
{
    int iRetval=-1;
    int ServerPort = 46500;
    struct sockaddr_in remote= {0};
    remote.sin_addr.s_addr = 2130706433; //Local Host
    remote.sin_family = AF_INET;
    remote.sin_port = htons(ServerPort);
    iRetval = connect(hSocket,(struct sockaddr *)&remote,sizeof(struct sockaddr_in));
    return iRetval;
}

I #include <sys/socket.h> in my Main.c. I get the following error:

libbpf: failed to find BTF for extern 'socket' [33] section: -2
ERROR: opening BPF object file failed

How can I fix this?

Fabian-Ser avatar Oct 26 '22 17:10 Fabian-Ser

Erm, what? You're trying to open a socket from inside a BPF program? You definitely can't do that...

tohojo avatar Oct 26 '22 21:10 tohojo