Skip to content

Commit

Permalink
Update goodbyedpi.c
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaXser committed Jun 1, 2024
1 parent 0aebde0 commit 1b6267f
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/goodbyedpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,14 @@ static void add_filter_str(int proto, int port) {
const char *tcp = " or (tcp and !impostor and !loopback " MAXPAYLOADSIZE_TEMPLATE " and " \
"(tcp.SrcPort == %d or tcp.DstPort == %d))";

char *current_filter = filter_string;
size_t current_filter_length = strlen(current_filter);
size_t new_filter_size = current_filter_length +
(proto == IPPROTO_UDP ? strlen(udp) : strlen(tcp)) + 16;
char *new_filter = malloc(new_filter_size);
const char *template = proto == IPPROTO_UDP ? udp : tcp;
size_t needed_size = strlen(filter_string) + strlen(template) + 16;

snprintf(new_filter, new_filter_size, "%s%s", current_filter,
proto == IPPROTO_UDP ? udp : tcp, port, port);
if (needed_size > strlen(filter_string)) {
filter_string = realloc(filter_string, needed_size);
}

filter_string = new_filter;
free(current_filter);
snprintf(filter_string + strlen(filter_string), needed_size, template, port, port);
}

static void add_ip_id_str(int id) {
Expand Down Expand Up @@ -224,7 +221,6 @@ static void add_maxpayloadsize_str(unsigned short maxpayload) {
free(addfilter);
}


static void finalize_filter_strings() {
char *newstr = repl_str(filter_string, IPID_TEMPLATE, "");
free(filter_string);
Expand All @@ -238,17 +234,13 @@ static void finalize_filter_strings() {
static const char* dumb_memmem(const char* haystack, unsigned int hlen,
const char* needle, unsigned int nlen)
{
// naive implementation
if (nlen == 0) return haystack;

if (nlen > hlen) return NULL;
size_t i;
for (i=0; i<hlen-nlen+1; i++) {
if (memcmp(haystack+i,needle,nlen)==0) {
return haystack+i;
}
}
return NULL;
return strstr(haystack, needle);
}


unsigned short int atousi(const char *str, const char *msg) {
long unsigned int res = strtoul(str, NULL, 10u);
enum {
Expand Down

0 comments on commit 1b6267f

Please sign in to comment.