+ /* Set up ringbuffer */
+
+ get_config_int(lookup_config(config_tree, "RingBufferSize"), &nbufs);
+ if(nbufs <= 1)
+ nbufs = 1;
+ else if(nbufs > 256)
+ nbufs = 256;
+
+ bufs = xmalloc_and_zero(nbufs * sizeof *bufs);
+
+ /* Create a listening socket */
+
+ err = getaddrinfo(NULL, myport, &hint, &ai);
+
+ if(err || !ai) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "getaddrinfo", gai_strerror(errno));
+ return false;
+ }
+
+ sock = socket(ai->ai_family, SOCK_STREAM, IPPROTO_TCP);
+
+ if(sock < 0) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "socket", strerror(errno));
+ return false;
+ }
+
+ if(bind(sock, ai->ai_addr, ai->ai_addrlen)) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "bind", strerror(errno));
+ return false;
+ }
+
+ freeaddrinfo(ai);
+
+ if(listen(sock, 1)) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "listen", strerror(errno));
+ return false;
+ }
+
+ /* Start the tap reader */
+
+ thread = CreateThread(NULL, 0, tapreader, NULL, 0, NULL);
+
+ if(!thread) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "CreateThread", winerror(GetLastError()));
+ return false;
+ }
+
+ /* Wait for the tap reader to connect back to us */
+
+ if((device_fd = accept(sock, NULL, 0)) == -1) {
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "accept", strerror(errno));
+ return false;
+ }
+
+ closesocket(sock);
+
+ /* Set media status for newer TAP-Win32 devices */
+
+ status = true;
+ DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof status, &status, sizeof status, &len, NULL);
+