diff --git a/FAQ.md b/FAQ.md index bb2a843..9515035 100644 --- a/FAQ.md +++ b/FAQ.md @@ -69,14 +69,6 @@ and buffer handling are different. ------ -**Q4: How to get Windows IP address in WSL2 quickly?** - -**A4:** Run `wslbridge2.exe` command as usual. IPv4 address of Windows 10 side -is set to `WSL_HOST_IP` and of WSL2 side is set to `WSL_GUEST_IP` environment -variable. e.g. for GUI programs, use `export DISPLAY=$WSL_HOST_IP:0`. - ------- - **Q5: What are the error code starting with 0x8?** **A5:** Generally the [system error codes][3] are translated into error diff --git a/src/nix-sock.c b/src/nix-sock.c index 05eda68..8287ac6 100644 --- a/src/nix-sock.c +++ b/src/nix-sock.c @@ -160,60 +160,3 @@ int nix_vsock_listen(unsigned int *port) *port = addr.svm_port; return sock; } - -// Set custom environment variables with IP values for WSL2. -void nix_set_env(void) -{ - const int sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) - { - perror("socket(AF_INET)"); - return; - } - - struct ifreq ifr; - memset(&ifr, 0, sizeof ifr); - strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); - const int ioctlRet = ioctl(sock, SIOCGIFADDR, &ifr); - close(sock); - if (ioctlRet != 0) - { - perror("ioctl(SIOCGIFADDR)"); - return; - } - - // Do not override environment if the name already exists. - struct sockaddr_in *addr_in = (struct sockaddr_in *)&ifr.ifr_addr; - setenv("WSL_GUEST_IP", inet_ntoa(addr_in->sin_addr), false); - - unsigned long int dest, gateway; - char iface[IF_NAMESIZE]; - char buf[4096]; - - memset(iface, 0, sizeof iface); - memset(buf, 0, sizeof buf); - - // Read route file to get IP address of default gateway or host. - FILE *rfd = fopen("/proc/net/route", "r"); - if (rfd == NULL) - { - perror("fopen(route)"); - return; - } - - while (fgets(buf, sizeof buf, rfd)) - { - if (sscanf(buf, "%s %lx %lx", iface, &dest, &gateway) == 3) - { - if (dest == 0) // Default destination. - { - struct in_addr addr; - addr.s_addr = gateway; - setenv("WSL_HOST_IP", inet_ntoa(addr), false); - break; - } - } - } - - fclose(rfd); -} diff --git a/src/nix-sock.h b/src/nix-sock.h index 10a0668..a2118ab 100644 --- a/src/nix-sock.h +++ b/src/nix-sock.h @@ -35,9 +35,6 @@ int nix_vsock_connect(const unsigned int port); // Create and listen to a vsocket and return it. int nix_vsock_listen(unsigned int *port); -// Set custom environment variables with IP values for WSL2. -void nix_set_env(void); - #ifdef __cplusplus } #endif diff --git a/src/wslbridge2-backend.cpp b/src/wslbridge2-backend.cpp index b6819e2..d04093f 100644 --- a/src/wslbridge2-backend.cpp +++ b/src/wslbridge2-backend.cpp @@ -337,13 +337,6 @@ int main(int argc, char *argv[]) for (char *const &setting : childParams.env) putenv(setting); - /* - * wsltty#225: Set WSL_GUEST_IP environment variable in WSL2 only. - * As WSL1 gets same IP address as Windows and NIC may not be eth0. - */ - if (vmMode) - nix_set_env(); - /* Changed directory should affect in child process */ if (!childParams.cwd.empty()) {