proxychains-ng/src/daemon/udpclient.c

42 lines
1.0 KiB
C
Raw Normal View History

experimental new feature: proxy_dns_daemon since many users complain about issues with modern, ultracomplex clusterfuck software such as chromium, nodejs, etc, i've reconsidered one of my original ideas how to implement remote dns lookup support. instead of having a background thread serving requests via a pipe, the user manually starts a background daemon process before running proxychains, and the two processes then communicate via UDP. this requires much less hacks (like hooking of close() to prevent pipes from getting closed) and doesn't need to call any async-signal unsafe code like malloc(). this means it should be much more compatible than the previous method, however it's not as practical and slightly slower. it's recommended that the proxychains4-daemon runs on localhost, and if you use proxychains-ng a lot you might want to set ip up as a service that starts on boot. a single proxychains4-daemon should theoretically be able to serve many parallel proxychains4 instances, but this has not yet been tested so far. it's also possible to run the daemon on other computers, even over internet, but currently there is no error-checking/ timeout code at all; that means the UDP connection needs to be very stable. the library code used for the daemon sources are from my projects libulz[0] and htab[1], and the server code is loosely based on microsocks[2]. their licenses are all compatible with the GPL. if not otherwise mentioned, they're released for this purpose under the standard proxychains-ng license (see COPYING). [0]: https://github.com/rofl0r/libulz [1]: https://github.com/rofl0r/htab [2]: https://github.com/rofl0r/microsocks
2020-09-23 21:00:29 +00:00
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "../remotedns.h"
#include "../ip_type.h"
int main() {
int fd;
int port = 1053;
char srvn[] = "127.0.0.1";
struct sockaddr_in srva = {.sin_family = AF_INET, .sin_port = htons(port)};
inet_pton(AF_INET, srvn, &srva.sin_addr);
fd = socket(AF_INET, SOCK_DGRAM, 0);
char namebuf[260];
while(fgets(namebuf, sizeof namebuf, stdin)) {
size_t l = strlen(namebuf);
if(namebuf[l-1] == '\n') {
l--;
namebuf[l] = 0;
}
struct at_msg msg = {0};
unsigned msglen;
if(isdigit(namebuf[0])) {
msglen = 4;
msg.h.msgtype = ATM_GETNAME;
inet_aton(namebuf, (void*) &msg.m.ip);
} else {
msglen = l+1;
msg.h.msgtype = ATM_GETIP;
memcpy(msg.m.host, namebuf, msglen);
}
msg.h.datalen = htons(msglen);
sendto(fd, &msg, sizeof(msg.h)+msglen, 0, (void*)&srva, sizeof(srva));
char rcvbuf[512];
recvfrom(fd, rcvbuf, sizeof rcvbuf, 0, (void*)0, (void*)0);
}
}