Unable to receive custom Ethernet frame
-
You must check the return value from the
recvfrom
call to find out why it is not working. See recvfrom function | Microsoft Docs[^].recvfrom has no return value, because there is no data, so it is blocking. And if I change 0x2328 to 0x0003, I can receive it.
-
recvfrom has no return value, because there is no data, so it is blocking. And if I change 0x2328 to 0x0003, I can receive it.
-
After I set it to non-blocking, I always returned error code 11, but I didn't find the error message corresponding to 11.
-
After I set it to non-blocking, I always returned error code 11, but I didn't find the error message corresponding to 11.
Could you show the actual code used to obtain the error?
-
After I set it to non-blocking, I always returned error code 11, but I didn't find the error message corresponding to 11.
-
After I set it to non-blocking, I always returned error code 11, but I didn't find the error message corresponding to 11.
It won't help you with your problem but error code 11 is
EGAIN
defined in errno.h. It indicates that you should execute the function again until you get data or an error, or give up (time out). It is returned by non-blocking functions when the corresponding blocking function would block. -
It won't help you with your problem but error code 11 is
EGAIN
defined in errno.h. It indicates that you should execute the function again until you get data or an error, or give up (time out). It is returned by non-blocking functions when the corresponding blocking function would block.int main(int argv, char *argc[])
{
struct ifreq ifr;
struct sockaddr_ll sll;
int sd, sll_len;
sll_len = sizeof(sll);
if ((sd = socket(PF_PACKET, SOCK_RAW, htons(0x2328))) < 0)
printf("create socket failed!\n");sll.sll\_halen = ETH\_ALEN; strcpy(ifr.ifr\_name, "ens33"); ioctl(sd, SIOCGIFFLAGS, &ifr); ifr.ifr\_flags |= IFF\_PROMISC; if(fcntl(sd, F\_SETFL, O\_NONBLOCK) == -1) { perror("fcntl"); exit(errno); } char recvbuf\[2048\]; sleep(5); int n\_read = recvfrom(sd, recvbuf, 2048, 0, (struct sockaddr \*)&sll, &sll\_len); if (n\_read <= 0) { printf("%d\\n", errno); }
}
I started to cycle data before I hibernate, but I still can't receive it
-
int main(int argv, char *argc[])
{
struct ifreq ifr;
struct sockaddr_ll sll;
int sd, sll_len;
sll_len = sizeof(sll);
if ((sd = socket(PF_PACKET, SOCK_RAW, htons(0x2328))) < 0)
printf("create socket failed!\n");sll.sll\_halen = ETH\_ALEN; strcpy(ifr.ifr\_name, "ens33"); ioctl(sd, SIOCGIFFLAGS, &ifr); ifr.ifr\_flags |= IFF\_PROMISC; if(fcntl(sd, F\_SETFL, O\_NONBLOCK) == -1) { perror("fcntl"); exit(errno); } char recvbuf\[2048\]; sleep(5); int n\_read = recvfrom(sd, recvbuf, 2048, 0, (struct sockaddr \*)&sll, &sll\_len); if (n\_read <= 0) { printf("%d\\n", errno); }
}
I started to cycle data before I hibernate, but I still can't receive it
I found the reason. Previously, because send and recv were sent and received on the same network card, it could not be received.
-
I found the reason. Previously, because send and recv were sent and received on the same network card, it could not be received.
Fine to hear that. I do know that it does not work on the same interface. But you wrote in your initial post that you are sending from another machine so that I thought it must be something else.
-
You must check the return value from the
recvfrom
call to find out why it is not working. See recvfrom function | Microsoft Docs[^].i"m interested in c and c++.im provide the link and please visited my website
[url=https://www.imgsrc.com/\]imgsrc[/url]