-
Notifications
You must be signed in to change notification settings - Fork 14
Fixed libcap with "any" device setting #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,24 @@ | |
#include <stdio.h> | ||
|
||
#include <pcap.h> | ||
#include <string.h> | ||
|
||
#include "params.h" | ||
#include "in.h" | ||
|
||
static pcap_t *p; | ||
|
||
static char *device; | ||
|
||
int in_init(void) | ||
{ | ||
char *device; | ||
char error[PCAP_ERRBUF_SIZE]; | ||
struct bpf_program filter; | ||
|
||
#ifdef SCANLOGD_DEVICE | ||
device = SCANLOGD_DEVICE; | ||
#else | ||
if (!(device = pcap_lookupdev(error))) { | ||
fprintf(stderr, "pcap_lookupdev: %s\n", error); | ||
return 1; | ||
} | ||
device = "any"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not continue using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see you wrote in the PR description:
I think if we do this, it should be a separate commit. BTW, your current commit message is over-long - I suggest that first lines (titles) of commit messages be limited to 72 chars, and subsequent lines (if any) wrapped at 75 (so that it's 79 max after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think that making the "any" as default should work for most users. It is much more useful than picking a random first interface. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, if we change the default, that also needs to be reflected in the comment in |
||
#endif | ||
|
||
if (!(p = pcap_open_live(device, sizeof(struct header), | ||
|
@@ -64,6 +63,9 @@ void in_run(void (*process_packet)(struct header *packet, int size)) | |
hw_size = 14; | ||
} | ||
|
||
if(device == NULL || strcmp(device, "any") == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent coding style with the rest of the file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you be more specific about what's wrong with this coding style? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The missing space between Also, while there isn't an exact example like this in scanlogd in particular, other checks generally use |
||
hw_size += 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the most important aspect: skipping the 2 bytes unconditionally probably breaks proper behavior with certain older versions of libpcap - ideally, we should investigate that and make this skipping conditional upon libpcap version (if our understanding is correct, or do something different if the understanding is not confirmed). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've just tested - the skipping of 2 bytes is needed even with libpcap 0.9.4. So we're good making this change unconditionally, and not skipping was probably always a scanlogd bug. |
||
|
||
while (1) | ||
if ((packet = (char *)pcap_next(p, &header))) { | ||
packet += hw_size; | ||
|
Uh oh!
There was an error while loading. Please reload this page.