How to use /dev/bpf

Post Reply
xfangfang
Posts: 1
Joined: Tue Feb 13, 2024 11:43 am

How to use /dev/bpf

Post by xfangfang » Tue Feb 13, 2024 12:55 pm

Hi, Thank you very much for your reply. I am not sure if this is the correct location for the question.

According to the wiki: https://switchbrew.org/wiki/Sockets_services#Open, we can use /dev/bpf in NintendoSwitch, so I wrote these code:

Code: Select all

// init socket
SocketInitConfig cfg = *(socketGetDefaultInitConfig());
cfg.bsd_service_type = BsdServiceType_System;
socketInitialize(&cfg);

// open bpf
int fd = open("soc:/dev/bpf0", O_RDWR);
if (fd < 0) {
    perror("Unable to open /dev/bpf");
} else {
    printf("/dev/bpf: %d\n", fd);
}

// set network interface
struct ifreq ifr;
strncpy(ifr.ifr_name, "lo0", sizeof(ifr.ifr_name));
if (ioctl(fd, BIOCSETIF, &ifr) == -1) {
    perror("BIOCSETIF");
    return 1;
}
I can open soc:/dev/bpf0 successfully, my question is:
1. I don't know which IF to use, so I used lo0 for testing. If I want to monitor game traffic, which IF should I use ?
2. When using ioctl BIOCSETIF, the program always returned -1 with a blank error description.
3. I am also unable to use BIOCSETF. I am curious if the ioctl on the NintendoSwitch really supports the BIOCSETIF and BIOCSETF as it described in the switchbrew wiki.

In the code of libnx, I saw content related to BIOCSETF, and I think maybe someone has done something similar before.
https://github.com/switchbrew/libnx/bla ... ket.c#L708

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests