Custom error page

hello, i want custom error massage after blocking site using wfp filter driver for example after blocking site browser shows "can't reach to site" i want my custom error massage, how can i achieve it.

You don't...You can't control how the application handles your failures. You need something in the notification area to pop your own custom dialogs/notifications (e.g. something like NotifyIcon Class (System.Windows.Forms) | Microsoft Learn)

thanks for reply, using wfp i will redirect traffic to local proxy instead blocking it and using local proxy return custom error page for example like error page 404 ,will do for all connections to proxy server. is there any way for it ,if yes, how to implement it.

You can receive the connection from the redirected client, then send an http 404 page content to the connection, and then close the connection

thanks for replay, I have redirected connection to local proxy and using it i am trying to redirect it to other remote address than original remote address but it didn't worked and showing error page on browser.is it possible to redirect connection to other address then original one ,for example original request is google.com and redirect it to apple.com?

Redirecting from google.com to apple.com might not work due to HTTPS security verification restrictions. I'm just saying it might not work because I haven't tried it, but regular HTTP pages(for example, your own local server hosting an error page) can be redirected. You just need to change the destination IP address in the driver layer or local proxy program to the server address hosting the HTTP page. It may not be achievable even with a reverse proxy server.
Also, I want to ask how the local proxy retrieves the original UDP address. I tried using redirection context, but I failed to retrieve it using WSAIoctl on the UDP socket; WSAGetLastError returns 10045, indicating an unsupported operation according to the official documentation.

proxy should be on same machine and format of wsaioctl should be correct you can find it in documentation also open proxy server in admin privileges

Thanks for reply,I can obtain the TCP redirection context using wsaioctl and redirect TCP traffic, but UDP sockets always return 10045. I haven't found any explanation for this in the official documentation. Here's Pseudocode:

recvfrom(UDPSocket, UDPBuffer, DATABUFFER_SIZE, 0, (sockaddr*)&ClientAddr, &SizeOfClientAddr);
WSAIoctl(UDPSocket, SIO_QUERY_WFP_CONNECTION_REDIRECT_CONTEXT, 0, 0,redirectContext, sizeof(WfpContext), &bytesReturned, 0, 0);

I haven't yet done it for UDP sockets, i have an problem for tcp proxy connection, i am getting traffic on proxy server from client and forward it to original dest and again forward responce of sever to client but still client showing can't reach to site. what need to be done?

Your information is not enough, can you send the source code?

thank for reply,
this is code for proxy server

if (connect(serverSock, (SOCKADDR*)&serverAddr, sizeof(serverAddr)) == SOCKET_ERROR) {
printf("Failed to connect to server: %ld\n", WSAGetLastError());
closesocket(clientSocket);
closesocket(serverSock);
continue;
}

char buffer[20480];
int bytesRead;

while (1)
{
bytesRead = recv(clientSocket, buffer, sizeof(buffer), 0);
if (bytesRead > 0) {
int bytesSent = send(serverSock, buffer, bytesRead, 0);
if (bytesSent == SOCKET_ERROR) {
printf("Error sending data to server: %d\n", WSAGetLastError());

       }
       else if (bytesSent < bytesRead) {
           printf(" Not all data sent to server.\n");
           
       }

   }
    else if (bytesRead == 0) {
       // Client closed the connection
       printf("Client closed connection.\n");
       break;
    }
   else {
       // Error or connection closed by client
       printf("Error receiving data from client: %d\n", WSAGetLastError());
       break;
   }


       bytesRead = recv(serverSock, buffer, sizeof(buffer), 0);
       if (bytesRead > 0) {
           
           int bytesSent = send(clientSocket, buffer, bytesRead, 0);
           if (bytesSent == SOCKET_ERROR) {
               printf("Error sending data to server: %d\n", WSAGetLastError());

           }
           else if (bytesSent < bytesRead) {
               printf(" Not all data sent to server.\n");

           }

       }
       else if (bytesRead == 0) {
          
           printf("Server closed connection.\n");
           break;
       }
       else {
           
           printf("Error receiving data from server: %d\n", WSAGetLastError());
           break;
       }

}

Your code logic is encountering a data blocking issue. Each data transfer occurs unidirectionally and can only handle TCP data transmission from a single client. You need to divide each client connection into a thread. Within this thread, further divide it into two threads. One thread continuously retrieves data from the client and forwards it to the server, while the other thread continuously retrieves data from the server and forwards it to the client. When the return values of the recv and send functions are not greater than or equal to zero, it indicates a connection interruption on one side. At this point, shutdown and closesocket both sockets, then exit the thread.