\chapter{Hardware} \label{chap:hardware} \section{Diagnostics} dmesg, lshw, lsusb, lspci\dots % ----------------------------------------------------------- \section{Ports série} \index{rs232} Comment détecter si un \textit{device} correspond bien à un port série ? \begin{lstlisting}[language=C] #include #include #include #define TTY "/dev/ttyS18" int main(void) { int fd = open(TTY, O_RDWR | O_NOCTTY); if (fd < 0) { perror("open " TTY); return 1; } struct termios tio; if (tcgetattr(fd, &tio)) { perror("tcgetattr " TTY); return 1; } return 0; } \end{lstlisting} % ----------------------------------------------------------- \section{Disques durs} Iozone ? Bonnie ? Smart\index{smart} ? \section{Interface réseaux} On a parfois besoin de savoir dans quel état est une interface réseau (\textsc{up}, \textsc{running} dans la sortie de ifconfig). Parfois, je n'aime pas trop \textit{parser} celle-ci à grand coup de \textit{regexp}\index{regexp}, en particulier dans un contexte de type Busybox\index{busybox}. Et pour ce cas-là, je préfère utiliser un binaire brassé à la maison, et dont voici un fragment de source : \begin{lstlisting}[language=C] int get_if_flags(char *ifname, short *p_flags) { int fd; int retcode; struct ifreq req; #if DEBUG_LEVEL fprintf(stderr, ">>> %s \"%s\" to %p\n", \ __func__, ifname, p_flags); #endif /* Sanity check */ if ( strlen(ifname) > (IFNAMSIZ-1) ) { fprintf(stderr, "name %s to long\n", ifname); abort(); } fd = socket(PF_INET, SOCK_DGRAM, 0); if (fd < 0) { perror("socket bla..."); return -2; } /* populate the struct for the request */ memset(&req, 0, sizeof(req)); strcpy(req.ifr_name, ifname); /* do the call */ retcode = ioctl(fd, SIOCGIFFLAGS, &req); if (retcode < 0) { perror("ioctl SIOCGIFFLAGS"); close(fd); return -1; } #if DEBUG_LEVEL /* display the result */ fprintf(stderr, "flags = 0x%04x\n", req.ifr_flags); #endif close(fd); *p_flags = req.ifr_flags; return 0; } \end{lstlisting} Hélas, je n'ai pas pu trop tester ce truc sur beaucoup de systèmes, et je vous propose de ne pas trop lui faire confiance pour une application critique...