When I want to implement the PPTP client in MacOS, the LCP packet encapsulated in GRE packet can't be received from PPTP server in my computer, the OS is Catalina 10.15.2.
This is my code written in C.
int ppp_fd;
if ((ppp_fd = socket(AF_INET, SOCK_RAW, IPPROTO_GRE)) <= 0)
{
perror("[Error] Create a new socket failed");
return;
}
struct sockaddr_in recv;
recv.sin_addr.s_addr = htonl(INADDR_ANY);
recv.sin_port = 0;
recv.sin_family = AF_INET;
char buffer[BUFSIZ];
int ret;
int addr_len = sizeof(recv);
if((ret = recvfrom(ppp_fd, buffer, BUFSIZ, 0, (struct sockaddr *)&recv, (socklen_t *)&addr_len)) < 0)
{
perror("[ERROR] Receive data failed");
return;
}
printf("ret: %d\n", ret);
The Wireshark can capture the Configure Request correctly, but the code seem to be blocked and print nothing.
Ok, perhaps we can't normally receive the data through raw socket in MacOS, but the software like Wireshark, tcpdump and etc. can capture the traffic. So, for solving the above questions, just following a few steps below.
#include<pcap/pcap.h>
in your source file.gcc source_name.c -lpcap -o output_name
in your terminal to compile and link.In effect, many protocols in MacOS can't be received correctly, in my practice, at least the ICMP datagram can do that.