parent
21b246c244
commit
a5e7a2e6d5
@ -0,0 +1,69 @@ |
||||
/*
|
||||
* ao_example.c |
||||
* Written by Stan Seibert - July 2001 |
||||
* |
||||
* Compilation command line (for Linux systems): |
||||
* gcc -o ao_example ao_example.c -lao -ldl -lm |
||||
*/ |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <ao/ao.h> |
||||
#include <math.h> |
||||
|
||||
#define BUF_SIZE 4096 |
||||
|
||||
int main(int argc, char **argv) |
||||
{ |
||||
ao_device *device; |
||||
ao_sample_format format; |
||||
int default_driver; |
||||
char *buffer; |
||||
int buf_size; |
||||
int sample; |
||||
float freq = 440.0; |
||||
int i; |
||||
|
||||
/* -- Initialize -- */ |
||||
|
||||
fprintf(stderr, "libao example program\n"); |
||||
|
||||
ao_initialize(); |
||||
|
||||
/* -- Setup for default driver -- */ |
||||
|
||||
default_driver = ao_default_driver_id(); |
||||
|
||||
memset(&format, 0, sizeof(format)); |
||||
format.bits = 16; |
||||
format.channels = 2; |
||||
format.rate = 44100; |
||||
format.byte_format = AO_FMT_LITTLE; |
||||
|
||||
/* -- Open driver -- */ |
||||
device = ao_open_live(default_driver, &format, NULL /* no options */); |
||||
if (device == NULL) { |
||||
fprintf(stderr, "Error opening device.\n"); |
||||
return 1; |
||||
} |
||||
|
||||
/* -- Play some stuff -- */ |
||||
buf_size = format.bits/8 * format.channels * format.rate; |
||||
buffer = calloc(buf_size, sizeof(char)); |
||||
|
||||
for (i = 0; i < format.rate; i++) { |
||||
sample = (int)(0.75 * 32768.0 * |
||||
sin(2 * M_PI * freq * ((float) i/format.rate))); |
||||
|
||||
/* Put the same stuff in left and right channel */ |
||||
buffer[4*i] = buffer[4*i+2] = sample & 0xff; |
||||
buffer[4*i+1] = buffer[4*i+3] = (sample >> 8) & 0xff; |
||||
} |
||||
ao_play(device, buffer, buf_size); |
||||
|
||||
/* -- Close and shutdown -- */ |
||||
ao_close(device); |
||||
ao_shutdown(); |
||||
|
||||
return (0); |
||||
} |
@ -0,0 +1,52 @@ |
||||
% |
||||
% nouveau 20 juillet 2014 ave StExupery |
||||
% |
||||
\chapter{curses} |
||||
\label{curses} |
||||
\index{curses} |
||||
|
||||
En fait, nous allons plutôt parler de \textbf{ncurses} qui est |
||||
l'implémentation actuelle de l'ancêtre \texttt{curses}. Voic ce |
||||
qu'en dit une page de man : |
||||
|
||||
\begin{quote} |
||||
The ncurses library routines give the user a terminal-independent |
||||
method of updating character screens with reasonable optimization. |
||||
This implementation is ``new curses'' (ncurses) and is the approved |
||||
replacement for 4.4BSD classic curses, which has been discontinued. |
||||
\end{quote} |
||||
|
||||
|
||||
\section{premier exemple} |
||||
|
||||
Bien entendu, nous commencerons par l'ECM traditionnel de rigueur. |
||||
|
||||
\lstinputlisting[language=C]{ex_curses.c} |
||||
|
||||
La première étape consiste à initialiser et configurer le moteur |
||||
interne de ncurses, et à régler l'interaction clavier/écran. |
||||
|
||||
Ensuite, avec \texttt{mvaddstr}, nous écrivons le texte passé |
||||
en paramètre à une position fixée ligne,colonne |
||||
dans un écran virtuel |
||||
qui sera ensuite transféré dans l'écran réel |
||||
par le \texttt{refresh()}. |
||||
|
||||
|
||||
\section{astuces} |
||||
|
||||
Dans une boucle interactive, on va utiliser \texttt{getch()}, qui va |
||||
bloquer tant qu'on n'a pas tapé sur une touche. Mais que faire si |
||||
on veut utiliser, en plus du clavier, un autre périphérique de |
||||
saisie, genre un Joystick\index{joystick} ? |
||||
|
||||
Bien entendu, on peut utiliser \texttt{select(2)}, mais cela nécessite |
||||
de connaitre le \textit{file descriptor} auquel est attaché le clavier. |
||||
Dans le contexte classique, on peut assumer que ce sera le \texttt{fd} |
||||
associé à \textit{stdin}, mais il est imprudent de compter là-dessus. |
||||
|
||||
---> voir \texttt{newterm(3)} |
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,170 @@ |
||||
\chapter{Les intertubes} |
||||
\label{Internet} \index{Internet} |
||||
|
||||
Ah, le grand Internet sauvage, il serait temps qu'on en parle un peu. |
||||
Nous allons voir dans ce chapitre quelques utilisations |
||||
que l'on peut qualifier de «~créatives~». |
||||
|
||||
Si vous attendiez des choses plus sérieuses, j'ai aussi ça |
||||
en magasin : \textsc{dns} page \pageref{DNS}, |
||||
\textsc{ssh} page \pageref{ssh}, |
||||
streaming page \pageref{streaming}, |
||||
et probablement bien d'autres à venir. |
||||
|
||||
% http://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/ |
||||
|
||||
% ============================================================== |
||||
|
||||
\section{xinetd} |
||||
\index{xinetd} |
||||
\label{xinetd} |
||||
|
||||
Xinetd est un \textit{super-server daemon} qui gère l'accueil |
||||
et le lancement pour certains services Internet essentiels |
||||
tels que \texttt{daytime}\index{daytime} ou |
||||
\texttt{echo}\index{echo}. |
||||
Par rapport à son ancêtre |
||||
\texttt{inetd}\index{inetd}, décrit en page \pageref{inetd}, |
||||
il offre plus |
||||
de souplesse dans la configuration et la gestion des droits |
||||
d'accès. |
||||
|
||||
\subsection{qotd} |
||||
\index{qotd} |
||||
|
||||
À titre d'exercice, nous allons reprendre l'exemple du serveur |
||||
de \textsl{quote of the day} que nous avons déja utilisé avec |
||||
Inetd\index{inetd}, et lancer le |
||||
petit script par l'intermédiaire de Xinetd. |
||||
|
||||
Pour cela, il faut créer dans le répertoire |
||||
\texttt{/etc/xinetd.d/}\footnote{Attention, ce répertoire |
||||
est peut-être un debianisme, ymmv.} un fichier nommé |
||||
\texttt{qotd} et contenant ceci : |
||||
|
||||
\begin{verbatim} |
||||
service qotd |
||||
{ |
||||
disable = yes |
||||
type = UNLISTED |
||||
|
||||
socket_type = stream |
||||
protocol = tcp |
||||
|
||||
user = nobody |
||||
server = /usr/local/bin/qotd.sh |
||||
} |
||||
\end{verbatim} |
||||
|
||||
Bien entendu, le script \texttt{qotd.sh} décrit en page |
||||
\pageref{inetd} sera placé dans le bon répertoire. |
||||
Ensuite, il faut demander à Xinetd de relire ses fichiers de |
||||
configuration par un signal bien senti et au bon endroit. |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
% ============================================================== |
||||
\section{Translation d'adresse} |
||||
\index{NAT} |
||||
|
||||
Voir en page \pageref{NAT} pour découvrir comment utiliser une |
||||
machine connectée en WiFi pour donner accès à Internet à votre |
||||
réseau local Ethernet\dots |
||||
|
||||
Mais cette translation d'adresse peut avoir aussi d'autres |
||||
défits à relever pour en faire une solution complexe et |
||||
amusante à des problèmes inexistants et datant du siècle |
||||
dernier. Par exemple la comparaison de la mise en œuvre du NAT |
||||
avec |
||||
\texttt{iptable} et \texttt{pfctl} est une source de trolls |
||||
sans fin. |
||||
|
||||
|
||||
% ============================================================== |
||||
\section{Iodine} |
||||
\index{iodine}\label{iodine} |
||||
|
||||
Iodine, c'est quoi ? C'est un ensemble de logiciels qui permettent |
||||
de se brancher sur l'Intertube même si on n'a pas d'accès |
||||
«~autorisé~» par la voisine qui a déménagée vers la |
||||
lointaine campagne avec sa friboite. |
||||
|
||||
\begin{quote} |
||||
This is a piece of software that lets you tunnel IPv4 data through a |
||||
DNS server. This can be usable in different situations where internet |
||||
access is firewalled, but DNS queries are allowed. |
||||
The name iodine was chosen since it starts with IOD (IP Over DNS) |
||||
and since iodine has atomic number 53, which happens to be the DNS |
||||
port number. |
||||
\end{quote} |
||||
|
||||
À ce jour (2 septembre 2013) ce que vous allez lire est basé |
||||
sur la version \texttt{0.6.0-rc1} et sera probablement plus ou |
||||
moins incompatible avec les versions précedentes ou suivantes, ymmv. |
||||
|
||||
\begin{verbatim} |
||||
root@plop:iodine-0.6.0-rc1# bin/iodine teton.mooo.com -f -P m |
||||
Opened dns0 |
||||
Opened UDP socket |
||||
Sending DNS queries for teton.mooo.com to 192.168.1.1 |
||||
Autodetecting DNS query type (use -T to override).................. |
||||
iodine: No suitable DNS query type found. Are you connected to a network? |
||||
iodine: If you expect very long roundtrip delays, use -T explicitly. |
||||
iodine: (Also, connecting to an "ancient" version of iodined won't work.) |
||||
\end{verbatim} |
||||
|
||||
|
||||
\subsection{Coté serveur} |
||||
|
||||
Je pense qu'il faut commencer par voir du coté du DNS |
||||
pour déléguer une sous-zone à la machine qui va faire tourner |
||||
le serveur iodine. Mais j'en suis pas certain. RTFM. |
||||
|
||||
\subsection{Coté client} |
||||
|
||||
Je n'en sais pas plus non plus... |
||||
|
||||
\begin{verbatim} |
||||
sudo bin/iodine -f -P s3cr3tp4ssw0rd i.buvette.org |
||||
\end{verbatim} |
||||
|
||||
% ============================================================== |
||||
\section{outils de diagnostic} |
||||
|
||||
|
||||
iftop\index{iftop}, |
||||
iptraf\index{iptraf} |
||||
\dots |
||||
|
||||
% ------------------------------------------------------------- |
||||
\subsection{tcpdump} |
||||
\index{tcpdump} |
||||
|
||||
C'est clairement un outil dédié au voyeurisme :) |
||||
|
||||
% ------------------------------------------------------------- |
||||
|
||||
\subsection{nmap} |
||||
\index{nmap} |
||||
|
||||
C'est clairement un outil dédié au voyeurisme :) |
||||
|
||||
|
||||
% ============================================================== |
||||
\section{netcat} |
||||
\index{netcat} |
||||
|
||||
\begin{quote} |
||||
The nc (or netcat) utility is used for just about anything under the sun |
||||
involving TCP or UDP. It can open TCP connections, send UDP packets, |
||||
listen on arbitrary TCP and UDP ports, do port scanning, and deal with |
||||
both IPv4 and IPv6. Unlike telnet(1), nc scripts nicely, and separates |
||||
error messages onto standard error instead of sending them to standard |
||||
output, as telnet(1) does with some. |
||||
\end{quote} |
||||
|
||||
|
||||
% ============================================================== |
||||
|
@ -0,0 +1,26 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <ncurses.h> |
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
int key; |
||||
|
||||
if (2 != argc) exit(1); |
||||
|
||||
initscr(); /* first initialization */ |
||||
cbreak(); /* no line buffering */ |
||||
noecho(); /* be silent on input */ |
||||
keypad(stdscr, TRUE); /* acces touches curseur */ |
||||
|
||||
mvaddstr(10, 3, argv[1]); |
||||
refresh(); |
||||
|
||||
key = getch(); |
||||
|
||||
endwin(); |
||||
printf("code touche %d\n", key); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue