getprotoent_r(3) | Library Functions Manual | getprotoent_r(3) |
NOM
getprotoent_r, getprotobyname_r, getprotobynumber_r — Lire une entrée de protocole (version réentrante)
BIBLIOTHÈQUE
Bibliothèque C standard (libc, -lc)
SYNOPSIS
#include <netdb.h>
int getprotoent_r(struct protoent *restrict result_buf, char buf[restrict .size], size_t size, struct protoent **restrict result); int getprotobyname_r(const char *restrict name, struct protoent *restrict result_buf, char buf[restrict .size], size_t size, struct protoent **restrict result); int getprotobynumber_r(int proto, struct protoent *restrict result_buf, char buf[restrict .size], size_t size, struct protoent **restrict result);
getprotoent_r(), getprotobyname_r(), getprotobynumber_r() :
Depuis la glibc 2.19 : _DEFAULT_SOURCE glibc 2.19 et antérieures : _BSD_SOURCE || _SVID_SOURCE
DESCRIPTION
getprotoent_r(), getprotobyname_r(), et getprotobynumber_r() sont respectivement, les versions réentrantes des fonctions getprotoent(3), getprotobyname(3) et getprotobynumber(3). Elles en diffèrent car elles renvoient une structure protoent, et leur signature ainsi que leur valeur de retour sont aussi différentes. Cette page de manuel décrit juste les différences avec les fonctions non réentrantes.
Au lieu de renvoyer un pointeur vers une structure protoent statiquement allouée, ces fonctions copient la structure à l'adresse pointée par tampon_resultat.
The buf array is used to store the string fields pointed to by the returned protoent structure. (The nonreentrant functions allocate these strings in static storage.) The size of this array is specified in size. If buf is too small, the call fails with the error ERANGE, and the caller must try again with a larger buffer. (A buffer of size 1024 bytes should be sufficient for most applications.)
Si la fonction obtient un enregistrement de protocole, alors *resultat pointe vers tampon_resultat sinon *resultat est défini à NULL.
VALEUR RENVOYÉE
En cas de succès, ces fonctions renvoient zéro. En cas d'erreur, une valeur d'erreur positive listée dans ERREURS est renvoyée.
Dans le cas des erreurs « enregistrement non trouvé » (getprotobyname_r(), getprotobynumber_r()) ou « fin de l'entrée » (getprotoent_r()), resultat est défini à NULL.
ERREURS
ATTRIBUTS
Pour une explication des termes utilisés dans cette section, consulter attributes(7).
Interface | Attribut | Valeur |
getprotoent_r(), getprotobyname_r(), getprotobynumber_r() | Sécurité des threads | MT-Safe locale |
VERSIONS
Des fonctions avec des noms similaires existent sur d'autres systèmes, bien qu’en général avec des signatures d'appel différentes.
STANDARDS
GNU.
EXEMPLES
The program below uses getprotobyname_r() to retrieve the protocol record for the protocol named in its first command-line argument. If a second (integer) command-line argument is supplied, it is used as the initial value for size; if getprotobyname_r() fails with the error ERANGE, the program retries with larger buffer sizes. The following shell session shows a couple of sample runs:
$ ./a.out tcp 1 ERANGE! Retrying with larger buffer getprotobyname_r() returned: 0 (success) (size=78) p_name=tcp; p_proto=6; aliases=TCP $ ./a.out xxx 1 ERANGE! Retrying with larger buffer getprotobyname_r() returned: 0 (success) (size=100) Call failed/record not found
Source du programme
#define _GNU_SOURCE #include <ctype.h> #include <errno.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_BUF 10000 int main(int argc, char *argv[]) { int size, erange_cnt, s; struct protoent result_buf; struct protoent *result; char buf[MAX_BUF]; if (argc < 2) { printf("Usage: %s proto-name [size]\n", argv[0]); exit(EXIT_FAILURE); } size = 1024; if (argc > 2) size = atoi(argv[2]); if (size > MAX_BUF) { printf("Exceeded buffer limit (%d)\n", MAX_BUF); exit(EXIT_FAILURE); } erange_cnt = 0; do { s = getprotobyname_r(argv[1], &result_buf, buf, size, &result); if (s == ERANGE) { if (erange_cnt == 0) printf("ERANGE! Retrying with larger buffer\n"); erange_cnt++; /* Increment a byte at a time so we can see exactly what size buffer was required. */ size++; if (size > MAX_BUF) { printf("Exceeded buffer limit (%d)\n", MAX_BUF); exit(EXIT_FAILURE); } } } while (s == ERANGE); printf("getprotobyname_r() returned: %s (size=%d)\n", (s == 0) ? "0 (success)" : (s == ENOENT) ? "ENOENT" : strerror(s), size); if (s != 0 || result == NULL) { printf("Call failed/record not found\n"); exit(EXIT_FAILURE); } printf("p_name=%s; p_proto=%d; aliases=", result_buf.p_name, result_buf.p_proto); for (char **p = result_buf.p_aliases; *p != NULL; p++) printf("%s ", *p); printf("\n"); exit(EXIT_SUCCESS); }
VOIR AUSSI
TRADUCTION
La traduction française de cette page de manuel a été créée par Christophe Blaess https://www.blaess.fr/christophe/, Stéphan Rafin <stephan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, François Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Guérard <fevrier@tigreraye.org>, Jean-Luc Coulon (f5ibh) <jean-luc.coulon@wanadoo.fr>, Julien Cristau <jcristau@debian.org>, Thomas Huriaux <thomas.huriaux@gmail.com>, Nicolas François <nicolas.francois@centraliens.net>, Florentin Duneau <fduneau@gmail.com>, Simon Paillard <simon.paillard@resel.enst-bretagne.fr>, Denis Barbier <barbier@debian.org>, David Prévot <david@tilapin.org> et Jean-Philippe MENGUAL <jpmengual@debian.org>
Cette traduction est une documentation libre ; veuillez vous reporter à la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.
Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à debian-l10n-french@lists.debian.org.
24 décembre 2024 | Pages du manuel de Linux 6.12 |