-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsockfilter.c
50 lines (44 loc) · 1.27 KB
/
sockfilter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/* Copyright (c) 2022 Jacky Yin */
#include <assert.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/tcp.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdbool.h>
#include "sockfilter.skel.h"
#define SO_ATTACH_BPF 50
int main(int argc, char** argv) {
struct sockfilter_bpf* skel;
int err, prog_fd, sock;
/* Load and verify BPF programs*/
skel = sockfilter_bpf__open_and_load();
if (!skel) {
fprintf(stderr, "Failed to open and load BPF skeleton\n");
return 1;
}
printf("[Client] Create TCP socket\n");
// TODO: add socket api from wasi
// sock = socket(AF_INET, SOCK_STREAM, 0);
// if (sock == -1) {
// perror("Create socket failed");
// return EXIT_FAILURE;
// }
// /* Attach BPF program to raw socket */
// prog_fd = bpf_program__fd(skel->progs.socket_handler);
// if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd, sizeof(prog_fd))) {
// err = -3;
// fprintf(stderr, "Failed to attach to raw socket\n");
// goto cleanup;
// }
sleep(10);
cleanup:
sockfilter_bpf__destroy(skel);
return -err;
}