# Spanish translation of manpages # This file is distributed under the same license as the manpages-l10n package. # Copyright © of this file: # Gerardo Aburruzaga García , 1998. msgid "" msgstr "" "Project-Id-Version: manpages-l10n\n" "POT-Creation-Date: 2024-06-01 06:20+0200\n" "PO-Revision-Date: 2021-02-01 18:58+0100\n" "Last-Translator: Gerardo Aburruzaga García \n" "Language-Team: Spanish \n" "Language: es\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "X-Generator: Lokalize 20.04.1\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 Mayo 2024" #. type: TH #: archlinux debian-unstable #, no-wrap msgid "Linux man-pages 6.8" msgstr "Páginas de Manual de Linux 6.8" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "NAME" msgstr "NOMBRE" #. 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 - multiplexación de E/S síncrona" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "LIBRARY" msgstr "BIBLIOTECA" #. 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 "Biblioteca Estándar C (I, I<-lc>)" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "SYNOPSIS" msgstr "SINOPSIS" #. 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 "DESCRIPCIÓN" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "The 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 B 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 " "(o B) regrese tomando la variable B el valor B. Este " "comportamiento es esencial para que las señales puedan ser procesadas en el " "bucle principal del programa, de otra manera B? La respuesta es que B? Can't I just read and write to my " #| "descriptors whenever I want? The point of select is that it watches " #| "multiple descriptors at the same time and properly puts the process to " #| "sleep if there is no activity. It does this while enabling you to handle " #| "multiple simultaneous pipes and sockets. Unix programmers often find " #| "themselves in a position where they have to handle IO from more than one " #| "file descriptor where the data flow may be intermittent. If you were to " #| "merely create a sequence of B and B calls, you would find " #| "that one of your calls may block waiting for data from/to a file " #| "descriptor, while another file descriptor is unused though available for " #| "data. 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 "" "Por lo tanto, ¿cuál es el propósito de B maneja eficientemente esta situación." #. type: SS #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "Select law" msgstr "" #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, fuzzy #| msgid "" #| "Many people who try to use B, hence I will present a list " #| "of essentials to watch for when using the 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 "" "Muchas personas que intentan usar B, por lo que voy a presentar una lista de los " "aspectos esenciales a tener en cuenta cuando se use la llamada 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 "" "Siempre debe de intentar usar B() call, and respond appropriately. See next " "rule." msgstr "" "No debe añadir a ningún conjunto un descriptor de fichero para el que no " "tenga intención de comprobar su resultado (y responder adecuadamente) tras " "una llamada a B() returns, all file descriptors in all sets should be " "checked to see if they are ready." msgstr "" #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "5." msgstr "5." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed msgid "" "The functions B(2), B(2), B(2), and B(2) do I " "necessarily read/write the full amount of data that you have requested. If " "they do read/write the full amount, it's because you have a low traffic load " "and a fast stream. This is not always going to be the case. You should " "cope with the case of your functions managing to send or receive only a " "single byte." msgstr "" "Las funciones B(), B(), B() y B() I leen/" "escriben necesariamente todos los datos que haya solicitado. Si leen/" "escriben todos los datos es porque tiene poco tráfico y un flujo muy rápido. " "Ese no va a ser siempre el caso. Debe hacer frente al caso en el que sus " "funciones sólo logren enviar o recibir un único byte." #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "6." msgstr "6." #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, fuzzy #| msgid "" #| "Never read/write only in single bytes at a time unless your are really " #| "sure that you have a small amount of data to process. It is extremely " #| "inefficient not to read/write as much data as you can buffer each time. " #| "The buffers in the example above are 1024 bytes although they could " #| "easily be made as large as the maximum possible packet size on your local " #| "network." msgid "" "Never read/write only in single bytes at a time unless you are really sure " "that you have a small amount of data to process. It is extremely " "inefficient not to read/write as much data as you can buffer each time. The " "buffers in the example below are 1024 bytes although they could easily be " "made larger." msgstr "" "Nunca lea/escriba byte a byte a menos que esté realmente seguro de que tiene " "que procesar una pequeña cantidad de datos. Es extremadamente ineficiente no " "leer/escribir cada vez tantos datos como pueda almacenar. Los buffers del " "ejemplo anterior son de 1024 bytes aunque podrían fácilmente hacerse tan " "grandes como el máximo tamaño de paquete posible en su red local." #. type: TP #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "7." msgstr "7." #. Nonetheless, you should still cope with these errors for completeness. #. type: Plain text #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, fuzzy #| msgid "" #| "The functions B, B, B, and B as well as " #| "the B call can return -1 with an errno of B or B " #| "(B) which are not errors. 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 non-blocking IO, you will not get B. " #| "Nonetheless you should still cope with these errors for completeness." msgid "" "Calls to B(2), B(2), B(2), B(2), and B() again. In the example below, I close the file " "descriptor immediately, and then set it to -1 to prevent it being included " "in a set." msgstr "" "Excepto como se indica en B<7.>, las funciones B, B, " "B y B nunca devuelven un valor menor que 1 salvo cuando se " "produce un error. Por ejemplo, un B sobre una tubería donde el otro " "extremo ha muerto devuelve cero (al igual que un error de fin de fichero), " "I devuelve cero sólo una vez (un lectura o escritura posterior " "devolverá -1). Cuando cualquiera de estas funciones devuelva 0 o -1, I pasar el descriptor correspondiente a select nunca más. En el ejemplo " "anterior, cierro el descriptor inmediatamente y le asigno -1 para evitar que " "se vuelva a incluir en un conjunto." #. 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(), ya que algunos sistemas operativos modifican la estructura. " "B(), sin embargo, no modifica su estructura de plazo de tiempo." #. 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(2)." msgstr "Vea B. Some people consider B can be used to solve many problems in a " #| "portable and efficient way that naive programmers try to solve with " #| "threads, forking, IPCs, signals, memory sharing and other dirty methods. " #| "B is a newer function that is less commonly used." 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 "" "Generalmente hablando, todos los sistemas operativos que soportan " "conectores, también soportan B es una función esotérica y raramente usada. De hecho, muchos tipos " "de programas se vuelven extremadamente complicados sin ella. B, but " #| "with less subtle behavior. It is less portable than B(), and " "is somewhat more efficient when monitoring sparse file descriptor sets. It " "is nowadays widely available, but historically was less portable than " "B, pero con un comportamiento menos sutil. Es menos portable que " "B(2) and B(2) when monitoring large numbers " "of file descriptors." msgstr "" #. type: SH #: archlinux debian-bookworm debian-unstable fedora-40 fedora-rawhide #: mageia-cauldron opensuse-leap-15-6 opensuse-tumbleweed #, no-wrap msgid "EXAMPLES" msgstr "EJEMPLOS" #. 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(). El listado de abajo es un programa de reenvío TCP que redirige " "de un puerto TCP a otro." #. 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 #, fuzzy #| 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 call and devote a " #| "thread to each stream. This becomes more tricky than you might suspect. " #| "Another idea is to set non-blocking IO using an B call. This " #| "also has its problems because you end up having to have inefficient " #| "timeouts." 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 "" "El programa anterior reenvía correctamente la mayoría de los tipos de " "conexiones TCP, incluyendo los datos OOB de señal transmitidos por los " "servidores B. También es capaz de manejar el difícil problema de " "tener flujos de datos en ambas direcciones a la vez. Podría pensar que es " "más eficiente hacer una llamada B y dedicar un hilo a cada flujo. " "Esto es más complicado de lo que podría pensar. Otra idea es activar E/S no " "bloqueante haciendo una llamada B. Esto también tiene sus problemas " "ya que acaba teniendo que utilizar plazos de tiempo (I) " "ineficientes." #. 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 "" "El programa no maneja más de una conexión simultánea a la vez, aunque podría " "extenderse fácilmente para hacer esto con una lista ligada de buffers " "\\(emuno para cada conexión. Por ahora, una nueva conexión hace que la " "conexión actual se caiga." #. 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 "VÉASE TAMBIÉN" #. 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 Febrero 2023" #. type: TH #: debian-bookworm #, no-wrap msgid "Linux man-pages 6.03" msgstr "Páginas de Manual de Linux 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 "" #. 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 "" #. 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 "" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " /* main body of program */\n" " }\n" "}\n" msgstr "" " /* cuerpo principal del programa */\n" " }\n" "}\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, fuzzy, no-wrap #| msgid "" #| "#include Estdlib.hE\n" #| "#include Estdio.hE\n" #| "#include Eunistd.hE\n" #| "#include Esys/select.hE\n" #| "#include Estring.hE\n" #| "#include Esignal.hE\n" #| "#include Esys/socket.hE\n" #| "#include Enetinet/in.hE\n" #| "#include Earpa/inet.hE\n" #| "#include Eerrno.hE\n" 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 Estdlib.hE\n" "#include Estdio.hE\n" "#include Eunistd.hE\n" "#include Esys/select.hE\n" "#include Estring.hE\n" "#include Esignal.hE\n" "#include Esys/socket.hE\n" "#include Enetinet/in.hE\n" "#include Earpa/inet.hE\n" "#include Eerrno.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 #, fuzzy, no-wrap #| msgid "" #| "#undef max\n" #| "#define max(x,y) ((x) E (y) ? (x) : (y))\n" 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 #, fuzzy, no-wrap #| msgid "" #| "static int\n" #| "listen_socket(int listen_port)\n" #| "{\n" #| " struct sockaddr_in addr;\n" #| " int lfd;\n" #| " int yes;\n" 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" " struct sockaddr_in addr;\n" " int lfd;\n" " int yes;\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 #, fuzzy, no-wrap #| msgid "" #| " yes = 1;\n" #| " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" #| " &yes, sizeof(yes)) == -1) {\n" #| " perror(\"setsockopt\");\n" #| " close(lfd);\n" #| " return -1;\n" #| " }\n" 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" " 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 "" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, fuzzy, no-wrap #| msgid "" #| "static int\n" #| "connect_socket(int connect_port, char *address)\n" #| "{\n" #| " struct sockaddr_in addr;\n" #| " int cfd;\n" 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" " struct sockaddr_in addr;\n" " int cfd;\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(): formato de dirección IP incorrecto\\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 #, fuzzy, no-wrap #| msgid "" #| "int\n" #| "main(int argc, char *argv[])\n" #| "{\n" #| " int h;\n" #| " int fd1 = -1, fd2 = -1;\n" #| " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" #| " int buf1_avail = 0, buf1_written = 0;\n" #| " int buf2_avail = 0, buf2_written = 0;\n" 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 fd1 = -1, fd2 = -1;\n" " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" " int buf1_avail = 0, buf1_written = 0;\n" " int buf2_avail = 0, buf2_written = 0;\n" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, fuzzy, 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" 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, \"Usage\\en\\etfwd Epuerto-escuchaE \"\n" " \"Eredirigir-a-puertoE Eredirigir-a-dirección-ipE\\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 #, fuzzy, no-wrap #| msgid " for (;;) {\n" msgid "" " for (;;) {\n" " nfds = 0;\n" msgstr " for (;;) {\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 "" #. 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 "" #. type: Plain text #: debian-bookworm opensuse-leap-15-6 #, no-wrap msgid "" " /* Skip any events on the old, closed file\n" " descriptors. */\n" msgstr "" #. 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 "" #. 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 #, fuzzy, 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" 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 "" #. 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 "" #. 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 Octubre 2023" #. type: TH #: fedora-40 mageia-cauldron #, no-wrap msgid "Linux man-pages 6.06" msgstr "Páginas de Manual de Linux 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 "Páginas de Manual de Linux 6.7" #. type: TH #: opensuse-leap-15-6 #, no-wrap msgid "Linux man-pages 6.04" msgstr "Páginas de Manual de Linux 6.04" #. type: TH #: opensuse-tumbleweed #, no-wrap msgid "Linux man-pages (unreleased)" msgstr "Páginas de Manual de Linux (no publicadas)"