From: Simone Piccardi Date: Sun, 13 Mar 2016 07:59:26 +0000 (+0000) Subject: Aggiornamento copyright e inizio aggiornameto parte sui socket. X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=commitdiff_plain;h=2270d0dd8cf9460e3aef8d5ffa2bf5c825707e58 Aggiornamento copyright e inizio aggiornameto parte sui socket. --- diff --git a/build.tex b/build.tex index d124f85..0d3c46e 100644 --- a/build.tex +++ b/build.tex @@ -1,6 +1,6 @@ %% build.tex %% -%% Copyright (C) 1999-2015 Simone Piccardi. Permission is granted to copy, +%% Copyright (C) 1999-2016 Simone Piccardi. Permission is granted to copy, %% distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/errors.tex b/errors.tex index 28af8f5..11ed527 100644 --- a/errors.tex +++ b/errors.tex @@ -1,6 +1,6 @@ %% errors.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/fileadv.tex b/fileadv.tex index 0251c7b..8ac1a73 100644 --- a/fileadv.tex +++ b/fileadv.tex @@ -1,6 +1,6 @@ %% fileadv.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/filedir.tex b/filedir.tex index ae7b557..f428ba8 100644 --- a/filedir.tex +++ b/filedir.tex @@ -1,6 +1,6 @@ %% filedir.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/fileio.tex b/fileio.tex index 20c4c1d..2c11011 100644 --- a/fileio.tex +++ b/fileio.tex @@ -1,6 +1,6 @@ %% fileio.tex (merge fileunix.tex - filestd.tex) %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/gapil.tex b/gapil.tex index f15cf7b..375f1a4 100644 --- a/gapil.tex +++ b/gapil.tex @@ -1,6 +1,6 @@ %% gapil.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.3 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", @@ -128,7 +128,7 @@ hyperfootnotes=false]{hyperref} \begin{quote} - Copyright \copyright\ 2000-2015 Simone Piccardi. Permission is granted to + Copyright \copyright\ 2000-2016 Simone Piccardi. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being ``Un preambolo'' diff --git a/intro.tex b/intro.tex index fd6a41b..fc9c791 100644 --- a/intro.tex +++ b/intro.tex @@ -1,6 +1,6 @@ %% intro.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-201 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/ipc.tex b/ipc.tex index bc8d542..e777487 100644 --- a/ipc.tex +++ b/ipc.tex @@ -1,6 +1,6 @@ %% ipc.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/macro.tex b/macro.tex index 9e0fa9e..3624bbe 100644 --- a/macro.tex +++ b/macro.tex @@ -1,6 +1,6 @@ %% macro.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/netlayer.tex b/netlayer.tex index f113a7e..388ee59 100644 --- a/netlayer.tex +++ b/netlayer.tex @@ -1,6 +1,6 @@ %% netlayer.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/network.tex b/network.tex index 6470c1f..575b4c5 100644 --- a/network.tex +++ b/network.tex @@ -1,6 +1,6 @@ %% network.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", @@ -369,10 +369,10 @@ la procedura si può riassumere nei seguenti passi: un suo specifico formato. Per applicazioni generiche, come la posta o le pagine web, viene di solito definito ed implementato quello che viene chiamato un protocollo di applicazione (esempi possono essere HTTP, POP, - SMTP, ecc.), ciascuno dei quali è descritto in un opportuno standard (di - solito attraverso un RFC\footnote{l'acronimo RFC sta per \textit{Request For - Comment} ed è la procedura attraverso la quale vengono proposti gli - standard per Internet.}). + SMTP, ecc.), ciascuno dei quali è descritto in un opportuno standard, di + solito attraverso un RFC (l'acronimo RFC sta per + \itindex{Request~For~Comment~(RFC)} \textit{Request For Comment} ed è la + procedura attraverso la quale vengono proposti gli standard per Internet). \item I dati delle applicazioni vengono inviati al livello di trasporto usando un'interfaccia opportuna (i \textit{socket}, che esamineremo in dettaglio in cap.~\ref{cha:socket_intro}). Qui verranno spezzati in pacchetti di @@ -527,8 +527,8 @@ seguenti: Combina per IPv6 le funzionalità di ICMPv4, IGMP e ARP. \item[\textsl{EGP}] \textit{Exterior Gateway Protocol}. È un protocollo di routing usato per comunicare lo stato fra gateway vicini a livello di - \textsl{sistemi autonomi}\footnote{vengono chiamati \textit{autonomous - systems} i raggruppamenti al livello più alto della rete.}, con + \textsl{sistemi autonomi} (vengono chiamati \textit{autonomous + systems} i raggruppamenti al livello più alto della rete), con meccanismi che permettono di identificare i vicini, controllarne la raggiungibilità e scambiare informazioni sullo stato della rete. Viene implementato direttamente sopra IP. @@ -773,11 +773,11 @@ alle eventuali implicazioni che possono avere, è il seguente: Quando un pacchetto IP viene inviato su una interfaccia di rete e le sue dimensioni eccedono la MTU viene eseguita la cosiddetta -\textit{frammentazione}, i pacchetti cioè vengono suddivisi\footnote{questo +\textit{frammentazione}, i pacchetti cioè vengono suddivisi in blocchi più +piccoli che possono essere trasmessi attraverso l'interfaccia.\footnote{questo accade sia per IPv4 che per IPv6, anche se i pacchetti frammentati sono gestiti con modalità diverse, IPv4 usa un flag nell'header, IPv6 una - opportuna opzione, si veda sez.~\ref{sec:ipv6_protocol}.}) in blocchi più -piccoli che possono essere trasmessi attraverso l'interfaccia. + opportuna opzione, si veda sez.~\ref{sec:ipv6_protocol}.} \begin{table}[!htb] \centering @@ -799,6 +799,8 @@ piccoli che possono essere trasmessi attraverso l'interfaccia. \label{tab:net_mtu_values} \end{table} +%TODO aggiornare la tabella con dati più recenti + \itindbeg{Path~MTU} La MTU più piccola fra due stazioni viene in genere chiamata \textit{path diff --git a/othersock.tex b/othersock.tex index 3f2e28a..af8d97a 100644 --- a/othersock.tex +++ b/othersock.tex @@ -1,6 +1,6 @@ %% othersock.tex %% -%% Copyright (C) 2004-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2004-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/preambolo.tex b/preambolo.tex index 4170b11..499857a 100644 --- a/preambolo.tex +++ b/preambolo.tex @@ -1,6 +1,6 @@ %% preambolo.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/pref.tex b/pref.tex index 9d1f356..2baacde 100644 --- a/pref.tex +++ b/pref.tex @@ -1,6 +1,6 @@ %% pref.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/process.tex b/process.tex index ba1a4cf..7f46bcd 100644 --- a/process.tex +++ b/process.tex @@ -1,6 +1,6 @@ %% process.tex %% -%% Copyright (C) 2000-2015 by Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 by Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/prochand.tex b/prochand.tex index db19575..2fb0f7c 100644 --- a/prochand.tex +++ b/prochand.tex @@ -1,6 +1,6 @@ %% prochand.tex %% -%% Copyright (C) 2000-2015 by Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 by Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/ringraziamenti.tex b/ringraziamenti.tex index ea4a28c..e4a2592 100644 --- a/ringraziamenti.tex +++ b/ringraziamenti.tex @@ -1,6 +1,6 @@ %% ringraziamenti.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/session.tex b/session.tex index bec30f9..6561859 100644 --- a/session.tex +++ b/session.tex @@ -1,6 +1,6 @@ %% session.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/signal.tex b/signal.tex index f78b3db..f5cbac3 100644 --- a/signal.tex +++ b/signal.tex @@ -1,6 +1,6 @@ %% signal.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/sockadv.tex b/sockadv.tex index 91f41d4..ac904bd 100644 --- a/sockadv.tex +++ b/sockadv.tex @@ -1,6 +1,6 @@ %% sockadv.tex %% -%% Copyright (C) 2004-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2004-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/sockctrl.tex b/sockctrl.tex index 7d0d957..44bb3a1 100644 --- a/sockctrl.tex +++ b/sockctrl.tex @@ -1,6 +1,6 @@ %% sockctrl.tex %% -%% Copyright (C) 2004-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2004-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Prefazione", diff --git a/socket.tex b/socket.tex index 52d4809..a8c697b 100644 --- a/socket.tex +++ b/socket.tex @@ -1,6 +1,6 @@ %% socket.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", @@ -227,7 +227,7 @@ comunicazione. \constd{PF\_PPPOX} &24& PPPoX socket & \\ \constd{PF\_WANPIPE} &25& Wanpipe API socket & \\ \constd{PF\_LLC} &26& Linux LLC & \\ - \constd{PF\_CAN} &29& Controller Are network & \\ + \constd{PF\_CAN} &29& Controller Are Network & \\ \constd{PF\_BLUETOOTH}&31& Bluetooth socket & \\ \hline \end{tabular} @@ -342,27 +342,27 @@ appena elencati. &\const{SOCK\_STREAM} &\const{SOCK\_DGRAM} &\const{SOCK\_RAW}& \const{SOCK\_RDM}&\const{SOCK\_SEQPACKET} \\ \hline - \const{PF\_LOCAL} & si & si & & & \\ + \const{PF\_UNIX} & si & si & -- & -- & si\footnotemark \\ \hline -% \const{PF\_UNIX}&\multicolumn{5}{|l|}{sinonimo di \const{PF\_LOCAL}.}\\ -% \hline - \const{PF\_INET} & TCP & UDP & IPv4 & & \\ + \const{PF\_LOCAL}&\multicolumn{5}{|c|}{sinonimo di \const{PF\_UNIX}}\\ \hline - \const{PF\_INET6} & TCP & UDP & IPv6 & & \\ + \const{PF\_INET} & TCP & UDP & IPv4 & -- & -- \\ \hline - \const{PF\_IPX} & & & & & \\ + \const{PF\_INET6} & TCP & UDP & IPv6 & -- & -- \\ \hline - \const{PF\_NETLINK} & & si & si & & \\ + \const{PF\_IPX} & -- & -- & -- & -- & -- \\ \hline - \const{PF\_X25} & & & & & si \\ + \const{PF\_NETLINK} & -- & si & si & -- & -- \\ \hline - \const{PF\_AX25} & & & & & \\ + \const{PF\_X25} & -- & -- & -- & -- & si \\ \hline - \const{PF\_ATMPVC} & & & & & \\ + \const{PF\_AX25} & -- & -- & -- & -- & -- \\ \hline - \const{PF\_APPLETALK} & & si & si & & \\ + \const{PF\_ATMPVC} & -- & -- & -- & -- & -- \\ \hline - \const{PF\_PACKET} & & si & si & & \\ + \const{PF\_APPLETALK} & -- & si & si & -- & -- \\ + \hline + \const{PF\_PACKET} & -- & si & si & -- & -- \\ \hline \end{tabular} \caption{Combinazioni valide di dominio e tipo di protocollo per la @@ -370,11 +370,14 @@ appena elencati. \label{tab:sock_sock_valid_combinations} \end{table} +\footnotetext{supportati a partire dal kernel 2.6.4 per socket che conservano + i limiti dei messaggi e li consegnano in sequenza ordinata.} + In tab.~\ref{tab:sock_sock_valid_combinations} sono mostrate le combinazioni valide possibili per le principali famiglie di protocolli. Per ogni combinazione valida si è indicato il tipo di protocollo, o la parola -\textsl{si} qualora non il protocollo non abbia un nome definito, mentre si -sono lasciate vuote le caselle per le combinazioni non supportate. +\textsl{si} qualora il protocollo non abbia un nome definito, mentre si sono +lasciate vuote le caselle per le combinazioni non supportate. \section{Le strutture degli indirizzi dei socket} @@ -474,12 +477,22 @@ indirizzo; per questo motivo, anche se l'uso di un puntatore \ctyp{void *} sarebbe più immediato per l'utente (che non dovrebbe più eseguire il casting), è stato mantenuto l'uso di questa struttura. +Se si usa una struttura \struct{sockaddr} per allocare delle variabili +generiche da usare in seguito per degli indirizzi si pone il problema che +niente assicura che i dati necessari per le varie famiglie di indirizzi +possano rientrare nella dimensione del campo \var{sa\_data}, anzi, come +vedremo in sez.~\ref{sec:sock_sa_ipv6}, nel caso di indirizzi IPv6 questa +non è proprio sufficiente. Per questo l'interfaccia di programmazione dei +socket prevede la defizione di una speciale struttura +\struct{sockaddr\_storage} per la quale è assicurato che la dimensione sia +sufficiente per qualunque + \subsection{La struttura degli indirizzi IPv4} \label{sec:sock_sa_ipv4} I socket di tipo \const{PF\_INET} vengono usati per la comunicazione -attraverso internet; la struttura per gli indirizzi per un socket internet (se +attraverso Internet; la struttura per gli indirizzi per un socket Internet (se si usa IPv4) è definita come \struct{sockaddr\_in} nell'header file \headfiled{netinet/in.h} ed ha la forma mostrata in fig.~\ref{fig:sock_sa_ipv4_struct}, conforme allo standard POSIX.1g. @@ -490,12 +503,12 @@ fig.~\ref{fig:sock_sa_ipv4_struct}, conforme allo standard POSIX.1g. \includestruct{listati/sockaddr_in.h} \end{minipage} \caption{La struttura \structd{sockaddr\_in} degli indirizzi dei socket - internet (IPv4) e la struttura \structd{in\_addr} degli indirizzi IPv4.} + Internet (IPv4) e la struttura \structd{in\_addr} degli indirizzi IPv4.} \label{fig:sock_sa_ipv4_struct} \end{figure} -L'indirizzo di un socket internet (secondo IPv4) comprende l'indirizzo -internet di un'interfaccia più un \textsl{numero di porta} (affronteremo in +L'indirizzo di un socket Internet (secondo IPv4) comprende l'indirizzo +Internet di un'interfaccia più un \textsl{numero di porta} (affronteremo in dettaglio il significato di questi numeri in sez.~\ref{sec:TCP_port_num}). Il protocollo IP non prevede numeri di porta, che sono utilizzati solo dai protocolli di livello superiore come TCP e UDP. Questa struttura però viene @@ -511,7 +524,7 @@ uguale a zero) o con la \textit{capability} \const{CAP\_NET\_BIND\_SERVICE} possono usare la funzione \func{bind} (che vedremo in sez.~\ref{sec:TCP_func_bind}) su queste porte. -Il membro \var{sin\_addr} contiene un indirizzo internet, e viene acceduto sia +Il membro \var{sin\_addr} contiene un indirizzo Internet, e viene acceduto sia come struttura (un resto di una implementazione precedente in cui questa era una \dirct{union} usata per accedere alle diverse classi di indirizzi) che direttamente come intero. In \headfile{netinet/in.h} vengono definite anche @@ -721,7 +734,7 @@ Al solito il campo \var{sll\_family} deve essere sempre impostato al valore e deve essere indicato in \textit{network order}, facendo uso delle costanti simboliche definite in \file{linux/if\_ether.h}. Il campo \var{sll\_ifindex} è l'indice dell'interfaccia, che, in caso di presenza di più interfacce dello -stesso tipo (se ad esempio si hanno più schede ethernet), permette di +stesso tipo (se ad esempio si hanno più schede Ethernet), permette di selezionare quella con cui si vuole operare (un valore nullo indica qualunque interfaccia). Questi sono i due soli campi che devono essere specificati quando si vuole selezionare una interfaccia specifica, usando questa struttura @@ -730,7 +743,7 @@ con la funzione \func{bind}. I campi \var{sll\_halen} e \var{sll\_addr} indicano rispettivamente l'indirizzo associato all'interfaccia sul protocollo di collegamento e la relativa lunghezza; ovviamente questi valori cambiano a seconda del tipo di -collegamento che si usa, ad esempio, nel caso di ethernet, questi saranno il +collegamento che si usa, ad esempio, nel caso di Ethernet, questi saranno il MAC address della scheda e la relativa lunghezza. Essi vengono usati, insieme ai campi \var{sll\_family} e \var{sll\_ifindex} quando si inviano dei pacchetti, in questo caso tutti gli altri campi devono essere nulli. @@ -747,7 +760,6 @@ pacchetto inviato ad un'altra stazione (e ricevuto su un'interfaccia in modo promiscuo), \constd{PACKET\_OUTGOING} per un pacchetto originato dalla propria macchina che torna indietro sul socket. - Si tenga presente infine che in fase di ricezione, anche se si richiede il troncamento del pacchetto, le funzioni \func{recv}, \func{recvfrom} e \func{recvmsg} (vedi sez.~\ref{sec:net_sendmsg}) restituiranno comunque la @@ -772,11 +784,12 @@ lunghezza effettiva del pacchetto così come arrivato sulla linea. \label{sec:sock_addr_func} In questa sezione tratteremo delle varie funzioni usate per manipolare gli -indirizzi, limitandoci però agli indirizzi internet. Come accennato gli +indirizzi, limitandoci però agli indirizzi Internet. Come accennato gli indirizzi e i numeri di porta usati nella rete devono essere forniti nel cosiddetto \textit{network order}, che corrisponde al formato \textit{big - endian}, anche quando la proprio macchina non usa questo formati, cosa che -può comportare la necessità di eseguire delle conversioni. + endian} (vedi sez.~\ref{sec:endianness}), anche quando la proprio macchina +non usa questo formato, cosa che può comportare la necessità di eseguire delle +conversioni. \subsection{Le funzioni per il riordinamento} @@ -786,32 +799,33 @@ Come già visto in sez.~\ref{sec:endianness} il problema connesso all'\textit{endianness} è che quando si passano dei dati da un tipo di architettura all'altra i dati vengono interpretati in maniera diversa, e ad esempio nel caso dell'intero a 16 bit ci si ritroverà con i due byte in cui è -suddiviso scambiati di posto. Per questo motivo si usano delle funzioni di -conversione che servono a tener conto automaticamente della possibile -differenza fra l'ordinamento usato sul computer e quello che viene usato nelle -trasmissione sulla rete; queste funzioni sono \funcd{htonl}, \funcd{htons}, -\funcd{ntohl} e \funcd{ntohs} ed i rispettivi prototipi sono: -\begin{functions} - \headdecl{netinet/in.h} - \funcdecl{unsigned long int htonl(unsigned long int hostlong)} - Converte l'intero a 32 bit \param{hostlong} dal formato della macchina a - quello della rete. - - \funcdecl{unsigned short int htons(unsigned short int hostshort)} - Converte l'intero a 16 bit \param{hostshort} dal formato della macchina a - quello della rete. +suddiviso scambiati di posto. - \funcdecl{unsigned long int ntohl(unsigned long int netlong)} - Converte l'intero a 32 bit \param{netlong} dal formato della rete a quello - della macchina. +Per questo motivo si usano delle funzioni di conversione che servono a tener +conto automaticamente della possibile differenza fra l'ordinamento usato sul +computer e quello che viene usato nelle trasmissione sulla rete; queste +funzioni sono \funcd{htonl}, \funcd{htons}, \funcd{ntohl} e \funcd{ntohs} ed i +rispettivi prototipi sono: - \funcdecl{unsigned sort int ntohs(unsigned short int netshort)} - Converte l'intero a 16 bit \param{netshort} dal formato della rete a quello - della macchina. - - \bodydesc{Tutte le funzioni restituiscono il valore convertito, e non - prevedono errori.} -\end{functions} +\begin{funcproto}{ +\fhead{netinet/in.h} +\fdecl{unsigned long int htonl(unsigned long int hostlong)} +\fdesc{Converte l'intero a 32 bit \param{hostlong} dal formato della macchina a + quello della rete.} +\fdecl{unsigned short int htons(unsigned short int hostshort)} +\fdesc{Converte l'intero a 16 bit \param{hostshort} dal formato della macchina a + quello della rete.} +\fdecl{unsigned long int ntohl(unsigned long int netlong)} +\fdesc{Converte l'intero a 32 bit \param{netlong} dal formato della rete a quello + della macchina.} +\fdecl{unsigned sort int ntohs(unsigned short int netshort)} +\fdesc{Converte l'intero a 16 bit \param{netshort} dal formato della rete a quello + della macchina.} +} + +{Tutte le funzioni restituiscono il valore convertito, e non prevedono + errori.} +\end{funcproto} I nomi sono assegnati usando la lettera \texttt{n} come mnemonico per indicare l'ordinamento usato sulla rete (da \textit{network order}) e la lettera diff --git a/system.tex b/system.tex index 198832d..e70cb35 100644 --- a/system.tex +++ b/system.tex @@ -1,6 +1,6 @@ %% system.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/tcpsock.tex b/tcpsock.tex index 71463a1..ff4aa49 100644 --- a/tcpsock.tex +++ b/tcpsock.tex @@ -1,6 +1,6 @@ -bg%% tcpsock.tex +%% tcpsock.tex %% -%% Copyright (C) 2000-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2000-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/thread.tex b/thread.tex index b917990..8d33540 100644 --- a/thread.tex +++ b/thread.tex @@ -1,6 +1,6 @@ %% thread.tex %% -%% Copyright (C) 2007-2015 Simone Piccardi. Permission is granted to +%% Copyright (C) 2007-2016 Simone Piccardi. Permission is granted to %% copy, distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo", diff --git a/trasplayer.tex b/trasplayer.tex index d48daeb..42a36f0 100644 --- a/trasplayer.tex +++ b/trasplayer.tex @@ -1,6 +1,6 @@ %% tcpprot.tex %% -%% Copyright (C) 2002-2015 Simone Piccardi. Permission is granted to copy, +%% Copyright (C) 2002-2016 Simone Piccardi. Permission is granted to copy, %% distribute and/or modify this document under the terms of the GNU Free %% Documentation License, Version 1.1 or any later version published by the %% Free Software Foundation; with the Invariant Sections being "Un preambolo",