Skip to content

Commit

Permalink
backend: Remove setting custom envrionment variables
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
Biswa96 committed Dec 20, 2023
1 parent 1770edd commit 5b2b652
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 75 deletions.
8 changes: 0 additions & 8 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 0 additions & 57 deletions src/nix-sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 0 additions & 3 deletions src/nix-sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/wslbridge2-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down

0 comments on commit 5b2b652

Please sign in to comment.