| 1 |
# French translation of manpages |
| 2 |
# This file is distributed under the same license as the manpages-l10n package. |
| 3 |
# Copyright © of this file: |
| 4 |
# Christophe Blaess <https://www.blaess.fr/christophe/>, 1996-2003. |
| 5 |
# Stéphan Rafin <[email protected]>, 2002. |
| 6 |
# Thierry Vignaud <[email protected]>, 1999,2002. |
| 7 |
# François Micaux, 2002. |
| 8 |
# Alain Portal <[email protected]>, 2003-2008. |
| 9 |
# Jean-Philippe Guérard <[email protected]>, 2005-2006. |
| 10 |
# Jean-Luc Coulon (f5ibh) <[email protected]>, 2006-2007. |
| 11 |
# Julien Cristau <[email protected]>, 2006-2007. |
| 12 |
# Thomas Huriaux <[email protected]>, 2006-2008. |
| 13 |
# Nicolas François <[email protected]>, 2006-2008. |
| 14 |
# Florentin Duneau <[email protected]>, 2006-2010. |
| 15 |
# Simon Paillard <[email protected]>, 2006, 2013. |
| 16 |
# Denis Barbier <[email protected]>, 2006,2010. |
| 17 |
# David Prévot <[email protected]>, 2010, 2013, 2014. |
| 18 |
# Cédric Boutillier <[email protected]>, 2011, 2012, 2013. |
| 19 |
# Frédéric Hantrais <[email protected]>, 2013, 2014. |
| 20 |
# Jean-Philippe MENGUAL <[email protected]>, 2021-2024. |
| 21 |
msgid "" |
| 22 |
msgstr "" |
| 23 |
"Project-Id-Version: manpages-l10n 4.22.0\n" |
| 24 |
"POT-Creation-Date: 2026-06-05 06:42+0200\n" |
| 25 |
"PO-Revision-Date: 2025-03-09 08:16+0100\n" |
| 26 |
"Last-Translator: Jean-Philippe MENGUAL <[email protected]>\n" |
| 27 |
"Language-Team: French <[email protected]>\n" |
| 28 |
"Language: fr\n" |
| 29 |
"MIME-Version: 1.0\n" |
| 30 |
"Content-Type: text/plain; charset=UTF-8\n" |
| 31 |
"Content-Transfer-Encoding: 8bit\n" |
| 32 |
"Plural-Forms: nplurals=2; plural=n > 1;\n" |
| 33 |
"X-Generator: Lokalize 22.12.3\n" |
| 34 |
|
| 35 |
#. type: TH |
| 36 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 37 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 38 |
#, no-wrap |
| 39 |
msgid "SELECT_TUT" |
| 40 |
msgstr "SELECT_TUT" |
| 41 |
|
| 42 |
#. type: TH |
| 43 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 44 |
#: opensuse-tumbleweed |
| 45 |
#, no-wrap |
| 46 |
msgid "2026-02-08" |
| 47 |
msgstr "8 février 2026" |
| 48 |
|
| 49 |
#. type: TH |
| 50 |
#: archlinux debian-unstable |
| 51 |
#, no-wrap |
| 52 |
msgid "Linux man-pages 6.18" |
| 53 |
msgstr "Pages du manuel de Linux 6.18" |
| 54 |
|
| 55 |
#. type: SH |
| 56 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 57 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 58 |
#, no-wrap |
| 59 |
msgid "NAME" |
| 60 |
msgstr "NOM" |
| 61 |
|
| 62 |
#. type: Plain text |
| 63 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 64 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 65 |
msgid "select, pselect - synchronous I/O multiplexing" |
| 66 |
msgstr "select, pselect - Multiplexage d'entrées-sorties synchrones" |
| 67 |
|
| 68 |
#. type: SH |
| 69 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 70 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 71 |
#, no-wrap |
| 72 |
msgid "LIBRARY" |
| 73 |
msgstr "BIBLIOTHÈQUE" |
| 74 |
|
| 75 |
#. type: Plain text |
| 76 |
#: archlinux debian-unstable fedora-44 fedora-rawhide mageia-cauldron |
| 77 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 78 |
msgid "Standard C library (I<libc>,\\ I<-lc>)" |
| 79 |
msgstr "Bibliothèque C standard (I<libc>,\\ I<-lc>)" |
| 80 |
|
| 81 |
#. type: SH |
| 82 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 83 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 84 |
#, no-wrap |
| 85 |
msgid "SYNOPSIS" |
| 86 |
msgstr "SYNOPSIS" |
| 87 |
|
| 88 |
#. type: Plain text |
| 89 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 90 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 91 |
msgid "See B<select>(2)" |
| 92 |
msgstr "Voir B<select>(2)" |
| 93 |
|
| 94 |
#. type: SH |
| 95 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 96 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 97 |
#, no-wrap |
| 98 |
msgid "DESCRIPTION" |
| 99 |
msgstr "DESCRIPTION" |
| 100 |
|
| 101 |
#. type: Plain text |
| 102 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 103 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 104 |
msgid "" |
| 105 |
"The B<select>() and B<pselect>() system calls are used to efficiently " |
| 106 |
"monitor multiple file descriptors, to see if any of them is, or becomes, " |
| 107 |
"\"ready\"; that is, to see whether I/O becomes possible, or an \"exceptional " |
| 108 |
"condition\" has occurred on any of the file descriptors." |
| 109 |
msgstr "" |
| 110 |
"Les appels système B<select>() et B<pselect>()) sont utilisés pour " |
| 111 |
"superviser efficacement plusieurs descripteurs de fichiers pour vérifier si " |
| 112 |
"l'un d'entre eux est ou devient « prêt » ; c'est-à-dire savoir si des " |
| 113 |
"entrées-sorties deviennent possibles ou si une « condition exceptionnelle » " |
| 114 |
"est survenue sur l'un des descripteurs." |
| 115 |
|
| 116 |
#. type: Plain text |
| 117 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 118 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 119 |
msgid "" |
| 120 |
"This page provides background and tutorial information on the use of these " |
| 121 |
"system calls. For details of the arguments and semantics of B<select>() " |
| 122 |
"and B<pselect>(), see B<select>(2)." |
| 123 |
msgstr "" |
| 124 |
"Cette page fournit des informations de contexte et des tutoriels sur " |
| 125 |
"l'utilisation de ces appels système. Pour des détails sur les paramètres et " |
| 126 |
"la sémantique de B<select>() et de B<pselect>(), voir B<select>(2)." |
| 127 |
|
| 128 |
#. type: SS |
| 129 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 130 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 131 |
#, no-wrap |
| 132 |
msgid "Combining signal and data events" |
| 133 |
msgstr "Combinaison d'événements de signaux et de données" |
| 134 |
|
| 135 |
#. type: Plain text |
| 136 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 137 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 138 |
msgid "" |
| 139 |
"B<pselect>() is useful if you are waiting for a signal as well as for file " |
| 140 |
"descriptor(s) to become ready for I/O. Programs that receive signals " |
| 141 |
"normally use the signal handler only to raise a global flag. The global " |
| 142 |
"flag will indicate that the event must be processed in the main loop of the " |
| 143 |
"program. A signal will cause the B<select>() (or B<pselect>()) call to " |
| 144 |
"return with I<errno> set to B<EINTR>. This behavior is essential so that " |
| 145 |
"signals can be processed in the main loop of the program, otherwise " |
| 146 |
"B<select>() would block indefinitely." |
| 147 |
msgstr "" |
| 148 |
"***B<pselect>() est utile si vous attendez un signal ou qu'un/des " |
| 149 |
"descripteur(s) de fichier deviennent prêts pour des entrées-sorties. Les " |
| 150 |
"programmes qui reçoivent des signaux utilisent généralement le gestionnaire " |
| 151 |
"de signal uniquement pour lever un drapeau global. Le drapeau global indique " |
| 152 |
"que l'événement doit être traité dans la boucle principale du programme. Un " |
| 153 |
"signal provoque l'arrêt de l'appel B<select>() (ou B<pselect>()) avec " |
| 154 |
"I<errno> positionnée à B<EINTR>. Ce comportement est essentiel afin que les " |
| 155 |
"signaux puissent être traités dans la boucle principale du programme, sinon " |
| 156 |
"B<select>() bloquerait indéfiniment." |
| 157 |
|
| 158 |
#. type: Plain text |
| 159 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 160 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 161 |
msgid "" |
| 162 |
"Now, somewhere in the main loop will be a conditional to check the global " |
| 163 |
"flag. So we must ask: what if a signal arrives after the conditional, but " |
| 164 |
"before the B<select>() call? The answer is that B<select>() would block " |
| 165 |
"indefinitely, even though an event is actually pending. This race condition " |
| 166 |
"is solved by the B<pselect>() call. This call can be used to set the " |
| 167 |
"signal mask to a set of signals that are to be received only within the " |
| 168 |
"B<pselect>() call. For instance, let us say that the event in question was " |
| 169 |
"the exit of a child process. Before the start of the main loop, we would " |
| 170 |
"block B<SIGCHLD> using B<sigprocmask>(2). Our B<pselect>() call would " |
| 171 |
"enable B<SIGCHLD> by using an empty signal mask. Our program would look " |
| 172 |
"like:" |
| 173 |
msgstr "" |
| 174 |
"Ceci étant, la boucle principale implante quelque part une condition " |
| 175 |
"vérifiant le drapeau global, et l'on doit donc se demander\\ : que se passe-" |
| 176 |
"t-il si un signal est levé après la condition mais avant l'appel à " |
| 177 |
"B<select>()\\ ? La réponse est que B<select>() bloquerait indéfiniment, même " |
| 178 |
"si un signal était en fait en attente. Cette \"race condition\" est résolue " |
| 179 |
"par l'appel B<pselect>(). Cet appel peut être utilisé afin de définir le " |
| 180 |
"masque des signaux qui sont censés n'être reçus que durant l'appel à " |
| 181 |
"B<pselect>(). Par exemple, supposons que l'événement en question est la fin " |
| 182 |
"d'un processus enfant. Avant le démarrage de la boucle principale, nous " |
| 183 |
"bloquerions B<SIGCHLD> en utilisant B<sigprocmask>(2). Notre appel " |
| 184 |
"B<pselect>() débloquerait B<SIGCHLD> en utilisant le masque de signaux vide. " |
| 185 |
"Le programme ressemblerait à ceci\\ :" |
| 186 |
|
| 187 |
#. type: Plain text |
| 188 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 189 |
#: opensuse-tumbleweed |
| 190 |
#, fuzzy, no-wrap |
| 191 |
#| msgid "" |
| 192 |
#| "static volatile sig_atomic_t got_SIGCHLD = 0;\n" |
| 193 |
#| "\\&\n" |
| 194 |
#| "static void\n" |
| 195 |
#| "child_sig_handler(int sig)\n" |
| 196 |
#| "{\n" |
| 197 |
#| " got_SIGCHLD = 1;\n" |
| 198 |
#| "}\n" |
| 199 |
#| "\\&\n" |
| 200 |
#| "int\n" |
| 201 |
#| "main(int argc, char *argv[])\n" |
| 202 |
#| "{\n" |
| 203 |
#| " sigset_t sigmask, empty_mask;\n" |
| 204 |
#| " struct sigaction sa;\n" |
| 205 |
#| " fd_set readfds, writefds, exceptfds;\n" |
| 206 |
#| " int r;\n" |
| 207 |
#| "\\&\n" |
| 208 |
#| " sigemptyset(&sigmask);\n" |
| 209 |
#| " sigaddset(&sigmask, SIGCHLD);\n" |
| 210 |
#| " if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" |
| 211 |
#| " perror(\"sigprocmask\");\n" |
| 212 |
#| " exit(EXIT_FAILURE);\n" |
| 213 |
#| " }\n" |
| 214 |
#| "\\&\n" |
| 215 |
#| " sa.sa_flags = 0;\n" |
| 216 |
#| " sa.sa_handler = child_sig_handler;\n" |
| 217 |
#| " sigemptyset(&sa.sa_mask);\n" |
| 218 |
#| " if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" |
| 219 |
#| " perror(\"sigaction\");\n" |
| 220 |
#| " exit(EXIT_FAILURE);\n" |
| 221 |
#| " }\n" |
| 222 |
#| "\\&\n" |
| 223 |
#| " sigemptyset(&empty_mask);\n" |
| 224 |
#| "\\&\n" |
| 225 |
#| " for (;;) { /* main loop */\n" |
| 226 |
#| " /* Initialize readfds, writefds, and exceptfds\n" |
| 227 |
#| " before the pselect() call. (Code omitted.) */\n" |
| 228 |
#| "\\&\n" |
| 229 |
#| " r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" |
| 230 |
#| " NULL, &empty_mask);\n" |
| 231 |
#| " if (r == -1 && errno != EINTR) {\n" |
| 232 |
#| " /* Handle error */\n" |
| 233 |
#| " }\n" |
| 234 |
#| "\\&\n" |
| 235 |
#| " if (got_SIGCHLD) {\n" |
| 236 |
#| " got_SIGCHLD = 0;\n" |
| 237 |
#| "\\&\n" |
| 238 |
#| " /* Handle signalled event here; e.g., wait() for all\n" |
| 239 |
#| " terminated children. (Code omitted.) */\n" |
| 240 |
#| " }\n" |
| 241 |
#| "\\&\n" |
| 242 |
#| " /* main body of program */\n" |
| 243 |
#| " }\n" |
| 244 |
#| "}\n" |
| 245 |
msgid "" |
| 246 |
"static volatile sig_atomic_t got_SIGCHLD = 0;\n" |
| 247 |
"\\&\n" |
| 248 |
"static void\n" |
| 249 |
"child_sig_handler(int sig)\n" |
| 250 |
"{\n" |
| 251 |
" got_SIGCHLD = 1;\n" |
| 252 |
"}\n" |
| 253 |
"\\&\n" |
| 254 |
"int\n" |
| 255 |
"main(int argc, char *argv[])\n" |
| 256 |
"{\n" |
| 257 |
" sigset_t sigmask, empty_mask;\n" |
| 258 |
" struct sigaction sa;\n" |
| 259 |
" fd_set readfds, writefds, exceptfds;\n" |
| 260 |
" int r;\n" |
| 261 |
"\\&\n" |
| 262 |
" sigemptyset(&sigmask);\n" |
| 263 |
" sigaddset(&sigmask, SIGCHLD);\n" |
| 264 |
" if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" |
| 265 |
" perror(\"sigprocmask\");\n" |
| 266 |
" exit(EXIT_FAILURE);\n" |
| 267 |
" }\n" |
| 268 |
"\\&\n" |
| 269 |
" sa.sa_flags = 0;\n" |
| 270 |
" sa.sa_handler = child_sig_handler;\n" |
| 271 |
" sigemptyset(&sa.sa_mask);\n" |
| 272 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" |
| 273 |
" perror(\"sigaction\");\n" |
| 274 |
" exit(EXIT_FAILURE);\n" |
| 275 |
" }\n" |
| 276 |
"\\&\n" |
| 277 |
" sigemptyset(&empty_mask);\n" |
| 278 |
"\\&\n" |
| 279 |
" for (;;) { /* main loop */\n" |
| 280 |
" /* Initialize readfds, writefds, and exceptfds\n" |
| 281 |
" before the pselect() call. (Code omitted.) */\n" |
| 282 |
"\\&\n" |
| 283 |
" r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" |
| 284 |
" NULL, &empty_mask);\n" |
| 285 |
" if (r == -1 && errno != EINTR) {\n" |
| 286 |
" /* Handle error */\n" |
| 287 |
" }\n" |
| 288 |
"\\&\n" |
| 289 |
" if (got_SIGCHLD) {\n" |
| 290 |
" got_SIGCHLD = 0;\n" |
| 291 |
"\\&\n" |
| 292 |
" /* Handle signalled event here; e.g., wait() for all\n" |
| 293 |
" terminated children. (Code omitted.) */\n" |
| 294 |
" }\n" |
| 295 |
"\\&\n" |
| 296 |
" /* main body of program */\n" |
| 297 |
" }\n" |
| 298 |
"}\n" |
| 299 |
msgstr "" |
| 300 |
"static volatile sig_atomic_t got_SIGCHLD = 0;\n" |
| 301 |
"\\&\n" |
| 302 |
"static void\n" |
| 303 |
"child_sig_handler(int sig)\n" |
| 304 |
"{\n" |
| 305 |
" got_SIGCHLD = 1;\n" |
| 306 |
"}\n" |
| 307 |
"\\&\n" |
| 308 |
"int\n" |
| 309 |
"main(int argc, char *argv[])\n" |
| 310 |
"{\n" |
| 311 |
" sigset_t sigmask, empty_mask;\n" |
| 312 |
" struct sigaction sa;\n" |
| 313 |
" fd_set readfds, writefds, exceptfds;\n" |
| 314 |
" int r;\n" |
| 315 |
"\\&\n" |
| 316 |
" sigemptyset(&sigmask);\n" |
| 317 |
" sigaddset(&sigmask, SIGCHLD);\n" |
| 318 |
" if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" |
| 319 |
" perror(\"sigprocmask\");\n" |
| 320 |
" exit(EXIT_FAILURE);\n" |
| 321 |
" }\n" |
| 322 |
"\\&\n" |
| 323 |
" sa.sa_flags = 0;\n" |
| 324 |
" sa.sa_handler = child_sig_handler;\n" |
| 325 |
" sigemptyset(&sa.sa_mask);\n" |
| 326 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" |
| 327 |
" perror(\"sigaction\");\n" |
| 328 |
" exit(EXIT_FAILURE);\n" |
| 329 |
" }\n" |
| 330 |
"\\&\n" |
| 331 |
" sigemptyset(&empty_mask);\n" |
| 332 |
"\\&\n" |
| 333 |
" for (;;) { /* main loop */\n" |
| 334 |
" /* Initialiser readfds, writefds et exceptfds\n" |
| 335 |
" avant l'appel à pselect(). (Code omis.) */\n" |
| 336 |
"\\&\n" |
| 337 |
" r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" |
| 338 |
" NULL, &empty_mask);\n" |
| 339 |
" if (r == -1 && errno != EINTR) {\n" |
| 340 |
" /* Handle error */\n" |
| 341 |
" }\n" |
| 342 |
"\\&\n" |
| 343 |
" if (got_SIGCHLD) {\n" |
| 344 |
" got_SIGCHLD = 0;\n" |
| 345 |
"\\&\n" |
| 346 |
" /* Gérer les événements signalés ici; e.g., wait() pour\n" |
| 347 |
" que tous les enfants se terminent. (Code omis.) */\n" |
| 348 |
" }\n" |
| 349 |
"\\&\n" |
| 350 |
" /* corps principal du programme */\n" |
| 351 |
" }\n" |
| 352 |
"}\n" |
| 353 |
|
| 354 |
#. type: SS |
| 355 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 356 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 357 |
#, no-wrap |
| 358 |
msgid "Practical" |
| 359 |
msgstr "Pratique" |
| 360 |
|
| 361 |
#. type: Plain text |
| 362 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 363 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 364 |
msgid "" |
| 365 |
"So what is the point of B<select>()? Can't I just read and write to my file " |
| 366 |
"descriptors whenever I want? The point of B<select>() is that it watches " |
| 367 |
"multiple descriptors at the same time and properly puts the process to sleep " |
| 368 |
"if there is no activity. UNIX programmers often find themselves in a " |
| 369 |
"position where they have to handle I/O from more than one file descriptor " |
| 370 |
"where the data flow may be intermittent. If you were to merely create a " |
| 371 |
"sequence of B<read>(2) and B<write>(2) calls, you would find that one of " |
| 372 |
"your calls may block waiting for data from/to a file descriptor, while " |
| 373 |
"another file descriptor is unused though ready for I/O. B<select>() " |
| 374 |
"efficiently copes with this situation." |
| 375 |
msgstr "" |
| 376 |
"Quelle est donc la finalité de B<select>()\\ ? Ne peut on pas simplement " |
| 377 |
"lire et écrire dans les descripteurs chaque fois qu'on le souhaite\\ ? " |
| 378 |
"L'objet de B<select>() est de surveiller de multiples descripteurs " |
| 379 |
"simultanément et d'endormir proprement le processus s'il n'y a pas " |
| 380 |
"d'activité. Les programmeurs UNIX se retrouvent souvent dans une situation " |
| 381 |
"dans laquelle ils doivent gérer des entrées-sorties provenant de plus d'un " |
| 382 |
"descripteur de fichier et dans laquelle le flux de données est intermittent. " |
| 383 |
"Si vous deviez créer une séquence d'appels B<read>(2) et B<write>(2), vous " |
| 384 |
"vous retrouveriez potentiellement bloqué sur un de vos appels attendant pour " |
| 385 |
"lire ou écrire des données à partir/vers un descripteur de fichier, alors " |
| 386 |
"qu'un autre descripteur de fichier est inutilisé bien qu'il soit prêt pour " |
| 387 |
"des entrées-sorties. B<select>() gère efficacement cette situation." |
| 388 |
|
| 389 |
#. type: SS |
| 390 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 391 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 392 |
#, no-wrap |
| 393 |
msgid "Select law" |
| 394 |
msgstr "Règles de select" |
| 395 |
|
| 396 |
#. type: Plain text |
| 397 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 398 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 399 |
msgid "" |
| 400 |
"Many people who try to use B<select>() come across behavior that is " |
| 401 |
"difficult to understand and produces nonportable or borderline results. For " |
| 402 |
"instance, the above program is carefully written not to block at any point, " |
| 403 |
"even though it does not set its file descriptors to nonblocking mode. It is " |
| 404 |
"easy to introduce subtle errors that will remove the advantage of using " |
| 405 |
"B<select>(), so here is a list of essentials to watch for when using " |
| 406 |
"B<select>()." |
| 407 |
msgstr "" |
| 408 |
"De nombreuses personnes qui essaient d'utiliser B<select>() obtiennent un " |
| 409 |
"comportement difficile à comprendre et produisent des résultats non " |
| 410 |
"portables ou des effets de bord. Par exemple, le programme ci-dessus est " |
| 411 |
"écrit avec précaution afin de ne bloquer nulle part, même s'il ne positionne " |
| 412 |
"pas ses descripteurs de fichier en mode non bloquant.Il est facile " |
| 413 |
"d'introduire des erreurs subtiles qui annuleraient l'avantage de " |
| 414 |
"l'utilisation de B<select>(), aussi, voici une liste de points essentiels à " |
| 415 |
"contrôler lors de l'utilisation de B<select>()." |
| 416 |
|
| 417 |
#. type: TP |
| 418 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 419 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 420 |
#, no-wrap |
| 421 |
msgid "1." |
| 422 |
msgstr "1." |
| 423 |
|
| 424 |
#. type: Plain text |
| 425 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 426 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 427 |
msgid "" |
| 428 |
"You should always try to use B<select>() without a timeout. Your program " |
| 429 |
"should have nothing to do if there is no data available. Code that depends " |
| 430 |
"on timeouts is not usually portable and is difficult to debug." |
| 431 |
msgstr "" |
| 432 |
"Vous devriez toujours essayer d'utiliser B<select>() sans timeout. Votre " |
| 433 |
"programme ne devrait rien avoir à faire s'il n'y a pas de données " |
| 434 |
"disponibles. Le code dépendant de timeouts n'est en général pas portable et " |
| 435 |
"difficile à déboguer." |
| 436 |
|
| 437 |
#. type: TP |
| 438 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 439 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 440 |
#, no-wrap |
| 441 |
msgid "2." |
| 442 |
msgstr "2." |
| 443 |
|
| 444 |
#. type: Plain text |
| 445 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 446 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 447 |
msgid "" |
| 448 |
"The value I<nfds> must be properly calculated for efficiency as explained " |
| 449 |
"above." |
| 450 |
msgstr "" |
| 451 |
"La valeur I<nfds> doit être calculée correctement pour des raisons " |
| 452 |
"d'efficacité comme expliqué plus haut." |
| 453 |
|
| 454 |
#. type: TP |
| 455 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 456 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 457 |
#, no-wrap |
| 458 |
msgid "3." |
| 459 |
msgstr "3." |
| 460 |
|
| 461 |
#. type: Plain text |
| 462 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 463 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 464 |
msgid "" |
| 465 |
"No file descriptor must be added to any set if you do not intend to check " |
| 466 |
"its result after the B<select>() call, and respond appropriately. See next " |
| 467 |
"rule." |
| 468 |
msgstr "" |
| 469 |
"Aucun descripteur de fichier ne doit être ajouté à un quelconque ensemble si " |
| 470 |
"vous ne projetez pas de vérifier son état après un appel à B<select>(), et " |
| 471 |
"de réagir de façon adéquate. Voir la règle suivante." |
| 472 |
|
| 473 |
#. type: TP |
| 474 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 475 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 476 |
#, no-wrap |
| 477 |
msgid "4." |
| 478 |
msgstr "4." |
| 479 |
|
| 480 |
#. type: Plain text |
| 481 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 482 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 483 |
msgid "" |
| 484 |
"After B<select>() returns, all file descriptors in all sets should be " |
| 485 |
"checked to see if they are ready." |
| 486 |
msgstr "" |
| 487 |
"Après le retour de B<select>(), tous les descripteurs de fichier dans tous " |
| 488 |
"les ensembles devraient être testés pour savoir s'ils sont prêts." |
| 489 |
|
| 490 |
#. type: TP |
| 491 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 492 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 493 |
#, no-wrap |
| 494 |
msgid "5." |
| 495 |
msgstr "5." |
| 496 |
|
| 497 |
#. type: Plain text |
| 498 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 499 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 500 |
msgid "" |
| 501 |
"The functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) do I<not> " |
| 502 |
"necessarily read/write the full amount of data that you have requested. If " |
| 503 |
"they do read/write the full amount, it's because you have a low traffic load " |
| 504 |
"and a fast stream. This is not always going to be the case. You should " |
| 505 |
"cope with the case of your functions managing to send or receive only a " |
| 506 |
"single byte." |
| 507 |
msgstr "" |
| 508 |
"Les fonctions B<read>(2), B<recv>(2), B<write>(2) et B<send>(2) ne lisent ou " |
| 509 |
"n'écrivent I<pas> forcément la quantité totale de données spécifiée. Si " |
| 510 |
"elles lisent/écrivent la quantité totale, c'est parce que vous avez une " |
| 511 |
"faible charge de trafic et un flux rapide. Ce n'est pas toujours le cas. " |
| 512 |
"Vous devriez gérer le cas où vos fonctions traitent seulement l'envoi ou la " |
| 513 |
"réception d'un unique octet." |
| 514 |
|
| 515 |
#. type: TP |
| 516 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 517 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 518 |
#, no-wrap |
| 519 |
msgid "6." |
| 520 |
msgstr "6." |
| 521 |
|
| 522 |
#. type: Plain text |
| 523 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 524 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 525 |
msgid "" |
| 526 |
"Never read/write only in single bytes at a time unless you are really sure " |
| 527 |
"that you have a small amount of data to process. It is extremely " |
| 528 |
"inefficient not to read/write as much data as you can buffer each time. The " |
| 529 |
"buffers in the example below are 1024 bytes although they could easily be " |
| 530 |
"made larger." |
| 531 |
msgstr "" |
| 532 |
"Ne lisez/n'écrivez jamais seulement quelques octets à la fois à moins que " |
| 533 |
"vous ne soyez absolument sûr de n'avoir qu'une faible quantité de données à " |
| 534 |
"traiter. Il est parfaitement inefficace de ne pas lire/écrire autant de " |
| 535 |
"données que vous pouvez en stocker à chaque fois. Les tampons de l'exemple " |
| 536 |
"ci-dessous font 1024 octets bien qu'ils aient facilement pu être rendus plus " |
| 537 |
"grands." |
| 538 |
|
| 539 |
#. type: TP |
| 540 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 541 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 542 |
#, no-wrap |
| 543 |
msgid "7." |
| 544 |
msgstr "7." |
| 545 |
|
| 546 |
#. Nonetheless, you should still cope with these errors for completeness. |
| 547 |
#. type: Plain text |
| 548 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 549 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 550 |
msgid "" |
| 551 |
"Calls to B<read>(2), B<recv>(2), B<write>(2), B<send>(2), and B<select>() " |
| 552 |
"can fail with the error B<EINTR>, and calls to B<read>(2), B<recv>(2), " |
| 553 |
"B<write>(2), and B<send>(2) can fail with I<errno> set to B<EAGAIN> " |
| 554 |
"(B<EWOULDBLOCK>). These results must be properly managed (not done properly " |
| 555 |
"above). If your program is not going to receive any signals, then it is " |
| 556 |
"unlikely you will get B<EINTR>. If your program does not set nonblocking I/" |
| 557 |
"O, you will not get B<EAGAIN>." |
| 558 |
msgstr "" |
| 559 |
"Les appels à B<read>(2), B<recv>(2), B<write>(2), B<send>(2) et B<select>() " |
| 560 |
"peuvent échouer avec l'erreur B<EINTR> et les appels à B<read>(2), " |
| 561 |
"B<recv>(2), B<write>(2), B<write>(2) et B<send>(2) peuvent échouer avec " |
| 562 |
"I<errno> positionné sur B<EAGAIN> (B<EWOULDBLOCK>). Ces résultats doivent " |
| 563 |
"être correctement gérés (cela n'est pas fait correctement ci-dessus). Si " |
| 564 |
"votre programme n'est pas censé recevoir de signal, alors, il est hautement " |
| 565 |
"improbable que vous obteniez B<EINTR>. Si votre programme n'a pas configuré " |
| 566 |
"les entrées-sorties en mode non bloquant, vous n'obtiendrez pas de B<EAGAIN>." |
| 567 |
|
| 568 |
#. type: TP |
| 569 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 570 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 571 |
#, no-wrap |
| 572 |
msgid "8." |
| 573 |
msgstr "8." |
| 574 |
|
| 575 |
#. type: Plain text |
| 576 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 577 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 578 |
msgid "" |
| 579 |
"Never call B<read>(2), B<recv>(2), B<write>(2), or B<send>(2) with a buffer " |
| 580 |
"length of zero." |
| 581 |
msgstr "" |
| 582 |
"N'appelez jamais B<read>(2), B<recv>(2), B<write>(2) ou B<send>(2) avec un " |
| 583 |
"tampon de taille nulle." |
| 584 |
|
| 585 |
#. type: TP |
| 586 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 587 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 588 |
#, no-wrap |
| 589 |
msgid "9." |
| 590 |
msgstr "9." |
| 591 |
|
| 592 |
#. type: Plain text |
| 593 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 594 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 595 |
msgid "" |
| 596 |
"If the functions B<read>(2), B<recv>(2), B<write>(2), and B<send>(2) fail " |
| 597 |
"with errors other than those listed in B<7.>, or one of the input functions " |
| 598 |
"returns 0, indicating end of file, then you should I<not> pass that file " |
| 599 |
"descriptor to B<select>() again. In the example below, I close the file " |
| 600 |
"descriptor immediately, and then set it to -1 to prevent it being included " |
| 601 |
"in a set." |
| 602 |
msgstr "" |
| 603 |
"Si les fonctions B<read>(2), B<recv>(2), B<write>(2) et B<send>(2) échouent " |
| 604 |
"avec une erreur autre que celles indiquées en B<7.>, ou si l'une des " |
| 605 |
"fonctions d'entrée renvoie B<0>, indiquant une fin de fichier, vous I<ne> " |
| 606 |
"devriez I<pas> utiliser ce descripteur à nouveau pour un appel à " |
| 607 |
"B<select>(). Dans l'exemple ci-dessous, le descripteur est immédiatement " |
| 608 |
"fermé et ensuite est positionné à B<-1> afin qu'il ne soit pas inclus dans " |
| 609 |
"un ensemble." |
| 610 |
|
| 611 |
#. type: TP |
| 612 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 613 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 614 |
#, no-wrap |
| 615 |
msgid "10." |
| 616 |
msgstr "10." |
| 617 |
|
| 618 |
#. type: Plain text |
| 619 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 620 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 621 |
msgid "" |
| 622 |
"The timeout value must be initialized with each new call to B<select>(), " |
| 623 |
"since some operating systems modify the structure. B<pselect>() however " |
| 624 |
"does not modify its timeout structure." |
| 625 |
msgstr "" |
| 626 |
"La valeur de timeout doit être initialisée à chaque nouvel appel à " |
| 627 |
"B<select>(), puisque des systèmes d'exploitation modifient la structure. " |
| 628 |
"Cependant, B<pselect>() ne modifie pas sa structure de timeout." |
| 629 |
|
| 630 |
#. type: TP |
| 631 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 632 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 633 |
#, no-wrap |
| 634 |
msgid "11." |
| 635 |
msgstr "11." |
| 636 |
|
| 637 |
#. "I have heard" does not fill me with confidence, and doesn't |
| 638 |
#. belong in a man page, so I've commented this point out. |
| 639 |
#. .TP |
| 640 |
#. 11. |
| 641 |
#. I have heard that the Windows socket layer does not cope with OOB data |
| 642 |
#. properly. |
| 643 |
#. It also does not cope with |
| 644 |
#. .BR select () |
| 645 |
#. calls when no file descriptors are set at all. |
| 646 |
#. Having no file descriptors set is a useful |
| 647 |
#. way to sleep the process with subsecond precision by using the timeout. |
| 648 |
#. (See further on.) |
| 649 |
#. type: Plain text |
| 650 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 651 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 652 |
msgid "" |
| 653 |
"Since B<select>() modifies its file descriptor sets, if the call is being " |
| 654 |
"used in a loop, then the sets must be reinitialized before each call." |
| 655 |
msgstr "" |
| 656 |
"Comme B<select>() modifie ses ensembles de descripteurs de fichiers, si " |
| 657 |
"l'appel est effectué dans une boucle alors les ensembles doivent être " |
| 658 |
"réinitialisés avant chaque appel." |
| 659 |
|
| 660 |
#. type: SH |
| 661 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 662 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 663 |
#, no-wrap |
| 664 |
msgid "RETURN VALUE" |
| 665 |
msgstr "VALEUR RENVOYÉE" |
| 666 |
|
| 667 |
#. type: Plain text |
| 668 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 669 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 670 |
msgid "See B<select>(2)." |
| 671 |
msgstr "Voir B<select>(2)." |
| 672 |
|
| 673 |
#. type: SH |
| 674 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 675 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 676 |
#, no-wrap |
| 677 |
msgid "NOTES" |
| 678 |
msgstr "NOTES" |
| 679 |
|
| 680 |
#. type: Plain text |
| 681 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 682 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 683 |
msgid "" |
| 684 |
"Generally speaking, all operating systems that support sockets also support " |
| 685 |
"B<select>(). B<select>() can be used to solve many problems in a portable " |
| 686 |
"and efficient way that naive programmers try to solve in a more complicated " |
| 687 |
"manner using threads, forking, IPCs, signals, memory sharing, and so on." |
| 688 |
msgstr "" |
| 689 |
"De façon générale, tous les systèmes d'exploitation qui gèrent les sockets " |
| 690 |
"proposent également B<select>(). B<select>() peut être utilisé pour résoudre " |
| 691 |
"de façon portable et efficace de nombreux problèmes que des programmeurs " |
| 692 |
"naïfs essaient de résoudre avec des threads, des forks, des IPC, des " |
| 693 |
"signaux, des mémoires partagées et d'autres méthodes peu élégantes." |
| 694 |
|
| 695 |
#. type: Plain text |
| 696 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 697 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 698 |
msgid "" |
| 699 |
"The B<poll>(2) system call has the same functionality as B<select>(), and " |
| 700 |
"is somewhat more efficient when monitoring sparse file descriptor sets. It " |
| 701 |
"is nowadays widely available, but historically was less portable than " |
| 702 |
"B<select>()." |
| 703 |
msgstr "" |
| 704 |
"L'appel système B<poll>(2) a les mêmes fonctionnalités que B<select>(), tout " |
| 705 |
"en étant légèrement plus efficace quand il doit surveiller des ensembles de " |
| 706 |
"descripteurs creux. Il est disponible sur la plupart des systèmes de nos " |
| 707 |
"jours, mais était historiquement moins portable que B<select>()." |
| 708 |
|
| 709 |
#. type: Plain text |
| 710 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 711 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 712 |
msgid "" |
| 713 |
"The Linux-specific B<epoll>(7) API provides an interface that is more " |
| 714 |
"efficient than B<select>(2) and B<poll>(2) when monitoring large numbers " |
| 715 |
"of file descriptors." |
| 716 |
msgstr "" |
| 717 |
"L'API B<epoll>(7) spécifique à Linux fournit une interface plus efficace que " |
| 718 |
"B<select>(2) et B<poll>(2) lorsque l'on surveille un grand nombre de " |
| 719 |
"descripteurs de fichier." |
| 720 |
|
| 721 |
#. type: SH |
| 722 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 723 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 724 |
#, no-wrap |
| 725 |
msgid "EXAMPLES" |
| 726 |
msgstr "EXEMPLES" |
| 727 |
|
| 728 |
#. type: Plain text |
| 729 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 730 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 731 |
msgid "" |
| 732 |
"Here is an example that better demonstrates the true utility of " |
| 733 |
"B<select>(). The listing below is a TCP forwarding program that forwards " |
| 734 |
"from one TCP port to another." |
| 735 |
msgstr "" |
| 736 |
"Voici un exemple qui montre mieux l'utilité réelle de B<select>(). Le code " |
| 737 |
"ci-dessous consiste en un programme de «\\ TCP forwarding\\ » qui redirige " |
| 738 |
"un port TCP vers un autre." |
| 739 |
|
| 740 |
#. type: Plain text |
| 741 |
#: archlinux debian-unstable mageia-cauldron opensuse-leap-16-1 |
| 742 |
#: opensuse-tumbleweed |
| 743 |
#, fuzzy, no-wrap |
| 744 |
#| msgid "" |
| 745 |
#| "#include E<lt>arpa/inet.hE<gt>\n" |
| 746 |
#| "#include E<lt>errno.hE<gt>\n" |
| 747 |
#| "#include E<lt>netinet/in.hE<gt>\n" |
| 748 |
#| "#include E<lt>signal.hE<gt>\n" |
| 749 |
#| "#include E<lt>stdio.hE<gt>\n" |
| 750 |
#| "#include E<lt>stdlib.hE<gt>\n" |
| 751 |
#| "#include E<lt>string.hE<gt>\n" |
| 752 |
#| "#include E<lt>sys/select.hE<gt>\n" |
| 753 |
#| "#include E<lt>sys/socket.hE<gt>\n" |
| 754 |
#| "#include E<lt>sys/types.hE<gt>\n" |
| 755 |
#| "#include E<lt>unistd.hE<gt>\n" |
| 756 |
#| "\\&\n" |
| 757 |
#| "static int forward_port;\n" |
| 758 |
#| "\\&\n" |
| 759 |
#| "#undef max\n" |
| 760 |
#| "#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n" |
| 761 |
#| "\\&\n" |
| 762 |
#| "static int\n" |
| 763 |
#| "listen_socket(int listen_port)\n" |
| 764 |
#| "{\n" |
| 765 |
#| " int lfd;\n" |
| 766 |
#| " int yes;\n" |
| 767 |
#| " struct sockaddr_in addr;\n" |
| 768 |
#| "\\&\n" |
| 769 |
#| " lfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 770 |
#| " if (lfd == -1) {\n" |
| 771 |
#| " perror(\"socket\");\n" |
| 772 |
#| " return -1;\n" |
| 773 |
#| " }\n" |
| 774 |
#| "\\&\n" |
| 775 |
#| " yes = 1;\n" |
| 776 |
#| " if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" |
| 777 |
#| " &yes, sizeof(yes)) == -1)\n" |
| 778 |
#| " {\n" |
| 779 |
#| " perror(\"setsockopt\");\n" |
| 780 |
#| " close(lfd);\n" |
| 781 |
#| " return -1;\n" |
| 782 |
#| " }\n" |
| 783 |
#| "\\&\n" |
| 784 |
#| " memset(&addr, 0, sizeof(addr));\n" |
| 785 |
#| " addr.sin_port = htons(listen_port);\n" |
| 786 |
#| " addr.sin_family = AF_INET;\n" |
| 787 |
#| " if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 788 |
#| " perror(\"bind\");\n" |
| 789 |
#| " close(lfd);\n" |
| 790 |
#| " return -1;\n" |
| 791 |
#| " }\n" |
| 792 |
#| "\\&\n" |
| 793 |
#| " printf(\"accepting connections on port %d\\[rs]n\", listen_port);\n" |
| 794 |
#| " listen(lfd, 10);\n" |
| 795 |
#| " return lfd;\n" |
| 796 |
#| "}\n" |
| 797 |
#| "\\&\n" |
| 798 |
#| "static int\n" |
| 799 |
#| "connect_socket(int connect_port, char *address)\n" |
| 800 |
#| "{\n" |
| 801 |
#| " int cfd;\n" |
| 802 |
#| " struct sockaddr_in addr;\n" |
| 803 |
#| "\\&\n" |
| 804 |
#| " cfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 805 |
#| " if (cfd == -1) {\n" |
| 806 |
#| " perror(\"socket\");\n" |
| 807 |
#| " return -1;\n" |
| 808 |
#| " }\n" |
| 809 |
#| "\\&\n" |
| 810 |
#| " memset(&addr, 0, sizeof(addr));\n" |
| 811 |
#| " addr.sin_port = htons(connect_port);\n" |
| 812 |
#| " addr.sin_family = AF_INET;\n" |
| 813 |
#| "\\&\n" |
| 814 |
#| " if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" |
| 815 |
#| " fprintf(stderr, \"inet_aton(): bad IP address format\\[rs]n\");\n" |
| 816 |
#| " close(cfd);\n" |
| 817 |
#| " return -1;\n" |
| 818 |
#| " }\n" |
| 819 |
#| "\\&\n" |
| 820 |
#| " if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 821 |
#| " perror(\"connect()\");\n" |
| 822 |
#| " shutdown(cfd, SHUT_RDWR);\n" |
| 823 |
#| " close(cfd);\n" |
| 824 |
#| " return -1;\n" |
| 825 |
#| " }\n" |
| 826 |
#| " return cfd;\n" |
| 827 |
#| "}\n" |
| 828 |
#| "\\&\n" |
| 829 |
#| "#define SHUT_FD1 do { \\[rs]\n" |
| 830 |
#| " if (fd1 E<gt>= 0) { \\[rs]\n" |
| 831 |
#| " shutdown(fd1, SHUT_RDWR); \\[rs]\n" |
| 832 |
#| " close(fd1); \\[rs]\n" |
| 833 |
#| " fd1 = -1; \\[rs]\n" |
| 834 |
#| " } \\[rs]\n" |
| 835 |
#| " } while (0)\n" |
| 836 |
#| "\\&\n" |
| 837 |
#| "#define SHUT_FD2 do { \\[rs]\n" |
| 838 |
#| " if (fd2 E<gt>= 0) { \\[rs]\n" |
| 839 |
#| " shutdown(fd2, SHUT_RDWR); \\[rs]\n" |
| 840 |
#| " close(fd2); \\[rs]\n" |
| 841 |
#| " fd2 = -1; \\[rs]\n" |
| 842 |
#| " } \\[rs]\n" |
| 843 |
#| " } while (0)\n" |
| 844 |
#| "\\&\n" |
| 845 |
#| "#define BUF_SIZE 1024\n" |
| 846 |
#| "\\&\n" |
| 847 |
#| "int\n" |
| 848 |
#| "main(int argc, char *argv[])\n" |
| 849 |
#| "{\n" |
| 850 |
#| " int h;\n" |
| 851 |
#| " int ready, nfds;\n" |
| 852 |
#| " int fd1 = -1, fd2 = -1;\n" |
| 853 |
#| " int buf1_avail = 0, buf1_written = 0;\n" |
| 854 |
#| " int buf2_avail = 0, buf2_written = 0;\n" |
| 855 |
#| " char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" |
| 856 |
#| " fd_set readfds, writefds, exceptfds;\n" |
| 857 |
#| " ssize_t nbytes;\n" |
| 858 |
#| "\\&\n" |
| 859 |
#| " if (argc != 4) {\n" |
| 860 |
#| " fprintf(stderr, \"Usage\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n" |
| 861 |
#| " \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n" |
| 862 |
#| " exit(EXIT_FAILURE);\n" |
| 863 |
#| " }\n" |
| 864 |
#| "\\&\n" |
| 865 |
#| " signal(SIGPIPE, SIG_IGN);\n" |
| 866 |
#| "\\&\n" |
| 867 |
#| " forward_port = atoi(argv[2]);\n" |
| 868 |
#| "\\&\n" |
| 869 |
#| " h = listen_socket(atoi(argv[1]));\n" |
| 870 |
#| " if (h == -1)\n" |
| 871 |
#| " exit(EXIT_FAILURE);\n" |
| 872 |
#| "\\&\n" |
| 873 |
#| " for (;;) {\n" |
| 874 |
#| " nfds = 0;\n" |
| 875 |
#| "\\&\n" |
| 876 |
#| " FD_ZERO(&readfds);\n" |
| 877 |
#| " FD_ZERO(&writefds);\n" |
| 878 |
#| " FD_ZERO(&exceptfds);\n" |
| 879 |
#| " FD_SET(h, &readfds);\n" |
| 880 |
#| " nfds = max(nfds, h);\n" |
| 881 |
#| "\\&\n" |
| 882 |
#| " if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n" |
| 883 |
#| " FD_SET(fd1, &readfds);\n" |
| 884 |
#| " /* Note: nfds is updated below, when fd1 is added to\n" |
| 885 |
#| " exceptfds. */\n" |
| 886 |
#| " if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n" |
| 887 |
#| " FD_SET(fd2, &readfds);\n" |
| 888 |
#| "\\&\n" |
| 889 |
#| " if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n" |
| 890 |
#| " FD_SET(fd1, &writefds);\n" |
| 891 |
#| " if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n" |
| 892 |
#| " FD_SET(fd2, &writefds);\n" |
| 893 |
#| "\\&\n" |
| 894 |
#| " if (fd1 E<gt> 0) {\n" |
| 895 |
#| " FD_SET(fd1, &exceptfds);\n" |
| 896 |
#| " nfds = max(nfds, fd1);\n" |
| 897 |
#| " }\n" |
| 898 |
#| " if (fd2 E<gt> 0) {\n" |
| 899 |
#| " FD_SET(fd2, &exceptfds);\n" |
| 900 |
#| " nfds = max(nfds, fd2);\n" |
| 901 |
#| " }\n" |
| 902 |
#| "\\&\n" |
| 903 |
#| " ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" |
| 904 |
#| "\\&\n" |
| 905 |
#| " if (ready == -1 && errno == EINTR)\n" |
| 906 |
#| " continue;\n" |
| 907 |
#| "\\&\n" |
| 908 |
#| " if (ready == -1) {\n" |
| 909 |
#| " perror(\"select()\");\n" |
| 910 |
#| " exit(EXIT_FAILURE);\n" |
| 911 |
#| " }\n" |
| 912 |
#| "\\&\n" |
| 913 |
#| " if (FD_ISSET(h, &readfds)) {\n" |
| 914 |
#| " socklen_t addrlen;\n" |
| 915 |
#| " struct sockaddr_in client_addr;\n" |
| 916 |
#| " int fd;\n" |
| 917 |
#| "\\&\n" |
| 918 |
#| " addrlen = sizeof(client_addr);\n" |
| 919 |
#| " memset(&client_addr, 0, addrlen);\n" |
| 920 |
#| " fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" |
| 921 |
#| " if (fd == -1) {\n" |
| 922 |
#| " perror(\"accept()\");\n" |
| 923 |
#| " } else {\n" |
| 924 |
#| " SHUT_FD1;\n" |
| 925 |
#| " SHUT_FD2;\n" |
| 926 |
#| " buf1_avail = buf1_written = 0;\n" |
| 927 |
#| " buf2_avail = buf2_written = 0;\n" |
| 928 |
#| " fd1 = fd;\n" |
| 929 |
#| " fd2 = connect_socket(forward_port, argv[3]);\n" |
| 930 |
#| " if (fd2 == -1)\n" |
| 931 |
#| " SHUT_FD1;\n" |
| 932 |
#| " else\n" |
| 933 |
#| " printf(\"connect from %s\\[rs]n\",\n" |
| 934 |
#| " inet_ntoa(client_addr.sin_addr));\n" |
| 935 |
#| "\\&\n" |
| 936 |
#| " /* Skip any events on the old, closed file\n" |
| 937 |
#| " descriptors. */\n" |
| 938 |
#| "\\&\n" |
| 939 |
#| " continue;\n" |
| 940 |
#| " }\n" |
| 941 |
#| " }\n" |
| 942 |
#| "\\&\n" |
| 943 |
#| " /* NB: read OOB data before normal reads. */\n" |
| 944 |
#| "\\&\n" |
| 945 |
#| " if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n" |
| 946 |
#| " char c;\n" |
| 947 |
#| "\\&\n" |
| 948 |
#| " nbytes = recv(fd1, &c, 1, MSG_OOB);\n" |
| 949 |
#| " if (nbytes E<lt> 1)\n" |
| 950 |
#| " SHUT_FD1;\n" |
| 951 |
#| " else\n" |
| 952 |
#| " send(fd2, &c, 1, MSG_OOB);\n" |
| 953 |
#| " }\n" |
| 954 |
#| " if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n" |
| 955 |
#| " char c;\n" |
| 956 |
#| "\\&\n" |
| 957 |
#| " nbytes = recv(fd2, &c, 1, MSG_OOB);\n" |
| 958 |
#| " if (nbytes E<lt> 1)\n" |
| 959 |
#| " SHUT_FD2;\n" |
| 960 |
#| " else\n" |
| 961 |
#| " send(fd1, &c, 1, MSG_OOB);\n" |
| 962 |
#| " }\n" |
| 963 |
#| " if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n" |
| 964 |
#| " nbytes = read(fd1, buf1 + buf1_avail,\n" |
| 965 |
#| " BUF_SIZE - buf1_avail);\n" |
| 966 |
#| " if (nbytes E<lt> 1)\n" |
| 967 |
#| " SHUT_FD1;\n" |
| 968 |
#| " else\n" |
| 969 |
#| " buf1_avail += nbytes;\n" |
| 970 |
#| " }\n" |
| 971 |
#| " if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n" |
| 972 |
#| " nbytes = read(fd2, buf2 + buf2_avail,\n" |
| 973 |
#| " BUF_SIZE - buf2_avail);\n" |
| 974 |
#| " if (nbytes E<lt> 1)\n" |
| 975 |
#| " SHUT_FD2;\n" |
| 976 |
#| " else\n" |
| 977 |
#| " buf2_avail += nbytes;\n" |
| 978 |
#| " }\n" |
| 979 |
#| " if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n" |
| 980 |
#| " nbytes = write(fd1, buf2 + buf2_written,\n" |
| 981 |
#| " buf2_avail - buf2_written);\n" |
| 982 |
#| " if (nbytes E<lt> 1)\n" |
| 983 |
#| " SHUT_FD1;\n" |
| 984 |
#| " else\n" |
| 985 |
#| " buf2_written += nbytes;\n" |
| 986 |
#| " }\n" |
| 987 |
#| " if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n" |
| 988 |
#| " nbytes = write(fd2, buf1 + buf1_written,\n" |
| 989 |
#| " buf1_avail - buf1_written);\n" |
| 990 |
#| " if (nbytes E<lt> 1)\n" |
| 991 |
#| " SHUT_FD2;\n" |
| 992 |
#| " else\n" |
| 993 |
#| " buf1_written += nbytes;\n" |
| 994 |
#| " }\n" |
| 995 |
#| "\\&\n" |
| 996 |
#| " /* Check if write data has caught read data. */\n" |
| 997 |
#| "\\&\n" |
| 998 |
#| " if (buf1_written == buf1_avail)\n" |
| 999 |
#| " buf1_written = buf1_avail = 0;\n" |
| 1000 |
#| " if (buf2_written == buf2_avail)\n" |
| 1001 |
#| " buf2_written = buf2_avail = 0;\n" |
| 1002 |
#| "\\&\n" |
| 1003 |
#| " /* One side has closed the connection, keep\n" |
| 1004 |
#| " writing to the other side until empty. */\n" |
| 1005 |
#| "\\&\n" |
| 1006 |
#| " if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n" |
| 1007 |
#| " SHUT_FD2;\n" |
| 1008 |
#| " if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n" |
| 1009 |
#| " SHUT_FD1;\n" |
| 1010 |
#| " }\n" |
| 1011 |
#| " exit(EXIT_SUCCESS);\n" |
| 1012 |
#| "}\n" |
| 1013 |
msgid "" |
| 1014 |
"#include E<lt>arpa/inet.hE<gt>\n" |
| 1015 |
"#include E<lt>errno.hE<gt>\n" |
| 1016 |
"#include E<lt>netinet/in.hE<gt>\n" |
| 1017 |
"#include E<lt>signal.hE<gt>\n" |
| 1018 |
"#include E<lt>stdio.hE<gt>\n" |
| 1019 |
"#include E<lt>stdlib.hE<gt>\n" |
| 1020 |
"#include E<lt>string.hE<gt>\n" |
| 1021 |
"#include E<lt>sys/select.hE<gt>\n" |
| 1022 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 1023 |
"#include E<lt>sys/types.hE<gt>\n" |
| 1024 |
"#include E<lt>unistd.hE<gt>\n" |
| 1025 |
"\\&\n" |
| 1026 |
"static int forward_port;\n" |
| 1027 |
"\\&\n" |
| 1028 |
"#undef max\n" |
| 1029 |
"#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n" |
| 1030 |
"\\&\n" |
| 1031 |
"static int\n" |
| 1032 |
"listen_socket(int listen_port)\n" |
| 1033 |
"{\n" |
| 1034 |
" int lfd;\n" |
| 1035 |
" int yes;\n" |
| 1036 |
" struct sockaddr_in addr;\n" |
| 1037 |
"\\&\n" |
| 1038 |
" lfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 1039 |
" if (lfd == -1) {\n" |
| 1040 |
" perror(\"socket\");\n" |
| 1041 |
" return -1;\n" |
| 1042 |
" }\n" |
| 1043 |
"\\&\n" |
| 1044 |
" yes = 1;\n" |
| 1045 |
" if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" |
| 1046 |
" &yes, sizeof(yes)) == -1)\n" |
| 1047 |
" {\n" |
| 1048 |
" perror(\"setsockopt\");\n" |
| 1049 |
" close(lfd);\n" |
| 1050 |
" return -1;\n" |
| 1051 |
" }\n" |
| 1052 |
"\\&\n" |
| 1053 |
" memset(&addr, 0, sizeof(addr));\n" |
| 1054 |
" addr.sin_port = htons(listen_port);\n" |
| 1055 |
" addr.sin_family = AF_INET;\n" |
| 1056 |
" if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 1057 |
" perror(\"bind\");\n" |
| 1058 |
" close(lfd);\n" |
| 1059 |
" return -1;\n" |
| 1060 |
" }\n" |
| 1061 |
"\\&\n" |
| 1062 |
" printf(\"accepting connections on port %d\\[rs]n\", listen_port);\n" |
| 1063 |
" listen(lfd, 10);\n" |
| 1064 |
" return lfd;\n" |
| 1065 |
"}\n" |
| 1066 |
"\\&\n" |
| 1067 |
"static int\n" |
| 1068 |
"connect_socket(int connect_port, char *address)\n" |
| 1069 |
"{\n" |
| 1070 |
" int cfd;\n" |
| 1071 |
" struct sockaddr_in addr;\n" |
| 1072 |
"\\&\n" |
| 1073 |
" cfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 1074 |
" if (cfd == -1) {\n" |
| 1075 |
" perror(\"socket\");\n" |
| 1076 |
" return -1;\n" |
| 1077 |
" }\n" |
| 1078 |
"\\&\n" |
| 1079 |
" memset(&addr, 0, sizeof(addr));\n" |
| 1080 |
" addr.sin_port = htons(connect_port);\n" |
| 1081 |
" addr.sin_family = AF_INET;\n" |
| 1082 |
"\\&\n" |
| 1083 |
" if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" |
| 1084 |
" fprintf(stderr, \"inet_aton(): bad IP address format\\[rs]n\");\n" |
| 1085 |
" close(cfd);\n" |
| 1086 |
" return -1;\n" |
| 1087 |
" }\n" |
| 1088 |
"\\&\n" |
| 1089 |
" if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 1090 |
" perror(\"connect()\");\n" |
| 1091 |
" shutdown(cfd, SHUT_RDWR);\n" |
| 1092 |
" close(cfd);\n" |
| 1093 |
" return -1;\n" |
| 1094 |
" }\n" |
| 1095 |
" return cfd;\n" |
| 1096 |
"}\n" |
| 1097 |
"\\&\n" |
| 1098 |
"#define SHUT_FD1 do { \\[rs]\n" |
| 1099 |
" if (fd1 E<gt>= 0) { \\[rs]\n" |
| 1100 |
" shutdown(fd1, SHUT_RDWR); \\[rs]\n" |
| 1101 |
" close(fd1); \\[rs]\n" |
| 1102 |
" fd1 = -1; \\[rs]\n" |
| 1103 |
" } \\[rs]\n" |
| 1104 |
" } while (0)\n" |
| 1105 |
"\\&\n" |
| 1106 |
"#define SHUT_FD2 do { \\[rs]\n" |
| 1107 |
" if (fd2 E<gt>= 0) { \\[rs]\n" |
| 1108 |
" shutdown(fd2, SHUT_RDWR); \\[rs]\n" |
| 1109 |
" close(fd2); \\[rs]\n" |
| 1110 |
" fd2 = -1; \\[rs]\n" |
| 1111 |
" } \\[rs]\n" |
| 1112 |
" } while (0)\n" |
| 1113 |
"\\&\n" |
| 1114 |
"#define BUF_SIZE 1024\n" |
| 1115 |
"\\&\n" |
| 1116 |
"int\n" |
| 1117 |
"main(int argc, char *argv[])\n" |
| 1118 |
"{\n" |
| 1119 |
" int h;\n" |
| 1120 |
" int ready, nfds;\n" |
| 1121 |
" int fd1 = -1, fd2 = -1;\n" |
| 1122 |
" int buf1_avail = 0, buf1_written = 0;\n" |
| 1123 |
" int buf2_avail = 0, buf2_written = 0;\n" |
| 1124 |
" char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" |
| 1125 |
" fd_set readfds, writefds, exceptfds;\n" |
| 1126 |
" ssize_t nbytes;\n" |
| 1127 |
"\\&\n" |
| 1128 |
" if (argc != 4) {\n" |
| 1129 |
" fprintf(stderr, \"Usage\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n" |
| 1130 |
" \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n" |
| 1131 |
" exit(EXIT_FAILURE);\n" |
| 1132 |
" }\n" |
| 1133 |
"\\&\n" |
| 1134 |
" signal(SIGPIPE, SIG_IGN);\n" |
| 1135 |
"\\&\n" |
| 1136 |
" forward_port = atoi(argv[2]);\n" |
| 1137 |
"\\&\n" |
| 1138 |
" h = listen_socket(atoi(argv[1]));\n" |
| 1139 |
" if (h == -1)\n" |
| 1140 |
" exit(EXIT_FAILURE);\n" |
| 1141 |
"\\&\n" |
| 1142 |
" for (;;) {\n" |
| 1143 |
" nfds = 0;\n" |
| 1144 |
"\\&\n" |
| 1145 |
" FD_ZERO(&readfds);\n" |
| 1146 |
" FD_ZERO(&writefds);\n" |
| 1147 |
" FD_ZERO(&exceptfds);\n" |
| 1148 |
" FD_SET(h, &readfds);\n" |
| 1149 |
" nfds = max(nfds, h);\n" |
| 1150 |
"\\&\n" |
| 1151 |
" if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n" |
| 1152 |
" FD_SET(fd1, &readfds);\n" |
| 1153 |
" /* Note: nfds is updated below, when fd1 is added to\n" |
| 1154 |
" exceptfds. */\n" |
| 1155 |
" if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n" |
| 1156 |
" FD_SET(fd2, &readfds);\n" |
| 1157 |
"\\&\n" |
| 1158 |
" if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n" |
| 1159 |
" FD_SET(fd1, &writefds);\n" |
| 1160 |
" if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n" |
| 1161 |
" FD_SET(fd2, &writefds);\n" |
| 1162 |
"\\&\n" |
| 1163 |
" if (fd1 E<gt> 0) {\n" |
| 1164 |
" FD_SET(fd1, &exceptfds);\n" |
| 1165 |
" nfds = max(nfds, fd1);\n" |
| 1166 |
" }\n" |
| 1167 |
" if (fd2 E<gt> 0) {\n" |
| 1168 |
" FD_SET(fd2, &exceptfds);\n" |
| 1169 |
" nfds = max(nfds, fd2);\n" |
| 1170 |
" }\n" |
| 1171 |
"\\&\n" |
| 1172 |
" ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" |
| 1173 |
"\\&\n" |
| 1174 |
" if (ready == -1 && errno == EINTR)\n" |
| 1175 |
" continue;\n" |
| 1176 |
"\\&\n" |
| 1177 |
" if (ready == -1) {\n" |
| 1178 |
" perror(\"select()\");\n" |
| 1179 |
" exit(EXIT_FAILURE);\n" |
| 1180 |
" }\n" |
| 1181 |
"\\&\n" |
| 1182 |
" if (FD_ISSET(h, &readfds)) {\n" |
| 1183 |
" socklen_t addrlen;\n" |
| 1184 |
" struct sockaddr_in client_addr;\n" |
| 1185 |
" int fd;\n" |
| 1186 |
"\\&\n" |
| 1187 |
" addrlen = sizeof(client_addr);\n" |
| 1188 |
" memset(&client_addr, 0, addrlen);\n" |
| 1189 |
" fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" |
| 1190 |
" if (fd == -1) {\n" |
| 1191 |
" perror(\"accept()\");\n" |
| 1192 |
" } else {\n" |
| 1193 |
" SHUT_FD1;\n" |
| 1194 |
" SHUT_FD2;\n" |
| 1195 |
" buf1_avail = buf1_written = 0;\n" |
| 1196 |
" buf2_avail = buf2_written = 0;\n" |
| 1197 |
" fd1 = fd;\n" |
| 1198 |
" fd2 = connect_socket(forward_port, argv[3]);\n" |
| 1199 |
" if (fd2 == -1)\n" |
| 1200 |
" SHUT_FD1;\n" |
| 1201 |
" else\n" |
| 1202 |
" printf(\"connect from %s\\[rs]n\",\n" |
| 1203 |
" inet_ntoa(client_addr.sin_addr));\n" |
| 1204 |
"\\&\n" |
| 1205 |
" /* Skip any events on the old, closed file\n" |
| 1206 |
" descriptors. */\n" |
| 1207 |
"\\&\n" |
| 1208 |
" continue;\n" |
| 1209 |
" }\n" |
| 1210 |
" }\n" |
| 1211 |
"\\&\n" |
| 1212 |
" /* NB: read OOB data before normal reads. */\n" |
| 1213 |
"\\&\n" |
| 1214 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n" |
| 1215 |
" char c;\n" |
| 1216 |
"\\&\n" |
| 1217 |
" nbytes = recv(fd1, &c, 1, MSG_OOB);\n" |
| 1218 |
" if (nbytes E<lt> 1)\n" |
| 1219 |
" SHUT_FD1;\n" |
| 1220 |
" else\n" |
| 1221 |
" send(fd2, &c, 1, MSG_OOB);\n" |
| 1222 |
" }\n" |
| 1223 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n" |
| 1224 |
" char c;\n" |
| 1225 |
"\\&\n" |
| 1226 |
" nbytes = recv(fd2, &c, 1, MSG_OOB);\n" |
| 1227 |
" if (nbytes E<lt> 1)\n" |
| 1228 |
" SHUT_FD2;\n" |
| 1229 |
" else\n" |
| 1230 |
" send(fd1, &c, 1, MSG_OOB);\n" |
| 1231 |
" }\n" |
| 1232 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n" |
| 1233 |
" nbytes = read(fd1, buf1 + buf1_avail,\n" |
| 1234 |
" BUF_SIZE - buf1_avail);\n" |
| 1235 |
" if (nbytes E<lt> 1)\n" |
| 1236 |
" SHUT_FD1;\n" |
| 1237 |
" else\n" |
| 1238 |
" buf1_avail += nbytes;\n" |
| 1239 |
" }\n" |
| 1240 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n" |
| 1241 |
" nbytes = read(fd2, buf2 + buf2_avail,\n" |
| 1242 |
" BUF_SIZE - buf2_avail);\n" |
| 1243 |
" if (nbytes E<lt> 1)\n" |
| 1244 |
" SHUT_FD2;\n" |
| 1245 |
" else\n" |
| 1246 |
" buf2_avail += nbytes;\n" |
| 1247 |
" }\n" |
| 1248 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n" |
| 1249 |
" nbytes = write(fd1, buf2 + buf2_written,\n" |
| 1250 |
" buf2_avail - buf2_written);\n" |
| 1251 |
" if (nbytes E<lt> 1)\n" |
| 1252 |
" SHUT_FD1;\n" |
| 1253 |
" else\n" |
| 1254 |
" buf2_written += nbytes;\n" |
| 1255 |
" }\n" |
| 1256 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n" |
| 1257 |
" nbytes = write(fd2, buf1 + buf1_written,\n" |
| 1258 |
" buf1_avail - buf1_written);\n" |
| 1259 |
" if (nbytes E<lt> 1)\n" |
| 1260 |
" SHUT_FD2;\n" |
| 1261 |
" else\n" |
| 1262 |
" buf1_written += nbytes;\n" |
| 1263 |
" }\n" |
| 1264 |
"\\&\n" |
| 1265 |
" /* Check if write data has caught read data. */\n" |
| 1266 |
"\\&\n" |
| 1267 |
" if (buf1_written == buf1_avail)\n" |
| 1268 |
" buf1_written = buf1_avail = 0;\n" |
| 1269 |
" if (buf2_written == buf2_avail)\n" |
| 1270 |
" buf2_written = buf2_avail = 0;\n" |
| 1271 |
"\\&\n" |
| 1272 |
" /* One side has closed the connection, keep\n" |
| 1273 |
" writing to the other side until empty. */\n" |
| 1274 |
"\\&\n" |
| 1275 |
" if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n" |
| 1276 |
" SHUT_FD2;\n" |
| 1277 |
" if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n" |
| 1278 |
" SHUT_FD1;\n" |
| 1279 |
" }\n" |
| 1280 |
" exit(EXIT_SUCCESS);\n" |
| 1281 |
"}\n" |
| 1282 |
msgstr "" |
| 1283 |
"#include E<lt>arpa/inet.hE<gt>\n" |
| 1284 |
"#include E<lt>errno.hE<gt>\n" |
| 1285 |
"#include E<lt>netinet/in.hE<gt>\n" |
| 1286 |
"#include E<lt>signal.hE<gt>\n" |
| 1287 |
"#include E<lt>stdio.hE<gt>\n" |
| 1288 |
"#include E<lt>stdlib.hE<gt>\n" |
| 1289 |
"#include E<lt>string.hE<gt>\n" |
| 1290 |
"#include E<lt>sys/select.hE<gt>\n" |
| 1291 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 1292 |
"#include E<lt>sys/types.hE<gt>\n" |
| 1293 |
"#include E<lt>unistd.hE<gt>\n" |
| 1294 |
"\\&\n" |
| 1295 |
"static int forward_port;\n" |
| 1296 |
"\\&\n" |
| 1297 |
"#undef max\n" |
| 1298 |
"#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n" |
| 1299 |
"\\&\n" |
| 1300 |
"static int\n" |
| 1301 |
"listen_socket(int listen_port)\n" |
| 1302 |
"{\n" |
| 1303 |
" int lfd;\n" |
| 1304 |
" int yes;\n" |
| 1305 |
" struct sockaddr_in addr;\n" |
| 1306 |
"\\&\n" |
| 1307 |
" lfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 1308 |
" if (lfd == -1) {\n" |
| 1309 |
" perror(\"socket\");\n" |
| 1310 |
" return -1;\n" |
| 1311 |
" }\n" |
| 1312 |
"\\&\n" |
| 1313 |
" yes = 1;\n" |
| 1314 |
" if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" |
| 1315 |
" &yes, sizeof(yes)) == -1)\n" |
| 1316 |
" {\n" |
| 1317 |
" perror(\"setsockopt\");\n" |
| 1318 |
" close(lfd);\n" |
| 1319 |
" return -1;\n" |
| 1320 |
" }\n" |
| 1321 |
"\\&\n" |
| 1322 |
" memset(&addr, 0, sizeof(addr));\n" |
| 1323 |
" addr.sin_port = htons(listen_port);\n" |
| 1324 |
" addr.sin_family = AF_INET;\n" |
| 1325 |
" if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 1326 |
" perror(\"bind\");\n" |
| 1327 |
" close(lfd);\n" |
| 1328 |
" return -1;\n" |
| 1329 |
" }\n" |
| 1330 |
"\\&\n" |
| 1331 |
" printf(\"on accepte les connexions sur le port %d\\[rs]n\", listen_port);\n" |
| 1332 |
" listen(lfd, 10);\n" |
| 1333 |
" return lfd;\n" |
| 1334 |
"}\n" |
| 1335 |
"\\&\n" |
| 1336 |
"static int\n" |
| 1337 |
"connect_socket(int connect_port, char *address)\n" |
| 1338 |
"{\n" |
| 1339 |
" int cfd;\n" |
| 1340 |
" struct sockaddr_in addr;\n" |
| 1341 |
"\\&\n" |
| 1342 |
" cfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 1343 |
" if (cfd == -1) {\n" |
| 1344 |
" perror(\"socket\");\n" |
| 1345 |
" return -1;\n" |
| 1346 |
" }\n" |
| 1347 |
"\\&\n" |
| 1348 |
" memset(&addr, 0, sizeof(addr));\n" |
| 1349 |
" addr.sin_port = htons(connect_port);\n" |
| 1350 |
" addr.sin_family = AF_INET;\n" |
| 1351 |
"\\&\n" |
| 1352 |
" if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" |
| 1353 |
" fprintf(stderr, \"inet_aton(): mauvais format d'adresse IP\\[rs]n\");\n" |
| 1354 |
" close(cfd);\n" |
| 1355 |
" return -1;\n" |
| 1356 |
" }\n" |
| 1357 |
"\\&\n" |
| 1358 |
" if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 1359 |
" perror(\"connect()\");\n" |
| 1360 |
" shutdown(cfd, SHUT_RDWR);\n" |
| 1361 |
" close(cfd);\n" |
| 1362 |
" return -1;\n" |
| 1363 |
" }\n" |
| 1364 |
" return cfd;\n" |
| 1365 |
"}\n" |
| 1366 |
"\\&\n" |
| 1367 |
"#define SHUT_FD1 do { \\[rs]\n" |
| 1368 |
" if (fd1 E<gt>= 0) { \\[rs]\n" |
| 1369 |
" shutdown(fd1, SHUT_RDWR); \\[rs]\n" |
| 1370 |
" close(fd1); \\[rs]\n" |
| 1371 |
" fd1 = -1; \\[rs]\n" |
| 1372 |
" } \\[rs]\n" |
| 1373 |
" } while (0)\n" |
| 1374 |
"\\&\n" |
| 1375 |
"#define SHUT_FD2 do { \\[rs]\n" |
| 1376 |
" if (fd2 E<gt>= 0) { \\[rs]\n" |
| 1377 |
" shutdown(fd2, SHUT_RDWR); \\[rs]\n" |
| 1378 |
" close(fd2); \\[rs]\n" |
| 1379 |
" fd2 = -1; \\[rs]\n" |
| 1380 |
" } \\[rs]\n" |
| 1381 |
" } while (0)\n" |
| 1382 |
"\\&\n" |
| 1383 |
"#define BUF_SIZE 1024\n" |
| 1384 |
"\\&\n" |
| 1385 |
"int\n" |
| 1386 |
"main(int argc, char *argv[])\n" |
| 1387 |
"{\n" |
| 1388 |
" int h;\n" |
| 1389 |
" int ready, nfds;\n" |
| 1390 |
" int fd1 = -1, fd2 = -1;\n" |
| 1391 |
" int buf1_avail = 0, buf1_written = 0;\n" |
| 1392 |
" int buf2_avail = 0, buf2_written = 0;\n" |
| 1393 |
" char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" |
| 1394 |
" fd_set readfds, writefds, exceptfds;\n" |
| 1395 |
" ssize_t nbytes;\n" |
| 1396 |
"\\&\n" |
| 1397 |
" if (argc != 4) {\n" |
| 1398 |
" fprintf(stderr, \"Utilisation\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n" |
| 1399 |
" \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n" |
| 1400 |
" exit(EXIT_FAILURE);\n" |
| 1401 |
" }\n" |
| 1402 |
"\\&\n" |
| 1403 |
" signal(SIGPIPE, SIG_IGN);\n" |
| 1404 |
"\\&\n" |
| 1405 |
" forward_port = atoi(argv[2]);\n" |
| 1406 |
"\\&\n" |
| 1407 |
" h = listen_socket(atoi(argv[1]));\n" |
| 1408 |
" if (h == -1)\n" |
| 1409 |
" exit(EXIT_FAILURE);\n" |
| 1410 |
"\\&\n" |
| 1411 |
" for (;;) {\n" |
| 1412 |
" nfds = 0;\n" |
| 1413 |
"\\&\n" |
| 1414 |
" FD_ZERO(&readfds);\n" |
| 1415 |
" FD_ZERO(&writefds);\n" |
| 1416 |
" FD_ZERO(&exceptfds);\n" |
| 1417 |
" FD_SET(h, &readfds);\n" |
| 1418 |
" nfds = max(nfds, h);\n" |
| 1419 |
"\\&\n" |
| 1420 |
" if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n" |
| 1421 |
" FD_SET(fd1, &readfds);\n" |
| 1422 |
" /* Note: nfds est mis à jour ci-dessous, lorsque fd1\n" |
| 1423 |
" est ajouté à exceptfds. */\n" |
| 1424 |
" if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n" |
| 1425 |
" FD_SET(fd2, &readfds);\n" |
| 1426 |
"\\&\n" |
| 1427 |
" if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n" |
| 1428 |
" FD_SET(fd1, &writefds);\n" |
| 1429 |
" if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n" |
| 1430 |
" FD_SET(fd2, &writefds);\n" |
| 1431 |
"\\&\n" |
| 1432 |
" if (fd1 E<gt> 0) {\n" |
| 1433 |
" FD_SET(fd1, &exceptfds);\n" |
| 1434 |
" nfds = max(nfds, fd1);\n" |
| 1435 |
" }\n" |
| 1436 |
" if (fd2 E<gt> 0) {\n" |
| 1437 |
" FD_SET(fd2, &exceptfds);\n" |
| 1438 |
" nfds = max(nfds, fd2);\n" |
| 1439 |
" }\n" |
| 1440 |
"\\&\n" |
| 1441 |
" ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" |
| 1442 |
"\\&\n" |
| 1443 |
" if (ready == -1 && errno == EINTR)\n" |
| 1444 |
" continue;\n" |
| 1445 |
"\\&\n" |
| 1446 |
" if (ready == -1) {\n" |
| 1447 |
" perror(\"select()\");\n" |
| 1448 |
" exit(EXIT_FAILURE);\n" |
| 1449 |
" }\n" |
| 1450 |
"\\&\n" |
| 1451 |
" if (FD_ISSET(h, &readfds)) {\n" |
| 1452 |
" socklen_t addrlen;\n" |
| 1453 |
" struct sockaddr_in client_addr;\n" |
| 1454 |
" int fd;\n" |
| 1455 |
"\\&\n" |
| 1456 |
" addrlen = sizeof(client_addr);\n" |
| 1457 |
" memset(&client_addr, 0, addrlen);\n" |
| 1458 |
" fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" |
| 1459 |
" if (fd == -1) {\n" |
| 1460 |
" perror(\"accept()\");\n" |
| 1461 |
" } else {\n" |
| 1462 |
" SHUT_FD1;\n" |
| 1463 |
" SHUT_FD2;\n" |
| 1464 |
" buf1_avail = buf1_written = 0;\n" |
| 1465 |
" buf2_avail = buf2_written = 0;\n" |
| 1466 |
" fd1 = fd;\n" |
| 1467 |
" fd2 = connect_socket(forward_port, argv[3]);\n" |
| 1468 |
" if (fd2 == -1)\n" |
| 1469 |
" SHUT_FD1;\n" |
| 1470 |
" else\n" |
| 1471 |
" printf(\"connexion depuis %s\\[rs]n\",\n" |
| 1472 |
" inet_ntoa(client_addr.sin_addr));\n" |
| 1473 |
"\\&\n" |
| 1474 |
" /* Passer les événements des anciens descripteurs de\n" |
| 1475 |
" fichier fermés. */\n" |
| 1476 |
"\\&\n" |
| 1477 |
" continue;\n" |
| 1478 |
" }\n" |
| 1479 |
" }\n" |
| 1480 |
"\\&\n" |
| 1481 |
" /* NB : lecture des données hors bande avant les lectures normales */\n" |
| 1482 |
"\\&\n" |
| 1483 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n" |
| 1484 |
" char c;\n" |
| 1485 |
"\\&\n" |
| 1486 |
" nbytes = recv(fd1, &c, 1, MSG_OOB);\n" |
| 1487 |
" if (nbytes E<lt> 1)\n" |
| 1488 |
" SHUT_FD1;\n" |
| 1489 |
" else\n" |
| 1490 |
" send(fd2, &c, 1, MSG_OOB);\n" |
| 1491 |
" }\n" |
| 1492 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n" |
| 1493 |
" char c;\n" |
| 1494 |
"\\&\n" |
| 1495 |
" nbytes = recv(fd2, &c, 1, MSG_OOB);\n" |
| 1496 |
" if (nbytes E<lt> 1)\n" |
| 1497 |
" SHUT_FD2;\n" |
| 1498 |
" else\n" |
| 1499 |
" send(fd1, &c, 1, MSG_OOB);\n" |
| 1500 |
" }\n" |
| 1501 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n" |
| 1502 |
" nbytes = read(fd1, buf1 + buf1_avail,\n" |
| 1503 |
" BUF_SIZE - buf1_avail);\n" |
| 1504 |
" if (nbytes E<lt> 1)\n" |
| 1505 |
" SHUT_FD1;\n" |
| 1506 |
" else\n" |
| 1507 |
" buf1_avail += nbytes;\n" |
| 1508 |
" }\n" |
| 1509 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n" |
| 1510 |
" nbytes = read(fd2, buf2 + buf2_avail,\n" |
| 1511 |
" BUF_SIZE - buf2_avail);\n" |
| 1512 |
" if (nbytes E<lt> 1)\n" |
| 1513 |
" SHUT_FD2;\n" |
| 1514 |
" else\n" |
| 1515 |
" buf2_avail += nbytes;\n" |
| 1516 |
" }\n" |
| 1517 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n" |
| 1518 |
" nbytes = write(fd1, buf2 + buf2_written,\n" |
| 1519 |
" buf2_avail - buf2_written);\n" |
| 1520 |
" if (nbytes E<lt> 1)\n" |
| 1521 |
" SHUT_FD1;\n" |
| 1522 |
" else\n" |
| 1523 |
" buf2_written += nbytes;\n" |
| 1524 |
" }\n" |
| 1525 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n" |
| 1526 |
" nbytes = write(fd2, buf1 + buf1_written,\n" |
| 1527 |
" buf1_avail - buf1_written);\n" |
| 1528 |
" if (nbytes E<lt> 1)\n" |
| 1529 |
" SHUT_FD2;\n" |
| 1530 |
" else\n" |
| 1531 |
" buf1_written += nbytes;\n" |
| 1532 |
" }\n" |
| 1533 |
"\\&\n" |
| 1534 |
" /* Vérifier si l'écriture de données a rattrapé la lecture de données */\n" |
| 1535 |
"\\&\n" |
| 1536 |
" if (buf1_written == buf1_avail)\n" |
| 1537 |
" buf1_written = buf1_avail = 0;\n" |
| 1538 |
" if (buf2_written == buf2_avail)\n" |
| 1539 |
" buf2_written = buf2_avail = 0;\n" |
| 1540 |
"\\&\n" |
| 1541 |
" /* une extrémité a fermé la connexion, continue\n" |
| 1542 |
" d'écrire vers l'autre extrémité jusqu'à ce\n" |
| 1543 |
" que ce soit vide */\n" |
| 1544 |
"\\&\n" |
| 1545 |
" if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n" |
| 1546 |
" SHUT_FD2;\n" |
| 1547 |
" if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n" |
| 1548 |
" SHUT_FD1;\n" |
| 1549 |
" }\n" |
| 1550 |
" exit(EXIT_SUCCESS);\n" |
| 1551 |
"}\n" |
| 1552 |
|
| 1553 |
# NOTE: timeouts => expirations ? (pas que ici) |
| 1554 |
#. type: Plain text |
| 1555 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1556 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1557 |
msgid "" |
| 1558 |
"The above program properly forwards most kinds of TCP connections including " |
| 1559 |
"OOB signal data transmitted by B<telnet> servers. It handles the tricky " |
| 1560 |
"problem of having data flow in both directions simultaneously. You might " |
| 1561 |
"think it more efficient to use a B<fork>(2) call and devote a thread to " |
| 1562 |
"each stream. This becomes more tricky than you might suspect. Another idea " |
| 1563 |
"is to set nonblocking I/O using B<fcntl>(2). This also has its problems " |
| 1564 |
"because you end up using inefficient timeouts." |
| 1565 |
msgstr "" |
| 1566 |
"Le programme ci-dessus redirige correctement la plupart des types de " |
| 1567 |
"connexions TCP y compris les signaux de données hors bande OOB transmis par " |
| 1568 |
"les serveurs B<telnet>. Il gère le problème épineux des flux de données " |
| 1569 |
"bidirectionnels simultanés. Vous pourriez penser qu'il est plus efficace " |
| 1570 |
"d'utiliser un appel B<fork>(2) et de dédier une tâche à chaque flux. Cela " |
| 1571 |
"devient alors plus délicat que vous ne l'imaginez. Une autre idée est de " |
| 1572 |
"configurer les entrées-sorties comme non bloquantes en utilisant " |
| 1573 |
"B<fcntl>(2). Cela pose également problème puisque ça vous force à utiliser " |
| 1574 |
"des timeouts inefficaces." |
| 1575 |
|
| 1576 |
#. type: Plain text |
| 1577 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1578 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1579 |
msgid "" |
| 1580 |
"The program does not handle more than one simultaneous connection at a time, " |
| 1581 |
"although it could easily be extended to do this with a linked list of " |
| 1582 |
"buffers\\[em]one for each connection. At the moment, new connections cause " |
| 1583 |
"the current connection to be dropped." |
| 1584 |
msgstr "" |
| 1585 |
"Le programme ne gère pas plus d'une connexion à la fois bien qu'il soit " |
| 1586 |
"aisément extensible à une telle fonctionnalité en utilisant une liste " |
| 1587 |
"chaînée de tampons \\[em] un pour chaque connexion. Pour l'instant, de " |
| 1588 |
"nouvelles connexions provoquent l'abandon de la connexion courante." |
| 1589 |
|
| 1590 |
#. type: SH |
| 1591 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1592 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1593 |
#, no-wrap |
| 1594 |
msgid "SEE ALSO" |
| 1595 |
msgstr "VOIR AUSSI" |
| 1596 |
|
| 1597 |
#. type: Plain text |
| 1598 |
#: archlinux debian-trixie debian-unstable fedora-44 fedora-rawhide |
| 1599 |
#: mageia-cauldron opensuse-leap-16-1 opensuse-tumbleweed |
| 1600 |
msgid "" |
| 1601 |
"B<accept>(2), B<connect>(2), B<poll>(2), B<read>(2), B<recv>(2), " |
| 1602 |
"B<select>(2), B<send>(2), B<sigprocmask>(2), B<write>(2), B<epoll>(7)" |
| 1603 |
msgstr "" |
| 1604 |
"B<accept>(2), B<connect>(2), B<poll>(2), B<read>(2), B<recv>(2), " |
| 1605 |
"B<select>(2), B<send>(2), B<sigprocmask>(2), B<write>(2), B<epoll>(7)" |
| 1606 |
|
| 1607 |
#. type: TH |
| 1608 |
#: debian-trixie |
| 1609 |
#, no-wrap |
| 1610 |
msgid "2024-06-15" |
| 1611 |
msgstr "15 juin 2024" |
| 1612 |
|
| 1613 |
#. type: TH |
| 1614 |
#: debian-trixie |
| 1615 |
#, no-wrap |
| 1616 |
msgid "Linux man-pages 6.9.1" |
| 1617 |
msgstr "Pages du manuel de Linux 6.9.1" |
| 1618 |
|
| 1619 |
#. type: Plain text |
| 1620 |
#: debian-trixie |
| 1621 |
msgid "Standard C library (I<libc>, I<-lc>)" |
| 1622 |
msgstr "Bibliothèque C standard (I<libc>, I<-lc>)" |
| 1623 |
|
| 1624 |
#. type: Plain text |
| 1625 |
#: debian-trixie fedora-44 fedora-rawhide |
| 1626 |
#, no-wrap |
| 1627 |
msgid "" |
| 1628 |
"static volatile sig_atomic_t got_SIGCHLD = 0;\n" |
| 1629 |
"\\&\n" |
| 1630 |
"static void\n" |
| 1631 |
"child_sig_handler(int sig)\n" |
| 1632 |
"{\n" |
| 1633 |
" got_SIGCHLD = 1;\n" |
| 1634 |
"}\n" |
| 1635 |
"\\&\n" |
| 1636 |
"int\n" |
| 1637 |
"main(int argc, char *argv[])\n" |
| 1638 |
"{\n" |
| 1639 |
" sigset_t sigmask, empty_mask;\n" |
| 1640 |
" struct sigaction sa;\n" |
| 1641 |
" fd_set readfds, writefds, exceptfds;\n" |
| 1642 |
" int r;\n" |
| 1643 |
"\\&\n" |
| 1644 |
" sigemptyset(&sigmask);\n" |
| 1645 |
" sigaddset(&sigmask, SIGCHLD);\n" |
| 1646 |
" if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" |
| 1647 |
" perror(\"sigprocmask\");\n" |
| 1648 |
" exit(EXIT_FAILURE);\n" |
| 1649 |
" }\n" |
| 1650 |
"\\&\n" |
| 1651 |
" sa.sa_flags = 0;\n" |
| 1652 |
" sa.sa_handler = child_sig_handler;\n" |
| 1653 |
" sigemptyset(&sa.sa_mask);\n" |
| 1654 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" |
| 1655 |
" perror(\"sigaction\");\n" |
| 1656 |
" exit(EXIT_FAILURE);\n" |
| 1657 |
" }\n" |
| 1658 |
"\\&\n" |
| 1659 |
" sigemptyset(&empty_mask);\n" |
| 1660 |
"\\&\n" |
| 1661 |
" for (;;) { /* main loop */\n" |
| 1662 |
" /* Initialize readfds, writefds, and exceptfds\n" |
| 1663 |
" before the pselect() call. (Code omitted.) */\n" |
| 1664 |
"\\&\n" |
| 1665 |
" r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" |
| 1666 |
" NULL, &empty_mask);\n" |
| 1667 |
" if (r == -1 && errno != EINTR) {\n" |
| 1668 |
" /* Handle error */\n" |
| 1669 |
" }\n" |
| 1670 |
"\\&\n" |
| 1671 |
" if (got_SIGCHLD) {\n" |
| 1672 |
" got_SIGCHLD = 0;\n" |
| 1673 |
"\\&\n" |
| 1674 |
" /* Handle signalled event here; e.g., wait() for all\n" |
| 1675 |
" terminated children. (Code omitted.) */\n" |
| 1676 |
" }\n" |
| 1677 |
"\\&\n" |
| 1678 |
" /* main body of program */\n" |
| 1679 |
" }\n" |
| 1680 |
"}\n" |
| 1681 |
msgstr "" |
| 1682 |
"static volatile sig_atomic_t got_SIGCHLD = 0;\n" |
| 1683 |
"\\&\n" |
| 1684 |
"static void\n" |
| 1685 |
"child_sig_handler(int sig)\n" |
| 1686 |
"{\n" |
| 1687 |
" got_SIGCHLD = 1;\n" |
| 1688 |
"}\n" |
| 1689 |
"\\&\n" |
| 1690 |
"int\n" |
| 1691 |
"main(int argc, char *argv[])\n" |
| 1692 |
"{\n" |
| 1693 |
" sigset_t sigmask, empty_mask;\n" |
| 1694 |
" struct sigaction sa;\n" |
| 1695 |
" fd_set readfds, writefds, exceptfds;\n" |
| 1696 |
" int r;\n" |
| 1697 |
"\\&\n" |
| 1698 |
" sigemptyset(&sigmask);\n" |
| 1699 |
" sigaddset(&sigmask, SIGCHLD);\n" |
| 1700 |
" if (sigprocmask(SIG_BLOCK, &sigmask, NULL) == -1) {\n" |
| 1701 |
" perror(\"sigprocmask\");\n" |
| 1702 |
" exit(EXIT_FAILURE);\n" |
| 1703 |
" }\n" |
| 1704 |
"\\&\n" |
| 1705 |
" sa.sa_flags = 0;\n" |
| 1706 |
" sa.sa_handler = child_sig_handler;\n" |
| 1707 |
" sigemptyset(&sa.sa_mask);\n" |
| 1708 |
" if (sigaction(SIGCHLD, &sa, NULL) == -1) {\n" |
| 1709 |
" perror(\"sigaction\");\n" |
| 1710 |
" exit(EXIT_FAILURE);\n" |
| 1711 |
" }\n" |
| 1712 |
"\\&\n" |
| 1713 |
" sigemptyset(&empty_mask);\n" |
| 1714 |
"\\&\n" |
| 1715 |
" for (;;) { /* main loop */\n" |
| 1716 |
" /* Initialiser readfds, writefds et exceptfds\n" |
| 1717 |
" avant l'appel à pselect(). (Code omis.) */\n" |
| 1718 |
"\\&\n" |
| 1719 |
" r = pselect(nfds, &readfds, &writefds, &exceptfds,\n" |
| 1720 |
" NULL, &empty_mask);\n" |
| 1721 |
" if (r == -1 && errno != EINTR) {\n" |
| 1722 |
" /* Handle error */\n" |
| 1723 |
" }\n" |
| 1724 |
"\\&\n" |
| 1725 |
" if (got_SIGCHLD) {\n" |
| 1726 |
" got_SIGCHLD = 0;\n" |
| 1727 |
"\\&\n" |
| 1728 |
" /* Gérer les événements signalés ici; e.g., wait() pour\n" |
| 1729 |
" que tous les enfants se terminent. (Code omis.) */\n" |
| 1730 |
" }\n" |
| 1731 |
"\\&\n" |
| 1732 |
" /* corps principal du programme */\n" |
| 1733 |
" }\n" |
| 1734 |
"}\n" |
| 1735 |
|
| 1736 |
#. type: Plain text |
| 1737 |
#: debian-trixie fedora-44 fedora-rawhide |
| 1738 |
#, no-wrap |
| 1739 |
msgid "" |
| 1740 |
"#include E<lt>arpa/inet.hE<gt>\n" |
| 1741 |
"#include E<lt>errno.hE<gt>\n" |
| 1742 |
"#include E<lt>netinet/in.hE<gt>\n" |
| 1743 |
"#include E<lt>signal.hE<gt>\n" |
| 1744 |
"#include E<lt>stdio.hE<gt>\n" |
| 1745 |
"#include E<lt>stdlib.hE<gt>\n" |
| 1746 |
"#include E<lt>string.hE<gt>\n" |
| 1747 |
"#include E<lt>sys/select.hE<gt>\n" |
| 1748 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 1749 |
"#include E<lt>sys/types.hE<gt>\n" |
| 1750 |
"#include E<lt>unistd.hE<gt>\n" |
| 1751 |
"\\&\n" |
| 1752 |
"static int forward_port;\n" |
| 1753 |
"\\&\n" |
| 1754 |
"#undef max\n" |
| 1755 |
"#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n" |
| 1756 |
"\\&\n" |
| 1757 |
"static int\n" |
| 1758 |
"listen_socket(int listen_port)\n" |
| 1759 |
"{\n" |
| 1760 |
" int lfd;\n" |
| 1761 |
" int yes;\n" |
| 1762 |
" struct sockaddr_in addr;\n" |
| 1763 |
"\\&\n" |
| 1764 |
" lfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 1765 |
" if (lfd == -1) {\n" |
| 1766 |
" perror(\"socket\");\n" |
| 1767 |
" return -1;\n" |
| 1768 |
" }\n" |
| 1769 |
"\\&\n" |
| 1770 |
" yes = 1;\n" |
| 1771 |
" if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" |
| 1772 |
" &yes, sizeof(yes)) == -1)\n" |
| 1773 |
" {\n" |
| 1774 |
" perror(\"setsockopt\");\n" |
| 1775 |
" close(lfd);\n" |
| 1776 |
" return -1;\n" |
| 1777 |
" }\n" |
| 1778 |
"\\&\n" |
| 1779 |
" memset(&addr, 0, sizeof(addr));\n" |
| 1780 |
" addr.sin_port = htons(listen_port);\n" |
| 1781 |
" addr.sin_family = AF_INET;\n" |
| 1782 |
" if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 1783 |
" perror(\"bind\");\n" |
| 1784 |
" close(lfd);\n" |
| 1785 |
" return -1;\n" |
| 1786 |
" }\n" |
| 1787 |
"\\&\n" |
| 1788 |
" printf(\"accepting connections on port %d\\[rs]n\", listen_port);\n" |
| 1789 |
" listen(lfd, 10);\n" |
| 1790 |
" return lfd;\n" |
| 1791 |
"}\n" |
| 1792 |
"\\&\n" |
| 1793 |
"static int\n" |
| 1794 |
"connect_socket(int connect_port, char *address)\n" |
| 1795 |
"{\n" |
| 1796 |
" int cfd;\n" |
| 1797 |
" struct sockaddr_in addr;\n" |
| 1798 |
"\\&\n" |
| 1799 |
" cfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 1800 |
" if (cfd == -1) {\n" |
| 1801 |
" perror(\"socket\");\n" |
| 1802 |
" return -1;\n" |
| 1803 |
" }\n" |
| 1804 |
"\\&\n" |
| 1805 |
" memset(&addr, 0, sizeof(addr));\n" |
| 1806 |
" addr.sin_port = htons(connect_port);\n" |
| 1807 |
" addr.sin_family = AF_INET;\n" |
| 1808 |
"\\&\n" |
| 1809 |
" if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" |
| 1810 |
" fprintf(stderr, \"inet_aton(): bad IP address format\\[rs]n\");\n" |
| 1811 |
" close(cfd);\n" |
| 1812 |
" return -1;\n" |
| 1813 |
" }\n" |
| 1814 |
"\\&\n" |
| 1815 |
" if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 1816 |
" perror(\"connect()\");\n" |
| 1817 |
" shutdown(cfd, SHUT_RDWR);\n" |
| 1818 |
" close(cfd);\n" |
| 1819 |
" return -1;\n" |
| 1820 |
" }\n" |
| 1821 |
" return cfd;\n" |
| 1822 |
"}\n" |
| 1823 |
"\\&\n" |
| 1824 |
"#define SHUT_FD1 do { \\[rs]\n" |
| 1825 |
" if (fd1 E<gt>= 0) { \\[rs]\n" |
| 1826 |
" shutdown(fd1, SHUT_RDWR); \\[rs]\n" |
| 1827 |
" close(fd1); \\[rs]\n" |
| 1828 |
" fd1 = -1; \\[rs]\n" |
| 1829 |
" } \\[rs]\n" |
| 1830 |
" } while (0)\n" |
| 1831 |
"\\&\n" |
| 1832 |
"#define SHUT_FD2 do { \\[rs]\n" |
| 1833 |
" if (fd2 E<gt>= 0) { \\[rs]\n" |
| 1834 |
" shutdown(fd2, SHUT_RDWR); \\[rs]\n" |
| 1835 |
" close(fd2); \\[rs]\n" |
| 1836 |
" fd2 = -1; \\[rs]\n" |
| 1837 |
" } \\[rs]\n" |
| 1838 |
" } while (0)\n" |
| 1839 |
"\\&\n" |
| 1840 |
"#define BUF_SIZE 1024\n" |
| 1841 |
"\\&\n" |
| 1842 |
"int\n" |
| 1843 |
"main(int argc, char *argv[])\n" |
| 1844 |
"{\n" |
| 1845 |
" int h;\n" |
| 1846 |
" int ready, nfds;\n" |
| 1847 |
" int fd1 = -1, fd2 = -1;\n" |
| 1848 |
" int buf1_avail = 0, buf1_written = 0;\n" |
| 1849 |
" int buf2_avail = 0, buf2_written = 0;\n" |
| 1850 |
" char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" |
| 1851 |
" fd_set readfds, writefds, exceptfds;\n" |
| 1852 |
" ssize_t nbytes;\n" |
| 1853 |
"\\&\n" |
| 1854 |
" if (argc != 4) {\n" |
| 1855 |
" fprintf(stderr, \"Usage\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n" |
| 1856 |
" \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n" |
| 1857 |
" exit(EXIT_FAILURE);\n" |
| 1858 |
" }\n" |
| 1859 |
"\\&\n" |
| 1860 |
" signal(SIGPIPE, SIG_IGN);\n" |
| 1861 |
"\\&\n" |
| 1862 |
" forward_port = atoi(argv[2]);\n" |
| 1863 |
"\\&\n" |
| 1864 |
" h = listen_socket(atoi(argv[1]));\n" |
| 1865 |
" if (h == -1)\n" |
| 1866 |
" exit(EXIT_FAILURE);\n" |
| 1867 |
"\\&\n" |
| 1868 |
" for (;;) {\n" |
| 1869 |
" nfds = 0;\n" |
| 1870 |
"\\&\n" |
| 1871 |
" FD_ZERO(&readfds);\n" |
| 1872 |
" FD_ZERO(&writefds);\n" |
| 1873 |
" FD_ZERO(&exceptfds);\n" |
| 1874 |
" FD_SET(h, &readfds);\n" |
| 1875 |
" nfds = max(nfds, h);\n" |
| 1876 |
"\\&\n" |
| 1877 |
" if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n" |
| 1878 |
" FD_SET(fd1, &readfds);\n" |
| 1879 |
" /* Note: nfds is updated below, when fd1 is added to\n" |
| 1880 |
" exceptfds. */\n" |
| 1881 |
" if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n" |
| 1882 |
" FD_SET(fd2, &readfds);\n" |
| 1883 |
"\\&\n" |
| 1884 |
" if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n" |
| 1885 |
" FD_SET(fd1, &writefds);\n" |
| 1886 |
" if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n" |
| 1887 |
" FD_SET(fd2, &writefds);\n" |
| 1888 |
"\\&\n" |
| 1889 |
" if (fd1 E<gt> 0) {\n" |
| 1890 |
" FD_SET(fd1, &exceptfds);\n" |
| 1891 |
" nfds = max(nfds, fd1);\n" |
| 1892 |
" }\n" |
| 1893 |
" if (fd2 E<gt> 0) {\n" |
| 1894 |
" FD_SET(fd2, &exceptfds);\n" |
| 1895 |
" nfds = max(nfds, fd2);\n" |
| 1896 |
" }\n" |
| 1897 |
"\\&\n" |
| 1898 |
" ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" |
| 1899 |
"\\&\n" |
| 1900 |
" if (ready == -1 && errno == EINTR)\n" |
| 1901 |
" continue;\n" |
| 1902 |
"\\&\n" |
| 1903 |
" if (ready == -1) {\n" |
| 1904 |
" perror(\"select()\");\n" |
| 1905 |
" exit(EXIT_FAILURE);\n" |
| 1906 |
" }\n" |
| 1907 |
"\\&\n" |
| 1908 |
" if (FD_ISSET(h, &readfds)) {\n" |
| 1909 |
" socklen_t addrlen;\n" |
| 1910 |
" struct sockaddr_in client_addr;\n" |
| 1911 |
" int fd;\n" |
| 1912 |
"\\&\n" |
| 1913 |
" addrlen = sizeof(client_addr);\n" |
| 1914 |
" memset(&client_addr, 0, addrlen);\n" |
| 1915 |
" fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" |
| 1916 |
" if (fd == -1) {\n" |
| 1917 |
" perror(\"accept()\");\n" |
| 1918 |
" } else {\n" |
| 1919 |
" SHUT_FD1;\n" |
| 1920 |
" SHUT_FD2;\n" |
| 1921 |
" buf1_avail = buf1_written = 0;\n" |
| 1922 |
" buf2_avail = buf2_written = 0;\n" |
| 1923 |
" fd1 = fd;\n" |
| 1924 |
" fd2 = connect_socket(forward_port, argv[3]);\n" |
| 1925 |
" if (fd2 == -1)\n" |
| 1926 |
" SHUT_FD1;\n" |
| 1927 |
" else\n" |
| 1928 |
" printf(\"connect from %s\\[rs]n\",\n" |
| 1929 |
" inet_ntoa(client_addr.sin_addr));\n" |
| 1930 |
"\\&\n" |
| 1931 |
" /* Skip any events on the old, closed file\n" |
| 1932 |
" descriptors. */\n" |
| 1933 |
"\\&\n" |
| 1934 |
" continue;\n" |
| 1935 |
" }\n" |
| 1936 |
" }\n" |
| 1937 |
"\\&\n" |
| 1938 |
" /* NB: read OOB data before normal reads. */\n" |
| 1939 |
"\\&\n" |
| 1940 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n" |
| 1941 |
" char c;\n" |
| 1942 |
"\\&\n" |
| 1943 |
" nbytes = recv(fd1, &c, 1, MSG_OOB);\n" |
| 1944 |
" if (nbytes E<lt> 1)\n" |
| 1945 |
" SHUT_FD1;\n" |
| 1946 |
" else\n" |
| 1947 |
" send(fd2, &c, 1, MSG_OOB);\n" |
| 1948 |
" }\n" |
| 1949 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n" |
| 1950 |
" char c;\n" |
| 1951 |
"\\&\n" |
| 1952 |
" nbytes = recv(fd2, &c, 1, MSG_OOB);\n" |
| 1953 |
" if (nbytes E<lt> 1)\n" |
| 1954 |
" SHUT_FD2;\n" |
| 1955 |
" else\n" |
| 1956 |
" send(fd1, &c, 1, MSG_OOB);\n" |
| 1957 |
" }\n" |
| 1958 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n" |
| 1959 |
" nbytes = read(fd1, buf1 + buf1_avail,\n" |
| 1960 |
" BUF_SIZE - buf1_avail);\n" |
| 1961 |
" if (nbytes E<lt> 1)\n" |
| 1962 |
" SHUT_FD1;\n" |
| 1963 |
" else\n" |
| 1964 |
" buf1_avail += nbytes;\n" |
| 1965 |
" }\n" |
| 1966 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n" |
| 1967 |
" nbytes = read(fd2, buf2 + buf2_avail,\n" |
| 1968 |
" BUF_SIZE - buf2_avail);\n" |
| 1969 |
" if (nbytes E<lt> 1)\n" |
| 1970 |
" SHUT_FD2;\n" |
| 1971 |
" else\n" |
| 1972 |
" buf2_avail += nbytes;\n" |
| 1973 |
" }\n" |
| 1974 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n" |
| 1975 |
" nbytes = write(fd1, buf2 + buf2_written,\n" |
| 1976 |
" buf2_avail - buf2_written);\n" |
| 1977 |
" if (nbytes E<lt> 1)\n" |
| 1978 |
" SHUT_FD1;\n" |
| 1979 |
" else\n" |
| 1980 |
" buf2_written += nbytes;\n" |
| 1981 |
" }\n" |
| 1982 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n" |
| 1983 |
" nbytes = write(fd2, buf1 + buf1_written,\n" |
| 1984 |
" buf1_avail - buf1_written);\n" |
| 1985 |
" if (nbytes E<lt> 1)\n" |
| 1986 |
" SHUT_FD2;\n" |
| 1987 |
" else\n" |
| 1988 |
" buf1_written += nbytes;\n" |
| 1989 |
" }\n" |
| 1990 |
"\\&\n" |
| 1991 |
" /* Check if write data has caught read data. */\n" |
| 1992 |
"\\&\n" |
| 1993 |
" if (buf1_written == buf1_avail)\n" |
| 1994 |
" buf1_written = buf1_avail = 0;\n" |
| 1995 |
" if (buf2_written == buf2_avail)\n" |
| 1996 |
" buf2_written = buf2_avail = 0;\n" |
| 1997 |
"\\&\n" |
| 1998 |
" /* One side has closed the connection, keep\n" |
| 1999 |
" writing to the other side until empty. */\n" |
| 2000 |
"\\&\n" |
| 2001 |
" if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n" |
| 2002 |
" SHUT_FD2;\n" |
| 2003 |
" if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n" |
| 2004 |
" SHUT_FD1;\n" |
| 2005 |
" }\n" |
| 2006 |
" exit(EXIT_SUCCESS);\n" |
| 2007 |
"}\n" |
| 2008 |
msgstr "" |
| 2009 |
"#include E<lt>arpa/inet.hE<gt>\n" |
| 2010 |
"#include E<lt>errno.hE<gt>\n" |
| 2011 |
"#include E<lt>netinet/in.hE<gt>\n" |
| 2012 |
"#include E<lt>signal.hE<gt>\n" |
| 2013 |
"#include E<lt>stdio.hE<gt>\n" |
| 2014 |
"#include E<lt>stdlib.hE<gt>\n" |
| 2015 |
"#include E<lt>string.hE<gt>\n" |
| 2016 |
"#include E<lt>sys/select.hE<gt>\n" |
| 2017 |
"#include E<lt>sys/socket.hE<gt>\n" |
| 2018 |
"#include E<lt>sys/types.hE<gt>\n" |
| 2019 |
"#include E<lt>unistd.hE<gt>\n" |
| 2020 |
"\\&\n" |
| 2021 |
"static int forward_port;\n" |
| 2022 |
"\\&\n" |
| 2023 |
"#undef max\n" |
| 2024 |
"#define max(x, y) ((x) E<gt> (y) ? (x) : (y))\n" |
| 2025 |
"\\&\n" |
| 2026 |
"static int\n" |
| 2027 |
"listen_socket(int listen_port)\n" |
| 2028 |
"{\n" |
| 2029 |
" int lfd;\n" |
| 2030 |
" int yes;\n" |
| 2031 |
" struct sockaddr_in addr;\n" |
| 2032 |
"\\&\n" |
| 2033 |
" lfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 2034 |
" if (lfd == -1) {\n" |
| 2035 |
" perror(\"socket\");\n" |
| 2036 |
" return -1;\n" |
| 2037 |
" }\n" |
| 2038 |
"\\&\n" |
| 2039 |
" yes = 1;\n" |
| 2040 |
" if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR,\n" |
| 2041 |
" &yes, sizeof(yes)) == -1)\n" |
| 2042 |
" {\n" |
| 2043 |
" perror(\"setsockopt\");\n" |
| 2044 |
" close(lfd);\n" |
| 2045 |
" return -1;\n" |
| 2046 |
" }\n" |
| 2047 |
"\\&\n" |
| 2048 |
" memset(&addr, 0, sizeof(addr));\n" |
| 2049 |
" addr.sin_port = htons(listen_port);\n" |
| 2050 |
" addr.sin_family = AF_INET;\n" |
| 2051 |
" if (bind(lfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 2052 |
" perror(\"bind\");\n" |
| 2053 |
" close(lfd);\n" |
| 2054 |
" return -1;\n" |
| 2055 |
" }\n" |
| 2056 |
"\\&\n" |
| 2057 |
" printf(\"on accepte les connexions sur le port %d\\[rs]n\", listen_port);\n" |
| 2058 |
" listen(lfd, 10);\n" |
| 2059 |
" return lfd;\n" |
| 2060 |
"}\n" |
| 2061 |
"\\&\n" |
| 2062 |
"static int\n" |
| 2063 |
"connect_socket(int connect_port, char *address)\n" |
| 2064 |
"{\n" |
| 2065 |
" int cfd;\n" |
| 2066 |
" struct sockaddr_in addr;\n" |
| 2067 |
"\\&\n" |
| 2068 |
" cfd = socket(AF_INET, SOCK_STREAM, 0);\n" |
| 2069 |
" if (cfd == -1) {\n" |
| 2070 |
" perror(\"socket\");\n" |
| 2071 |
" return -1;\n" |
| 2072 |
" }\n" |
| 2073 |
"\\&\n" |
| 2074 |
" memset(&addr, 0, sizeof(addr));\n" |
| 2075 |
" addr.sin_port = htons(connect_port);\n" |
| 2076 |
" addr.sin_family = AF_INET;\n" |
| 2077 |
"\\&\n" |
| 2078 |
" if (!inet_aton(address, (struct in_addr *) &addr.sin_addr.s_addr)) {\n" |
| 2079 |
" fprintf(stderr, \"inet_aton(): mauvais format d'adresse IP\\[rs]n\");\n" |
| 2080 |
" close(cfd);\n" |
| 2081 |
" return -1;\n" |
| 2082 |
" }\n" |
| 2083 |
"\\&\n" |
| 2084 |
" if (connect(cfd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {\n" |
| 2085 |
" perror(\"connect()\");\n" |
| 2086 |
" shutdown(cfd, SHUT_RDWR);\n" |
| 2087 |
" close(cfd);\n" |
| 2088 |
" return -1;\n" |
| 2089 |
" }\n" |
| 2090 |
" return cfd;\n" |
| 2091 |
"}\n" |
| 2092 |
"\\&\n" |
| 2093 |
"#define SHUT_FD1 do { \\[rs]\n" |
| 2094 |
" if (fd1 E<gt>= 0) { \\[rs]\n" |
| 2095 |
" shutdown(fd1, SHUT_RDWR); \\[rs]\n" |
| 2096 |
" close(fd1); \\[rs]\n" |
| 2097 |
" fd1 = -1; \\[rs]\n" |
| 2098 |
" } \\[rs]\n" |
| 2099 |
" } while (0)\n" |
| 2100 |
"\\&\n" |
| 2101 |
"#define SHUT_FD2 do { \\[rs]\n" |
| 2102 |
" if (fd2 E<gt>= 0) { \\[rs]\n" |
| 2103 |
" shutdown(fd2, SHUT_RDWR); \\[rs]\n" |
| 2104 |
" close(fd2); \\[rs]\n" |
| 2105 |
" fd2 = -1; \\[rs]\n" |
| 2106 |
" } \\[rs]\n" |
| 2107 |
" } while (0)\n" |
| 2108 |
"\\&\n" |
| 2109 |
"#define BUF_SIZE 1024\n" |
| 2110 |
"\\&\n" |
| 2111 |
"int\n" |
| 2112 |
"main(int argc, char *argv[])\n" |
| 2113 |
"{\n" |
| 2114 |
" int h;\n" |
| 2115 |
" int ready, nfds;\n" |
| 2116 |
" int fd1 = -1, fd2 = -1;\n" |
| 2117 |
" int buf1_avail = 0, buf1_written = 0;\n" |
| 2118 |
" int buf2_avail = 0, buf2_written = 0;\n" |
| 2119 |
" char buf1[BUF_SIZE], buf2[BUF_SIZE];\n" |
| 2120 |
" fd_set readfds, writefds, exceptfds;\n" |
| 2121 |
" ssize_t nbytes;\n" |
| 2122 |
"\\&\n" |
| 2123 |
" if (argc != 4) {\n" |
| 2124 |
" fprintf(stderr, \"Utilisation\\[rs]n\\[rs]tfwd E<lt>listen-portE<gt> \"\n" |
| 2125 |
" \"E<lt>forward-to-portE<gt> E<lt>forward-to-ip-addressE<gt>\\[rs]n\");\n" |
| 2126 |
" exit(EXIT_FAILURE);\n" |
| 2127 |
" }\n" |
| 2128 |
"\\&\n" |
| 2129 |
" signal(SIGPIPE, SIG_IGN);\n" |
| 2130 |
"\\&\n" |
| 2131 |
" forward_port = atoi(argv[2]);\n" |
| 2132 |
"\\&\n" |
| 2133 |
" h = listen_socket(atoi(argv[1]));\n" |
| 2134 |
" if (h == -1)\n" |
| 2135 |
" exit(EXIT_FAILURE);\n" |
| 2136 |
"\\&\n" |
| 2137 |
" for (;;) {\n" |
| 2138 |
" nfds = 0;\n" |
| 2139 |
"\\&\n" |
| 2140 |
" FD_ZERO(&readfds);\n" |
| 2141 |
" FD_ZERO(&writefds);\n" |
| 2142 |
" FD_ZERO(&exceptfds);\n" |
| 2143 |
" FD_SET(h, &readfds);\n" |
| 2144 |
" nfds = max(nfds, h);\n" |
| 2145 |
"\\&\n" |
| 2146 |
" if (fd1 E<gt> 0 && buf1_avail E<lt> BUF_SIZE)\n" |
| 2147 |
" FD_SET(fd1, &readfds);\n" |
| 2148 |
" /* Note: nfds est mis à jour ci-dessous, lorsque fd1\n" |
| 2149 |
" est ajouté à exceptfds. */\n" |
| 2150 |
" if (fd2 E<gt> 0 && buf2_avail E<lt> BUF_SIZE)\n" |
| 2151 |
" FD_SET(fd2, &readfds);\n" |
| 2152 |
"\\&\n" |
| 2153 |
" if (fd1 E<gt> 0 && buf2_avail - buf2_written E<gt> 0)\n" |
| 2154 |
" FD_SET(fd1, &writefds);\n" |
| 2155 |
" if (fd2 E<gt> 0 && buf1_avail - buf1_written E<gt> 0)\n" |
| 2156 |
" FD_SET(fd2, &writefds);\n" |
| 2157 |
"\\&\n" |
| 2158 |
" if (fd1 E<gt> 0) {\n" |
| 2159 |
" FD_SET(fd1, &exceptfds);\n" |
| 2160 |
" nfds = max(nfds, fd1);\n" |
| 2161 |
" }\n" |
| 2162 |
" if (fd2 E<gt> 0) {\n" |
| 2163 |
" FD_SET(fd2, &exceptfds);\n" |
| 2164 |
" nfds = max(nfds, fd2);\n" |
| 2165 |
" }\n" |
| 2166 |
"\\&\n" |
| 2167 |
" ready = select(nfds + 1, &readfds, &writefds, &exceptfds, NULL);\n" |
| 2168 |
"\\&\n" |
| 2169 |
" if (ready == -1 && errno == EINTR)\n" |
| 2170 |
" continue;\n" |
| 2171 |
"\\&\n" |
| 2172 |
" if (ready == -1) {\n" |
| 2173 |
" perror(\"select()\");\n" |
| 2174 |
" exit(EXIT_FAILURE);\n" |
| 2175 |
" }\n" |
| 2176 |
"\\&\n" |
| 2177 |
" if (FD_ISSET(h, &readfds)) {\n" |
| 2178 |
" socklen_t addrlen;\n" |
| 2179 |
" struct sockaddr_in client_addr;\n" |
| 2180 |
" int fd;\n" |
| 2181 |
"\\&\n" |
| 2182 |
" addrlen = sizeof(client_addr);\n" |
| 2183 |
" memset(&client_addr, 0, addrlen);\n" |
| 2184 |
" fd = accept(h, (struct sockaddr *) &client_addr, &addrlen);\n" |
| 2185 |
" if (fd == -1) {\n" |
| 2186 |
" perror(\"accept()\");\n" |
| 2187 |
" } else {\n" |
| 2188 |
" SHUT_FD1;\n" |
| 2189 |
" SHUT_FD2;\n" |
| 2190 |
" buf1_avail = buf1_written = 0;\n" |
| 2191 |
" buf2_avail = buf2_written = 0;\n" |
| 2192 |
" fd1 = fd;\n" |
| 2193 |
" fd2 = connect_socket(forward_port, argv[3]);\n" |
| 2194 |
" if (fd2 == -1)\n" |
| 2195 |
" SHUT_FD1;\n" |
| 2196 |
" else\n" |
| 2197 |
" printf(\"connexion depuis %s\\[rs]n\",\n" |
| 2198 |
" inet_ntoa(client_addr.sin_addr));\n" |
| 2199 |
"\\&\n" |
| 2200 |
" /* Passer les événements des anciens descripteurs de\n" |
| 2201 |
" fichier fermés. */\n" |
| 2202 |
"\\&\n" |
| 2203 |
" continue;\n" |
| 2204 |
" }\n" |
| 2205 |
" }\n" |
| 2206 |
"\\&\n" |
| 2207 |
" /* NB : lecture des données hors bande avant les lectures normales */\n" |
| 2208 |
"\\&\n" |
| 2209 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &exceptfds)) {\n" |
| 2210 |
" char c;\n" |
| 2211 |
"\\&\n" |
| 2212 |
" nbytes = recv(fd1, &c, 1, MSG_OOB);\n" |
| 2213 |
" if (nbytes E<lt> 1)\n" |
| 2214 |
" SHUT_FD1;\n" |
| 2215 |
" else\n" |
| 2216 |
" send(fd2, &c, 1, MSG_OOB);\n" |
| 2217 |
" }\n" |
| 2218 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &exceptfds)) {\n" |
| 2219 |
" char c;\n" |
| 2220 |
"\\&\n" |
| 2221 |
" nbytes = recv(fd2, &c, 1, MSG_OOB);\n" |
| 2222 |
" if (nbytes E<lt> 1)\n" |
| 2223 |
" SHUT_FD2;\n" |
| 2224 |
" else\n" |
| 2225 |
" send(fd1, &c, 1, MSG_OOB);\n" |
| 2226 |
" }\n" |
| 2227 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &readfds)) {\n" |
| 2228 |
" nbytes = read(fd1, buf1 + buf1_avail,\n" |
| 2229 |
" BUF_SIZE - buf1_avail);\n" |
| 2230 |
" if (nbytes E<lt> 1)\n" |
| 2231 |
" SHUT_FD1;\n" |
| 2232 |
" else\n" |
| 2233 |
" buf1_avail += nbytes;\n" |
| 2234 |
" }\n" |
| 2235 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &readfds)) {\n" |
| 2236 |
" nbytes = read(fd2, buf2 + buf2_avail,\n" |
| 2237 |
" BUF_SIZE - buf2_avail);\n" |
| 2238 |
" if (nbytes E<lt> 1)\n" |
| 2239 |
" SHUT_FD2;\n" |
| 2240 |
" else\n" |
| 2241 |
" buf2_avail += nbytes;\n" |
| 2242 |
" }\n" |
| 2243 |
" if (fd1 E<gt> 0 && FD_ISSET(fd1, &writefds) && buf2_avail E<gt> 0) {\n" |
| 2244 |
" nbytes = write(fd1, buf2 + buf2_written,\n" |
| 2245 |
" buf2_avail - buf2_written);\n" |
| 2246 |
" if (nbytes E<lt> 1)\n" |
| 2247 |
" SHUT_FD1;\n" |
| 2248 |
" else\n" |
| 2249 |
" buf2_written += nbytes;\n" |
| 2250 |
" }\n" |
| 2251 |
" if (fd2 E<gt> 0 && FD_ISSET(fd2, &writefds) && buf1_avail E<gt> 0) {\n" |
| 2252 |
" nbytes = write(fd2, buf1 + buf1_written,\n" |
| 2253 |
" buf1_avail - buf1_written);\n" |
| 2254 |
" if (nbytes E<lt> 1)\n" |
| 2255 |
" SHUT_FD2;\n" |
| 2256 |
" else\n" |
| 2257 |
" buf1_written += nbytes;\n" |
| 2258 |
" }\n" |
| 2259 |
"\\&\n" |
| 2260 |
" /* Vérifier si l'écriture de données a rattrapé la lecture de données */\n" |
| 2261 |
"\\&\n" |
| 2262 |
" if (buf1_written == buf1_avail)\n" |
| 2263 |
" buf1_written = buf1_avail = 0;\n" |
| 2264 |
" if (buf2_written == buf2_avail)\n" |
| 2265 |
" buf2_written = buf2_avail = 0;\n" |
| 2266 |
"\\&\n" |
| 2267 |
" /* une extrémité a fermé la connexion, continue\n" |
| 2268 |
" d'écrire vers l'autre extrémité jusqu'à ce\n" |
| 2269 |
" que ce soit vide */\n" |
| 2270 |
"\\&\n" |
| 2271 |
" if (fd1 E<lt> 0 && buf1_avail - buf1_written == 0)\n" |
| 2272 |
" SHUT_FD2;\n" |
| 2273 |
" if (fd2 E<lt> 0 && buf2_avail - buf2_written == 0)\n" |
| 2274 |
" SHUT_FD1;\n" |
| 2275 |
" }\n" |
| 2276 |
" exit(EXIT_SUCCESS);\n" |
| 2277 |
"}\n" |
| 2278 |
|
| 2279 |
#. type: TH |
| 2280 |
#: fedora-44 fedora-rawhide |
| 2281 |
#, no-wrap |
| 2282 |
msgid "2024-07-23" |
| 2283 |
msgstr "23 juillet 2024" |
| 2284 |
|
| 2285 |
#. type: TH |
| 2286 |
#: fedora-44 fedora-rawhide |
| 2287 |
#, no-wrap |
| 2288 |
msgid "Linux man-pages 6.13" |
| 2289 |
msgstr "Pages du manuel de Linux 6.13" |
| 2290 |
|
| 2291 |
#. type: TH |
| 2292 |
#: mageia-cauldron |
| 2293 |
#, no-wrap |
| 2294 |
msgid "Linux man-pages 6.17" |
| 2295 |
msgstr "Pages du manuel de Linux 6.17" |
| 2296 |
|
| 2297 |
#. type: TH |
| 2298 |
#: opensuse-leap-16-1 opensuse-tumbleweed |
| 2299 |
#, no-wrap |
| 2300 |
msgid "Linux man-pages (unreleased)" |
| 2301 |
msgstr "Pages du manuel de Linux (non publiées)" |