# Russian translation of manpages # This file is distributed under the same license as the manpages-l10n package. # Copyright © of this file: # Alexander Golubev , 2018. # Azamat Hackimov , 2011, 2014-2016. # Hotellook, 2014. # Nikita , 2014. # Spiros Georgaras , 2016. # Vladislav , 2015. # Yuri Kozlov , 2011-2019. # Иван Павлов , 2017. msgid "" msgstr "" "Project-Id-Version: manpages-l10n\n" "POT-Creation-Date: 2024-06-01 06:20+0200\n" "PO-Revision-Date: 2019-10-15 18:55+0300\n" "Last-Translator: Yuri Kozlov \n" "Language-Team: Russian \n" "Language: ru\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" "%100>=11 && n%100<=14)? 2 : 3);\n" "X-Generator: Lokalize 2.0\n" #. type: TH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "SELECT_TUT" msgstr "SELECT_TUT" #. type: TH #: archlinux debian-unstable opensuse-tumbleweed #, no-wrap msgid "2024-05-02" msgstr "2 мая 2024 г." #. type: TH #: archlinux debian-unstable #, fuzzy, no-wrap #| msgid "Linux man-pages 6.7" msgid "Linux man-pages 6.8" msgstr "Linux man-pages 6.7" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "NAME" msgstr "ИМЯ" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "select, pselect - synchronous I/O multiplexing" msgstr "select, pselect - многопоточный синхронный ввод-вывод" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "LIBRARY" msgstr "" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "Standard C library (I, I<-lc>)" msgstr "" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "SYNOPSIS" msgstr "СИНТАКСИС" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "See B(2)" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "DESCRIPTION" msgstr "ОПИСАНИЕ" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, fuzzy #| msgid "" #| "B() and B() system calls are used to efficiently " "monitor multiple file descriptors, to see if any of them is, or becomes, " "\"ready\"; that is, to see whether I/O becomes possible, or an \"exceptional " "condition\" has occurred on any of the file descriptors." msgstr "" "Вызов B() " "and B(), see B() (or B()) call to " "return with I set to B. This behavior is essential so that " "signals can be processed in the main loop of the program, otherwise " "B() (or " #| "B()) call to return with I set to B. This " #| "behavior is essential so that signals can be processed in the main loop " #| "of the program, otherwise B() call? The answer is that B() call? The answer is that B() (или B()) вернуть " "управление вызвавшей программе; при этом I будет присвоено B. " "Это поведение продиктовано необходимостью обработки сигналов в главном цикле " "программы во избежание бесконечной блокировки B()? В этом случае программа навсегда останется в B()? Can't I just read and write to my file " "descriptors whenever I want? The point of B() " "efficiently copes with this situation." msgstr "" "Итак, какой прок от использования B() в том, что он позволяет следит за несколькими " "дескрипторами одновременно и корректно переводить процесс в режим ожидания, " "когда активности не наблюдается. Программисты UNIX часто попадают в " "ситуацию, когда необходимо обработать ввод-вывод из более чем одного " "файлового дескриптора в то время как поток данных может быть неравномерным. " "Если вы просто создадите последовательность вызовов B(2) и " "B(2), то можете попасть в ситуацию, когда один из вызовов будет " "ожидать данные из/в файлового дескриптора, в то время как другой будет " "простаивать, хотя данные для него уже появились. Вызов B() come across behavior that is " "difficult to understand and produces nonportable or borderline results. For " "instance, the above program is carefully written not to block at any point, " "even though it does not set its file descriptors to nonblocking mode. It is " "easy to introduce subtle errors that will remove the advantage of using " "B()." msgstr "" "Многие из тех, кто пытался использовать B(), поэтому вот список основных моментов, на которые " "нужно обращать внимание при использовании B() without a timeout. Your program " "should have nothing to do if there is no data available. Code that depends " "on timeouts is not usually portable and is difficult to debug." msgstr "" "Всегда старайтесь использовать B() call, and respond appropriately. See next " "rule." msgstr "" "Файловые дескрипторы не должны добавляться в наборы, если вы не планируете " "после вызова B() returns, all file descriptors in all sets should be " "checked to see if they are ready." msgstr "" "После возврата из B() can fail with the error B, and calls to B(2), " #| "B(2) B(2), and B(2) can fail with I set to " #| "B (B). These results must be properly managed (not " #| "done properly above). If your program is not going to receive any " #| "signals, then it is unlikely you will get B. If your program does " #| "not set nonblocking I/O, you will not get B." msgid "" "Calls to B(2), B(2), B(2), B(2), and B() могут " "завершиться ошибкой B, а вызовы B(2), B(2) B(2) и " "B(2) могут завершиться присвоением I значения B " "(B). Эти варианты должны быть правильно обработаны (в " "вышеприведенной программе этого не сделано). Если ваша программа не " "собирается принимать сигналы, то маловероятно, что вы получите B. " "Если ваша программа не использует неблокирующий ввод-вывод, то вы не " "получите B." #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "8." msgstr "8." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "Never call B(2), B(2), B(2), or B(2) with a buffer " "length of zero." msgstr "" "Никогда не вызывайте B(2), B(2), B(2) или B(2) с " "буфером нулевой длины." #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "9." msgstr "9." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "If the functions B(2), B(2), B(2), and B(2) fail " "with errors other than those listed in B<7.>, or one of the input functions " "returns 0, indicating end of file, then you should I pass that file " "descriptor to B() снова. В примере выше я немедленно " "закрываю файловый дескриптор и устанавливаю его в -1 для предотвращения его " "включения в набор." #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "10." msgstr "10." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "The timeout value must be initialized with each new call to B(), так как некоторые операционные системы изменяют значение " "структуры. Однако B() не изменяет структуру времени ожидания." #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "11." msgstr "11." #. "I have heard" does not fill me with confidence, and doesn't #. belong in a man page, so I've commented this point out. #. .TP #. 11. #. I have heard that the Windows socket layer does not cope with OOB data #. properly. #. It also does not cope with #. .BR select () #. calls when no file descriptors are set at all. #. Having no file descriptors set is a useful #. way to sleep the process with subsecond precision by using the timeout. #. (See further on.) #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "Since B() изменяет переданные наборы файловых дескрипторов, то при " "использовании его в цикле наборы должны повторно инициализироваться перед " "каждым вызовом." #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "RETURN VALUE" msgstr "ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "See B(2)." #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "NOTES" msgstr "ПРИМЕЧАНИЯ" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "Generally speaking, all operating systems that support sockets also support " "B() can be used to solve many problems in a portable " "and efficient way that naive programmers try to solve in a more complicated " "manner using threads, forking, IPCs, signals, memory sharing, and so on." msgstr "" "В общем случае, все операционные системы, поддерживающие сокеты, " "поддерживают также и B() можно применять для " "переносимого и эффективного решения многих задач, вместо которого многие " "программисты пытаются использовать нити, ветвление процессов, IPC, сигналы, " "разделение памяти и другие методы." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "The B(2) system call has the same functionality as B()." msgstr "" "Системный вызов B(2) имеет такую же функциональность, как и " "B()." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "The Linux-specific B(7) API provides an interface that is more " "efficient than B(2) и B(2)." #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "EXAMPLES" msgstr "ПРИМЕРЫ" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "Here is an example that better demonstrates the true utility of " "B(). Программа " "осуществляет перенаправление одного порта TCP в другой. " #. type: Plain text #: archlinux debian-unstable opensuse-tumbleweed #, no-wrap msgid "" "#include Earpa/inet.hE\n" "#include Eerrno.hE\n" "#include Enetinet/in.hE\n" "#include Esignal.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/select.hE\n" "#include Esys/socket.hE\n" "#include Esys/types.hE\n" "#include Eunistd.hE\n" "\\&\n" "static int forward_port;\n" "\\&\n" "#undef max\n" "#define max(x, y) ((x) E (y) ? (x) : (y))\n" "\\&\n" "static int\n" "listen_socket(int listen_port)\n" "{\n" " int lfd;\n" " int yes;\n" " struct sockaddr_in addr;\n" "\\&\n" " lfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (lfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" "\\&\n" " yes = 1;\n" " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" " &yes, sizeof(yes)) == -1)\n" " {\n" " perror(\"setsockopt\");\n" " close(lfd);\n" " return -1;\n" " }\n" "\\&\n" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(listen_port);\n" " addr.sin_family = AF_INET;\n" " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"bind\");\n" " close(lfd);\n" " return -1;\n" " }\n" "\\&\n" " printf(\"accepting connections on port %d\\en\", listen_port);\n" " listen(lfd, 10);\n" " return lfd;\n" "}\n" "\\&\n" "static int\n" "connect_socket(int connect_port, char *address)\n" "{\n" " int cfd;\n" " struct sockaddr_in addr;\n" "\\&\n" " cfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (cfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" "\\&\n" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(connect_port);\n" " addr.sin_family = AF_INET;\n" "\\&\n" " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" " fprintf(stderr, \"inet_aton(): bad IP address format\\en\");\n" " close(cfd);\n" " return -1;\n" " }\n" "\\&\n" " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"connect()\");\n" " shutdown(cfd, SHUT_RDWR);\n" " close(cfd);\n" " return -1;\n" " }\n" " return cfd;\n" "}\n" "\\&\n" "#define SHUT_FD1 do { \\e\n" " if (fd1 E= 0) { \\e\n" " shutdown(fd1, SHUT_RDWR); \\e\n" " close(fd1); \\e\n" " fd1 = -1; \\e\n" " } \\e\n" " } while (0)\n" "\\&\n" "#define SHUT_FD2 do { \\e\n" " if (fd2 E= 0) { \\e\n" " shutdown(fd2, SHUT_RDWR); \\e\n" " close(fd2); \\e\n" " fd2 = -1; \\e\n" " } \\e\n" " } while (0)\n" "\\&\n" "#define BUF_SIZE 1024\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int h;\n" " int ready, nfds;\n" " int fd1 = -1, fd2 = -1;\n" " int buf1_avail = 0, buf1_written = 0;\n" " int buf2_avail = 0, buf2_written = 0;\n" " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" " fd_set readfds, writefds, exceptfds;\n" " ssize_t nbytes;\n" "\\&\n" " if (argc != 4) {\n" " fprintf(stderr, \"Usage\\en\\etfwd Elisten-portE \"\n" " \"Eforward-to-portE Eforward-to-ip-addressE\\en\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " signal(SIGPIPE, SIG_IGN);\n" "\\&\n" " forward_port = atoi(argv[2]);\n" "\\&\n" " h = listen_socket(atoi(argv[1]));\n" " if (h == -1)\n" " exit(EXIT_FAILURE);\n" "\\&\n" " for (;;) {\n" " nfds = 0;\n" "\\&\n" " FD_ZERO(&readfds);\n" " FD_ZERO(&writefds);\n" " FD_ZERO(&exceptfds);\n" " FD_SET(h, &readfds);\n" " nfds = max(nfds, h);\n" "\\&\n" " if (fd1 E 0 && buf1_avail E BUF_SIZE)\n" " FD_SET(fd1, &readfds);\n" " /* Note: nfds is updated below, when fd1 is added to\n" " exceptfds. */\n" " if (fd2 E 0 && buf2_avail E BUF_SIZE)\n" " FD_SET(fd2, &readfds);\n" "\\&\n" " if (fd1 E 0 && buf2_avail - buf2_written E 0)\n" " FD_SET(fd1, &writefds);\n" " if (fd2 E 0 && buf1_avail - buf1_written E 0)\n" " FD_SET(fd2, &writefds);\n" "\\&\n" " if (fd1 E 0) {\n" " FD_SET(fd1, &exceptfds);\n" " nfds = max(nfds, fd1);\n" " }\n" " if (fd2 E 0) {\n" " FD_SET(fd2, &exceptfds);\n" " nfds = max(nfds, fd2);\n" " }\n" "\\&\n" " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" "\\&\n" " if (ready == -1 && errno == EINTR)\n" " continue;\n" "\\&\n" " if (ready == -1) {\n" " perror(\"select()\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " if (FD_ISSET(h, &readfds)) {\n" " socklen_t addrlen;\n" " struct sockaddr_in client_addr;\n" " int fd;\n" "\\&\n" " addrlen = sizeof(client_addr);\n" " memset(&client_addr, 0, addrlen);\n" " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" " if (fd == -1) {\n" " perror(\"accept()\");\n" " } else {\n" " SHUT_FD1;\n" " SHUT_FD2;\n" " buf1_avail = buf1_written = 0;\n" " buf2_avail = buf2_written = 0;\n" " fd1 = fd;\n" " fd2 = connect_socket(forward_port, argv[3]);\n" " if (fd2 == -1)\n" " SHUT_FD1;\n" " else\n" " printf(\"connect from %s\\en\",\n" " inet_ntoa(client_addr.sin_addr));\n" "\\&\n" " /* Skip any events on the old, closed file\n" " descriptors. */\n" "\\&\n" " continue;\n" " }\n" " }\n" "\\&\n" " /* NB: read OOB data before normal reads. */\n" "\\&\n" " if (fd1 E 0 && FD_ISSET(fd1, &exceptfds)) {\n" " char c;\n" "\\&\n" " nbytes = recv(fd1, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " send(fd2, &c, 1, MSG_OOB);\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &exceptfds)) {\n" " char c;\n" "\\&\n" " nbytes = recv(fd2, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " send(fd1, &c, 1, MSG_OOB);\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &readfds)) {\n" " nbytes = read(fd1, buf1 + buf1_avail,\n" " BUF_SIZE - buf1_avail);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf1_avail += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &readfds)) {\n" " nbytes = read(fd2, buf2 + buf2_avail,\n" " BUF_SIZE - buf2_avail);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf2_avail += nbytes;\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &writefds) && buf2_avail E 0) {\n" " nbytes = write(fd1, buf2 + buf2_written,\n" " buf2_avail - buf2_written);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf2_written += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &writefds) && buf1_avail E 0) {\n" " nbytes = write(fd2, buf1 + buf1_written,\n" " buf1_avail - buf1_written);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf1_written += nbytes;\n" " }\n" "\\&\n" " /* Check if write data has caught read data. */\n" "\\&\n" " if (buf1_written == buf1_avail)\n" " buf1_written = buf1_avail = 0;\n" " if (buf2_written == buf2_avail)\n" " buf2_written = buf2_avail = 0;\n" "\\&\n" " /* One side has closed the connection, keep\n" " writing to the other side until empty. */\n" "\\&\n" " if (fd1 E 0 && buf1_avail - buf1_written == 0)\n" " SHUT_FD2;\n" " if (fd2 E 0 && buf2_avail - buf2_written == 0)\n" " SHUT_FD1;\n" " }\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "The above program properly forwards most kinds of TCP connections including " "OOB signal data transmitted by B servers. It handles the tricky " "problem of having data flow in both directions simultaneously. You might " "think it more efficient to use a B(2) call and devote a thread to " "each stream. This becomes more tricky than you might suspect. Another idea " "is to set nonblocking I/O using B(2). This also has its problems " "because you end up using inefficient timeouts." msgstr "" "Вышеприведенная программа правильно перенаправляет большинство данных задач, " "использующих соединения TCP, включая внепоточные (OOB) данные, передаваемые " "серверами B. Она справляется со сложной проблемой поддержания " "одновременного двустороннего обмена данными. Возможно, вы решите, что " "эффективнее использовать B(2) и выделить отдельную нить для каждого " "потока. На самом деле это сложнее, чем кажется. Другой идеей может быть " "использование неблокирующего ввода-вывода с помощью B(2). Это также " "может вызвать проблемы из-за того, что придётся использовать неэффективные " "таймауты." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, fuzzy #| msgid "" #| "The program does not handle more than one simultaneous connection at a " #| "time, although it could easily be extended to do this with a linked list " #| "of buffers\\(emone for each connection. At the moment, new connections " #| "cause the current connection to be dropped." msgid "" "The program does not handle more than one simultaneous connection at a time, " "although it could easily be extended to do this with a linked list of buffers" "\\[em]one for each connection. At the moment, new connections cause the " "current connection to be dropped." msgstr "" "Программа не обрабатывает более одного соединения, однако она может быть " "легко доработана путем добавления связанного списка буферов — по одному на " "каждое соединение. В данный момент новые соединения приводят к закрытию " "текущего." #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "SEE ALSO" msgstr "СМОТРИТЕ ТАКЖЕ" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "B(2), B(2), B(2), B(2), B(2), " "B(2), B(2), B(2), B(2), B(7)" #. type: TH #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "2023-02-05" msgstr "5 февраля 2023 г." #. type: TH #: debian-bookworm #, no-wrap msgid "Linux man-pages 6.03" msgstr "Linux man-pages 6.03" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "static volatile sig_atomic_t got_SIGCHLD = 0;\n" msgstr "static volatile sig_atomic_t got_SIGCHLD = 0;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "static void\n" "child_sig_handler(int sig)\n" "{\n" " got_SIGCHLD = 1;\n" "}\n" msgstr "" "static void\n" "child_sig_handler(int sig)\n" "{\n" " got_SIGCHLD = 1;\n" "}\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "int\n" "main(int argc, char *argv[])\n" "{\n" " sigset_t sigmask, empty_mask;\n" " struct sigaction sa;\n" " fd_set readfds, writefds, exceptfds;\n" " int r;\n" msgstr "" "int\n" "main(int argc, char *argv[])\n" "{\n" " sigset_t sigmask, empty_mask;\n" " struct sigaction sa;\n" " fd_set readfds, writefds, exceptfds;\n" " int r;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " sigemptyset(&sigmask);\n" " sigaddset(&sigmask, SIGCHLD);\n" " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" " perror(\"sigprocmask\");\n" " exit(EXIT_FAILURE);\n" " }\n" msgstr "" " sigemptyset(&sigmask);\n" " sigaddset(&sigmask, SIGCHLD);\n" " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" " perror(\"sigprocmask\");\n" " exit(EXIT_FAILURE);\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " sa.sa_flags = 0;\n" " sa.sa_handler = child_sig_handler;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" " perror(\"sigaction\");\n" " exit(EXIT_FAILURE);\n" " }\n" msgstr "" " sa.sa_flags = 0;\n" " sa.sa_handler = child_sig_handler;\n" " sigemptyset(&sa.sa_mask);\n" " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" " perror(\"sigaction\");\n" " exit(EXIT_FAILURE);\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid " sigemptyset(&empty_mask);\n" msgstr " sigemptyset(&empty_mask);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " for (;;) { /* main loop */\n" " /* Initialize readfds, writefds, and exceptfds\n" " before the pselect() call. (Code omitted.) */\n" msgstr "" " for (;;) { /* главный цикл */\n" " /* Инициализация readfds, writefds и exceptfds\n" " до вызова pselect() (код не показан). */\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" " NULL, &empty_mask);\n" " if (r == -1 && errno != EINTR) {\n" " /* Handle error */\n" " }\n" msgstr "" " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" " NULL, &empty_mask);\n" " if (r == -1 && errno != EINTR) {\n" " /* обработка ошибки */\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (got_SIGCHLD) {\n" " got_SIGCHLD = 0;\n" msgstr "" " if (got_SIGCHLD) {\n" " got_SIGCHLD = 0;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " /* Handle signalled event here; e.g., wait() for all\n" " terminated children. (Code omitted.) */\n" " }\n" msgstr "" " /* Здесь обработка сигнального события; например с\n" " помощью wait() для завершения потомком (код не показан). */\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " /* main body of program */\n" " }\n" "}\n" msgstr "" " /* код основной программы */\n" " }\n" "}\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "#include Earpa/inet.hE\n" "#include Eerrno.hE\n" "#include Enetinet/in.hE\n" "#include Esignal.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/select.hE\n" "#include Esys/socket.hE\n" "#include Eunistd.hE\n" msgstr "" "#include Earpa/inet.hE\n" "#include Eerrno.hE\n" "#include Enetinet/in.hE\n" "#include Esignal.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/select.hE\n" "#include Esys/socket.hE\n" "#include Eunistd.hE\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "static int forward_port;\n" msgstr "static int forward_port;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "#undef max\n" "#define max(x, y) ((x) E (y) ? (x) : (y))\n" msgstr "" "#undef max\n" "#define max(x, y) ((x) E (y) ? (x) : (y))\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "static int\n" "listen_socket(int listen_port)\n" "{\n" " int lfd;\n" " int yes;\n" " struct sockaddr_in addr;\n" msgstr "" "static int\n" "listen_socket(int listen_port)\n" "{\n" " int lfd;\n" " int yes;\n" " struct sockaddr_in addr;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " lfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (lfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" msgstr "" " lfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (lfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " yes = 1;\n" " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" " &yes, sizeof(yes)) == -1)\n" " {\n" " perror(\"setsockopt\");\n" " close(lfd);\n" " return -1;\n" " }\n" msgstr "" " yes = 1;\n" " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" " &yes, sizeof(yes)) == -1)\n" " {\n" " perror(\"setsockopt\");\n" " close(lfd);\n" " return -1;\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(listen_port);\n" " addr.sin_family = AF_INET;\n" " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"bind\");\n" " close(lfd);\n" " return -1;\n" " }\n" msgstr "" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(listen_port);\n" " addr.sin_family = AF_INET;\n" " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"bind\");\n" " close(lfd);\n" " return -1;\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " printf(\"accepting connections on port %d\\en\", listen_port);\n" " listen(lfd, 10);\n" " return lfd;\n" "}\n" msgstr "" " printf(\"приём соединений на порту %d\\en\", listen_port);\n" " listen(lfd, 10);\n" " return lfd;\n" "}\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "static int\n" "connect_socket(int connect_port, char *address)\n" "{\n" " int cfd;\n" " struct sockaddr_in addr;\n" msgstr "" "static int\n" "connect_socket(int connect_port, char *address)\n" "{\n" " int cfd;\n" " struct sockaddr_in addr;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " cfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (cfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" msgstr "" " cfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (cfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(connect_port);\n" " addr.sin_family = AF_INET;\n" msgstr "" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(connect_port);\n" " addr.sin_family = AF_INET;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" " fprintf(stderr, \"inet_aton(): bad IP address format\\en\");\n" " close(cfd);\n" " return -1;\n" " }\n" msgstr "" " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" " fprintf(stderr, \"inet_aton(): неправильный формат IP-адреса\\en\");\n" " close(cfd);\n" " return -1;\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"connect()\");\n" " shutdown(cfd, SHUT_RDWR);\n" " close(cfd);\n" " return -1;\n" " }\n" " return cfd;\n" "}\n" msgstr "" " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"connect()\");\n" " shutdown(cfd, SHUT_RDWR);\n" " close(cfd);\n" " return -1;\n" " }\n" " return cfd;\n" "}\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "#define SHUT_FD1 do { \\e\n" " if (fd1 E= 0) { \\e\n" " shutdown(fd1, SHUT_RDWR); \\e\n" " close(fd1); \\e\n" " fd1 = -1; \\e\n" " } \\e\n" " } while (0)\n" msgstr "" "#define SHUT_FD1 do { \\e\n" " if (fd1 E= 0) { \\e\n" " shutdown(fd1, SHUT_RDWR); \\e\n" " close(fd1); \\e\n" " fd1 = -1; \\e\n" " } \\e\n" " } while (0)\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "#define SHUT_FD2 do { \\e\n" " if (fd2 E= 0) { \\e\n" " shutdown(fd2, SHUT_RDWR); \\e\n" " close(fd2); \\e\n" " fd2 = -1; \\e\n" " } \\e\n" " } while (0)\n" msgstr "" "#define SHUT_FD2 do { \\e\n" " if (fd2 E= 0) { \\e\n" " shutdown(fd2, SHUT_RDWR); \\e\n" " close(fd2); \\e\n" " fd2 = -1; \\e\n" " } \\e\n" " } while (0)\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "#define BUF_SIZE 1024\n" msgstr "#define BUF_SIZE 1024\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" "int\n" "main(int argc, char *argv[])\n" "{\n" " int h;\n" " int ready, nfds;\n" " int fd1 = -1, fd2 = -1;\n" " int buf1_avail = 0, buf1_written = 0;\n" " int buf2_avail = 0, buf2_written = 0;\n" " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" " fd_set readfds, writefds, exceptfds;\n" " ssize_t nbytes;\n" msgstr "" "int\n" "main(int argc, char *argv[])\n" "{\n" " int h;\n" " int ready, nfds;\n" " int fd1 = -1, fd2 = -1;\n" " int buf1_avail = 0, buf1_written = 0;\n" " int buf2_avail = 0, buf2_written = 0;\n" " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" " fd_set readfds, writefds, exceptfds;\n" " ssize_t nbytes;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (argc != 4) {\n" " fprintf(stderr, \"Usage\\en\\etfwd Elisten-portE \"\n" " \"Eforward-to-portE Eforward-to-ip-addressE\\en\");\n" " exit(EXIT_FAILURE);\n" " }\n" msgstr "" " if (argc != 4) {\n" " fprintf(stderr, \"Использование\\en\\etfwd Eпрослушиваемый-портE \"\n" " \"Eпорт-перенаправленияE Eip-адрес-перенаправленияE\\en\");\n" " exit(EXIT_FAILURE);\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid " signal(SIGPIPE, SIG_IGN);\n" msgstr " signal(SIGPIPE, SIG_IGN);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid " forward_port = atoi(argv[2]);\n" msgstr " forward_port = atoi(argv[2]);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " h = listen_socket(atoi(argv[1]));\n" " if (h == -1)\n" " exit(EXIT_FAILURE);\n" msgstr "" " h = listen_socket(atoi(argv[1]));\n" " if (h == -1)\n" " exit(EXIT_FAILURE);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " for (;;) {\n" " nfds = 0;\n" msgstr "" " for (;;) {\n" " nfds = 0;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " FD_ZERO(&readfds);\n" " FD_ZERO(&writefds);\n" " FD_ZERO(&exceptfds);\n" " FD_SET(h, &readfds);\n" " nfds = max(nfds, h);\n" msgstr "" " FD_ZERO(&readfds);\n" " FD_ZERO(&writefds);\n" " FD_ZERO(&exceptfds);\n" " FD_SET(h, &readfds);\n" " nfds = max(nfds, h);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (fd1 E 0 && buf1_avail E BUF_SIZE)\n" " FD_SET(fd1, &readfds);\n" " /* Note: nfds is updated below, when fd1 is added to\n" " exceptfds. */\n" " if (fd2 E 0 && buf2_avail E BUF_SIZE)\n" " FD_SET(fd2, &readfds);\n" msgstr "" " if (fd1 E 0 && buf1_avail E BUF_SIZE)\n" " FD_SET(fd1, &readfds);\n" " /* Замечание: nfds обновляется ниже, когда добавляется fd1\n" " в exceptfds. */\n" " if (fd2 E 0 && buf2_avail E BUF_SIZE)\n" " FD_SET(fd2, &readfds);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (fd1 E 0 && buf2_avail - buf2_written E 0)\n" " FD_SET(fd1, &writefds);\n" " if (fd2 E 0 && buf1_avail - buf1_written E 0)\n" " FD_SET(fd2, &writefds);\n" msgstr "" " if (fd1 E 0 && buf2_avail - buf2_written E 0)\n" " FD_SET(fd1, &writefds);\n" " if (fd2 E 0 && buf1_avail - buf1_written E 0)\n" " FD_SET(fd2, &writefds);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (fd1 E 0) {\n" " FD_SET(fd1, &exceptfds);\n" " nfds = max(nfds, fd1);\n" " }\n" " if (fd2 E 0) {\n" " FD_SET(fd2, &exceptfds);\n" " nfds = max(nfds, fd2);\n" " }\n" msgstr "" " if (fd1 E 0) {\n" " FD_SET(fd1, &exceptfds);\n" " nfds = max(nfds, fd1);\n" " }\n" " if (fd2 E 0) {\n" " FD_SET(fd2, &exceptfds);\n" " nfds = max(nfds, fd2);\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" msgstr " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (ready == -1 && errno == EINTR)\n" " continue;\n" msgstr "" " if (ready == -1 && errno == EINTR)\n" " continue;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (ready == -1) {\n" " perror(\"select()\");\n" " exit(EXIT_FAILURE);\n" " }\n" msgstr "" " if (ready == -1) {\n" " perror(\"select()\");\n" " exit(EXIT_FAILURE);\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (FD_ISSET(h, &readfds)) {\n" " socklen_t addrlen;\n" " struct sockaddr_in client_addr;\n" " int fd;\n" msgstr "" " if (FD_ISSET(h, &readfds)) {\n" " socklen_t addrlen;\n" " struct sockaddr_in client_addr;\n" " int fd;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " addrlen = sizeof(client_addr);\n" " memset(&client_addr, 0, addrlen);\n" " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" " if (fd == -1) {\n" " perror(\"accept()\");\n" " } else {\n" " SHUT_FD1;\n" " SHUT_FD2;\n" " buf1_avail = buf1_written = 0;\n" " buf2_avail = buf2_written = 0;\n" " fd1 = fd;\n" " fd2 = connect_socket(forward_port, argv[3]);\n" " if (fd2 == -1)\n" " SHUT_FD1;\n" " else\n" " printf(\"connect from %s\\en\",\n" " inet_ntoa(client_addr.sin_addr));\n" msgstr "" " addrlen = sizeof(client_addr);\n" " memset(&client_addr, 0, addrlen);\n" " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" " if (fd == -1) {\n" " perror(\"accept()\");\n" " } else {\n" " SHUT_FD1;\n" " SHUT_FD2;\n" " buf1_avail = buf1_written = 0;\n" " buf2_avail = buf2_written = 0;\n" " fd1 = fd;\n" " fd2 = connect_socket(forward_port, argv[3]);\n" " if (fd2 == -1)\n" " SHUT_FD1;\n" " else\n" " printf(\"connect from %s\\en\",\n" " inet_ntoa(client_addr.sin_addr));\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " /* Skip any events on the old, closed file\n" " descriptors. */\n" msgstr "" " /* пропускаем все события для старых, закрытых\n" " файловых дескрипторов */\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " continue;\n" " }\n" " }\n" msgstr "" " continue;\n" " }\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid " /* NB: read OOB data before normal reads. */\n" msgstr " /* Замечание: чтение данных OOB до обычных. */\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (fd1 E 0 && FD_ISSET(fd1, &exceptfds)) {\n" " char c;\n" msgstr "" " if (fd1 E 0 && FD_ISSET(fd1, &exceptfds)) {\n" " char c;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " nbytes = recv(fd1, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " send(fd2, &c, 1, MSG_OOB);\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &exceptfds)) {\n" " char c;\n" msgstr "" " nbytes = recv(fd1, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " send(fd2, &c, 1, MSG_OOB);\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &exceptfds)) {\n" " char c;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " nbytes = recv(fd2, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " send(fd1, &c, 1, MSG_OOB);\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &readfds)) {\n" " nbytes = read(fd1, buf1 + buf1_avail,\n" " BUF_SIZE - buf1_avail);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf1_avail += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &readfds)) {\n" " nbytes = read(fd2, buf2 + buf2_avail,\n" " BUF_SIZE - buf2_avail);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf2_avail += nbytes;\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &writefds) && buf2_avail E 0) {\n" " nbytes = write(fd1, buf2 + buf2_written,\n" " buf2_avail - buf2_written);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf2_written += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &writefds) && buf1_avail E 0) {\n" " nbytes = write(fd2, buf1 + buf1_written,\n" " buf1_avail - buf1_written);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf1_written += nbytes;\n" " }\n" msgstr "" " nbytes = recv(fd2, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " send(fd1, &c, 1, MSG_OOB);\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &readfds)) {\n" " nbytes = read(fd1, buf1 + buf1_avail,\n" " BUF_SIZE - buf1_avail);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf1_avail += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &readfds)) {\n" " nbytes = read(fd2, buf2 + buf2_avail,\n" " BUF_SIZE - buf2_avail);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf2_avail += nbytes;\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &writefds) && buf2_avail E 0) {\n" " nbytes = write(fd1, buf2 + buf2_written,\n" " buf2_avail - buf2_written);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf2_written += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &writefds) && buf1_avail E 0) {\n" " nbytes = write(fd2, buf1 + buf1_written,\n" " buf1_avail - buf1_written);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf1_written += nbytes;\n" " }\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid " /* Check if write data has caught read data. */\n" msgstr " /* Проверить, что записанные данные были прочитаны. */\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (buf1_written == buf1_avail)\n" " buf1_written = buf1_avail = 0;\n" " if (buf2_written == buf2_avail)\n" " buf2_written = buf2_avail = 0;\n" msgstr "" " if (buf1_written == buf1_avail)\n" " buf1_written = buf1_avail = 0;\n" " if (buf2_written == buf2_avail)\n" " buf2_written = buf2_avail = 0;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " /* One side has closed the connection, keep\n" " writing to the other side until empty. */\n" msgstr "" " /* Одна из сторон закрыла соединение, продолжать\n" " записывать, пока другая сторона не закончит. */\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " if (fd1 E 0 && buf1_avail - buf1_written == 0)\n" " SHUT_FD2;\n" " if (fd2 E 0 && buf2_avail - buf2_written == 0)\n" " SHUT_FD1;\n" " }\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" " if (fd1 E 0 && buf1_avail - buf1_written == 0)\n" " SHUT_FD2;\n" " if (fd2 E 0 && buf2_avail - buf2_written == 0)\n" " SHUT_FD1;\n" " }\n" " exit(EXIT_SUCCESS);\n" "}\n" #. type: TH #: fedora-40 fedora-rawhide mageia-cauldron #, no-wrap msgid "2023-10-31" msgstr "31 октября 2023 г." #. type: TH #: fedora-40 mageia-cauldron #, no-wrap msgid "Linux man-pages 6.06" msgstr "Linux man-pages 6.06" #. type: Plain text #: fedora-40 fedora-rawhide mageia-cauldron #, no-wrap msgid "" "#include Earpa/inet.hE\n" "#include Eerrno.hE\n" "#include Enetinet/in.hE\n" "#include Esignal.hE\n" "#include Estdio.hE\n" "#include Estdlib.hE\n" "#include Estring.hE\n" "#include Esys/select.hE\n" "#include Esys/socket.hE\n" "#include Eunistd.hE\n" "\\&\n" "static int forward_port;\n" "\\&\n" "#undef max\n" "#define max(x, y) ((x) E (y) ? (x) : (y))\n" "\\&\n" "static int\n" "listen_socket(int listen_port)\n" "{\n" " int lfd;\n" " int yes;\n" " struct sockaddr_in addr;\n" "\\&\n" " lfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (lfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" "\\&\n" " yes = 1;\n" " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" " &yes, sizeof(yes)) == -1)\n" " {\n" " perror(\"setsockopt\");\n" " close(lfd);\n" " return -1;\n" " }\n" "\\&\n" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(listen_port);\n" " addr.sin_family = AF_INET;\n" " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"bind\");\n" " close(lfd);\n" " return -1;\n" " }\n" "\\&\n" " printf(\"accepting connections on port %d\\en\", listen_port);\n" " listen(lfd, 10);\n" " return lfd;\n" "}\n" "\\&\n" "static int\n" "connect_socket(int connect_port, char *address)\n" "{\n" " int cfd;\n" " struct sockaddr_in addr;\n" "\\&\n" " cfd = socket(AF_INET, SOCK_STREAM, 0);\n" " if (cfd == -1) {\n" " perror(\"socket\");\n" " return -1;\n" " }\n" "\\&\n" " memset(&addr, 0, sizeof(addr));\n" " addr.sin_port = htons(connect_port);\n" " addr.sin_family = AF_INET;\n" "\\&\n" " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" " fprintf(stderr, \"inet_aton(): bad IP address format\\en\");\n" " close(cfd);\n" " return -1;\n" " }\n" "\\&\n" " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" " perror(\"connect()\");\n" " shutdown(cfd, SHUT_RDWR);\n" " close(cfd);\n" " return -1;\n" " }\n" " return cfd;\n" "}\n" "\\&\n" "#define SHUT_FD1 do { \\e\n" " if (fd1 E= 0) { \\e\n" " shutdown(fd1, SHUT_RDWR); \\e\n" " close(fd1); \\e\n" " fd1 = -1; \\e\n" " } \\e\n" " } while (0)\n" "\\&\n" "#define SHUT_FD2 do { \\e\n" " if (fd2 E= 0) { \\e\n" " shutdown(fd2, SHUT_RDWR); \\e\n" " close(fd2); \\e\n" " fd2 = -1; \\e\n" " } \\e\n" " } while (0)\n" "\\&\n" "#define BUF_SIZE 1024\n" "\\&\n" "int\n" "main(int argc, char *argv[])\n" "{\n" " int h;\n" " int ready, nfds;\n" " int fd1 = -1, fd2 = -1;\n" " int buf1_avail = 0, buf1_written = 0;\n" " int buf2_avail = 0, buf2_written = 0;\n" " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" " fd_set readfds, writefds, exceptfds;\n" " ssize_t nbytes;\n" "\\&\n" " if (argc != 4) {\n" " fprintf(stderr, \"Usage\\en\\etfwd Elisten-portE \"\n" " \"Eforward-to-portE Eforward-to-ip-addressE\\en\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " signal(SIGPIPE, SIG_IGN);\n" "\\&\n" " forward_port = atoi(argv[2]);\n" "\\&\n" " h = listen_socket(atoi(argv[1]));\n" " if (h == -1)\n" " exit(EXIT_FAILURE);\n" "\\&\n" " for (;;) {\n" " nfds = 0;\n" "\\&\n" " FD_ZERO(&readfds);\n" " FD_ZERO(&writefds);\n" " FD_ZERO(&exceptfds);\n" " FD_SET(h, &readfds);\n" " nfds = max(nfds, h);\n" "\\&\n" " if (fd1 E 0 && buf1_avail E BUF_SIZE)\n" " FD_SET(fd1, &readfds);\n" " /* Note: nfds is updated below, when fd1 is added to\n" " exceptfds. */\n" " if (fd2 E 0 && buf2_avail E BUF_SIZE)\n" " FD_SET(fd2, &readfds);\n" "\\&\n" " if (fd1 E 0 && buf2_avail - buf2_written E 0)\n" " FD_SET(fd1, &writefds);\n" " if (fd2 E 0 && buf1_avail - buf1_written E 0)\n" " FD_SET(fd2, &writefds);\n" "\\&\n" " if (fd1 E 0) {\n" " FD_SET(fd1, &exceptfds);\n" " nfds = max(nfds, fd1);\n" " }\n" " if (fd2 E 0) {\n" " FD_SET(fd2, &exceptfds);\n" " nfds = max(nfds, fd2);\n" " }\n" "\\&\n" " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" "\\&\n" " if (ready == -1 && errno == EINTR)\n" " continue;\n" "\\&\n" " if (ready == -1) {\n" " perror(\"select()\");\n" " exit(EXIT_FAILURE);\n" " }\n" "\\&\n" " if (FD_ISSET(h, &readfds)) {\n" " socklen_t addrlen;\n" " struct sockaddr_in client_addr;\n" " int fd;\n" "\\&\n" " addrlen = sizeof(client_addr);\n" " memset(&client_addr, 0, addrlen);\n" " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" " if (fd == -1) {\n" " perror(\"accept()\");\n" " } else {\n" " SHUT_FD1;\n" " SHUT_FD2;\n" " buf1_avail = buf1_written = 0;\n" " buf2_avail = buf2_written = 0;\n" " fd1 = fd;\n" " fd2 = connect_socket(forward_port, argv[3]);\n" " if (fd2 == -1)\n" " SHUT_FD1;\n" " else\n" " printf(\"connect from %s\\en\",\n" " inet_ntoa(client_addr.sin_addr));\n" "\\&\n" " /* Skip any events on the old, closed file\n" " descriptors. */\n" "\\&\n" " continue;\n" " }\n" " }\n" "\\&\n" " /* NB: read OOB data before normal reads. */\n" "\\&\n" " if (fd1 E 0 && FD_ISSET(fd1, &exceptfds)) {\n" " char c;\n" "\\&\n" " nbytes = recv(fd1, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " send(fd2, &c, 1, MSG_OOB);\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &exceptfds)) {\n" " char c;\n" "\\&\n" " nbytes = recv(fd2, &c, 1, MSG_OOB);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " send(fd1, &c, 1, MSG_OOB);\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &readfds)) {\n" " nbytes = read(fd1, buf1 + buf1_avail,\n" " BUF_SIZE - buf1_avail);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf1_avail += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &readfds)) {\n" " nbytes = read(fd2, buf2 + buf2_avail,\n" " BUF_SIZE - buf2_avail);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf2_avail += nbytes;\n" " }\n" " if (fd1 E 0 && FD_ISSET(fd1, &writefds) && buf2_avail E 0) {\n" " nbytes = write(fd1, buf2 + buf2_written,\n" " buf2_avail - buf2_written);\n" " if (nbytes E 1)\n" " SHUT_FD1;\n" " else\n" " buf2_written += nbytes;\n" " }\n" " if (fd2 E 0 && FD_ISSET(fd2, &writefds) && buf1_avail E 0) {\n" " nbytes = write(fd2, buf1 + buf1_written,\n" " buf1_avail - buf1_written);\n" " if (nbytes E 1)\n" " SHUT_FD2;\n" " else\n" " buf1_written += nbytes;\n" " }\n" "\\&\n" " /* Check if write data has caught read data. */\n" "\\&\n" " if (buf1_written == buf1_avail)\n" " buf1_written = buf1_avail = 0;\n" " if (buf2_written == buf2_avail)\n" " buf2_written = buf2_avail = 0;\n" "\\&\n" " /* One side has closed the connection, keep\n" " writing to the other side until empty. */\n" "\\&\n" " if (fd1 E 0 && buf1_avail - buf1_written == 0)\n" " SHUT_FD2;\n" " if (fd2 E 0 && buf2_avail - buf2_written == 0)\n" " SHUT_FD1;\n" " }\n" " exit(EXIT_SUCCESS);\n" "}\n" msgstr "" #. type: TH #: fedora-rawhide #, no-wrap msgid "Linux man-pages 6.7" msgstr "Linux man-pages 6.7" #. type: TH #: opensuse-leap-15-6 #, no-wrap msgid "Linux man-pages 6.04" msgstr "Linux man-pages 6.04" #. type: TH #: opensuse-tumbleweed #, fuzzy, no-wrap #| msgid "Linux man-pages 6.7" msgid "Linux man-pages (unreleased)" msgstr "Linux man-pages 6.7"