Closed fshahinfar1 closed 6 months ago
In the following program, the malloc statement will be replaced by the packet. The generated BPF code will first do a lookup to a map and then replace the pointer with the packet. It would be nice to track unused map lookups and remove them.
#include <arpa/inet.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #define BUFSIZE 128 int main(int argc, char *argv[]) { int fd; struct sockaddr_in sk_addr, addr; socklen_t addr_len; inet_pton(AF_INET, "127.0.0.1", &(sk_addr.sin_addr)); sk_addr.sin_port = htons(8080); fd = socket(AF_INET, SOCK_DGRAM, 0); bind(fd, (struct sockaddr *)&sk_addr, sizeof(sk_addr)); while (1) { char *buf = malloc(BUFSIZE); recvfrom(fd, buf, BUFSIZE, 0, (struct sockaddr *)&addr, &addr_len); /* Drop everything */ free(buf); } return 0; }
The issue should be solved (although the code might not be stable).
In the following program, the malloc statement will be replaced by the packet. The generated BPF code will first do a lookup to a map and then replace the pointer with the packet. It would be nice to track unused map lookups and remove them.