+ /* Now we start the child */
+
+ reader_pid = fork();
+
+ if(reader_pid == -1) {
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "System call `%s' failed: %s", "fork", strerror(errno));
+ return false;
+ }
+
+ if(!reader_pid) {
+ /* The child opens the tap device for reading, blocking.
+ It passes everything it reads to the socket. */
+
+ char buf[MTU];
+ long inlen;
+
+ CloseHandle(device_handle);
+
+ device_handle = CreateFile(tapname, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, 0);
+
+ if(device_handle == INVALID_HANDLE_VALUE) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Could not open Windows tap device %s (%s) for reading: %s", device, iface, winerror(GetLastError()));
+ buf[0] = 0;
+ write(sp[1], buf, 1);
+ exit(1);
+ }
+
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "Tap reader forked and running.");
+
+ /* Notify success */
+
+ buf[0] = 1;
+ write(sp[1], buf, 1);
+
+ /* Pass packets */
+
+ for(;;) {
+ ReadFile(device_handle, buf, MTU, &inlen, NULL);
+ write(sp[1], buf, inlen);
+ }
+ }
+
+ read(device_fd, &gelukt, 1);
+
+ if(gelukt != 1) {
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "Tap reader failed!");
+ return false;
+ }
+
+ logger(DEBUG_ALWAYS, LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
+
+ return true;