if_nameindex
Section: C Library Functions (3)
Updated: 15 décembre 2022
Index
Return to Main Contents
NOM
if_nameindex, if_freenameindex - Obtenir le nom et l'indice des interfaces
réseau
BIBLIOTHÈQUE
Bibliothèque C standard (libc, -lc)
SYNOPSIS
#include <net/if.h>
struct if_nameindex *if_nameindex(void);
void if_freenameindex(struct if_nameindex *ptr);
DESCRIPTION
La fonction if_nameindex() renvoie un tableau de structures
if_nameindex, contenant chacune des informations au sujet d'une des
interfaces réseau du système local. La structure if_nameindex contient au
moins les champs suivants :
unsigned int if_index; /* Index of interface (1, 2, ...) */
char *if_name; /* Null-terminated name ("eth0", etc.) */
The if_index field contains the interface index. The if_name field
points to the null-terminated interface name. The end of the array is
indicated by entry with if_index set to zero and if_name set to NULL.
La donnée renvoyée par if_nameindex() est dynamiquement allouée et
devrait être libérée avec if_freenameindex() lorsqu'elle n'est plus
utilisée.
VALEUR RENVOYÉE
On success, if_nameindex() returns pointer to the array; on error, NULL
is returned, and errno is set to indicate the error.
ERREURS
if_nameindex() peut échouer et remplir errno si :
- ENOBUFS
-
les ressources disponibles sont insuffisantes.
getifaddrs() peut aussi échouer pour les erreurs précisées pour
socket(2), bind(2), getsockname(2), recvmsg(2), sendto(2) ou
malloc(3).
VERSIONS
getifaddrs() est apparue dans la glibc 2.1. Les versions antérieures à la
glibc 2.3.4 ne géraient que les interfaces avec des adresses IPv4. La
gestion des interfaces qui n'ont pas d'adresse IPv4 n'est disponible que si
le noyau gère netlink.
ATTRIBUTS
Pour une explication des termes utilisés dans cette section, consulter
attributes(7).
Interface | Attribut | Valeur
|
if_nameindex(),
if_freenameindex()
| Sécurité des threads | MT-Safe
|
STANDARDS
POSIX.1-2001, POSIX.1-2008, RFC 3493.
Cette fonction est d'abord apparue dans BSDi.
EXEMPLES
Le programme ci-dessous montre l'utilisation des fonctions décrites dans
cette page. Voici un exemple de sortie que ce programme peut produire :
$ ./a.out 1: lo 2: wlan0 3: em1
Source du programme
#include <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main(void)
{
struct if_nameindex *if_ni, *i;
if_ni = if_nameindex();
if (if_ni == NULL) {
perror("if_nameindex");
exit(EXIT_FAILURE);
}
for (i = if_ni; !(i->if_index == 0 && i->if_name == NULL); i++)
printf("%u: %s\n", i->if_index, i->if_name);
if_freenameindex(if_ni);
exit(EXIT_SUCCESS);
}
VOIR AUSSI
getsockopt(2), setsockopt(2), getifaddrs(3), if_indextoname(3),
if_nametoindex(3), ifconfig(8)
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>,
Cédric Boutillier <cedric.boutillier@gmail.com>
et
Frédéric Hantrais <fhantrais@gmail.com>
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 à
Index
- NOM
-
- BIBLIOTHÈQUE
-
- SYNOPSIS
-
- DESCRIPTION
-
- VALEUR RENVOYÉE
-
- ERREURS
-
- VERSIONS
-
- ATTRIBUTS
-
- STANDARDS
-
- EXEMPLES
-
- Source du programme
-
- VOIR AUSSI
-
- TRADUCTION
-
This document was created by
man2html,
using the manual pages.
Time: 05:39:51 GMT, May 18, 2024