\doxysubsection{netint.\+c}
\label{netint_8c_source}\index{netint.c@{netint.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ * Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>}}
\DoxyCodeLine{00007 \textcolor{comment}{ *}}
\DoxyCodeLine{00008 \textcolor{comment}{ * This program is free software; you can redistribute it and/or}}
\DoxyCodeLine{00009 \textcolor{comment}{ * modify it under the terms of the GNU Lesser General Public License}}
\DoxyCodeLine{00010 \textcolor{comment}{ * as published by the Free Software Foundation; either version 2.1 of}}
\DoxyCodeLine{00011 \textcolor{comment}{ * the License, or (at your option) any later version.}}
\DoxyCodeLine{00012 \textcolor{comment}{ *}}
\DoxyCodeLine{00013 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{00014 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00015 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{00016 \textcolor{comment}{ * GNU Lesser General Public License for more details.}}
\DoxyCodeLine{00017 \textcolor{comment}{ *}}
\DoxyCodeLine{00018 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public}}
\DoxyCodeLine{00019 \textcolor{comment}{ * License along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00020 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00021 \textcolor{comment}{ */}}
\DoxyCodeLine{00022 }
\DoxyCodeLine{00023                             \textcolor{comment}{/*=}}
\DoxyCodeLine{00024 \textcolor{comment}{                             | Ummm, well, OK.  The network's the}}
\DoxyCodeLine{00025 \textcolor{comment}{                             | network, the computer's the}}
\DoxyCodeLine{00026 \textcolor{comment}{                             | computer.  Sorry for the confusion.}}
\DoxyCodeLine{00027 \textcolor{comment}{                             |        -\/-\/ Sun Microsystems}}
\DoxyCodeLine{00028 \textcolor{comment}{                             */}}
\DoxyCodeLine{00029 }
\DoxyCodeLine{00030 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00031 \textcolor{preprocessor}{\#include <assert.h>}}
\DoxyCodeLine{00032 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00033 \textcolor{preprocessor}{\#include "{}netint.h"{}}}
\DoxyCodeLine{00034 \textcolor{preprocessor}{\#include "{}scoop.h"{}}}
\DoxyCodeLine{00035 }
\DoxyCodeLine{00036 \textcolor{preprocessor}{\#define RS\_MAX\_INT\_BYTES 8}}
\DoxyCodeLine{00037 }
\DoxyCodeLine{00038 rs\_result rs\_squirt\_byte(rs\_job\_t *job, rs\_byte\_t val)}
\DoxyCodeLine{00039 \{}
\DoxyCodeLine{00040     rs\_tube\_write(job, \&val, 1);}
\DoxyCodeLine{00041     \textcolor{keywordflow}{return} RS\_DONE;}
\DoxyCodeLine{00042 \}}
\DoxyCodeLine{00043 }
\DoxyCodeLine{00044 rs\_result rs\_squirt\_netint(rs\_job\_t *job, rs\_long\_t val, \textcolor{keywordtype}{int} len)}
\DoxyCodeLine{00045 \{}
\DoxyCodeLine{00046     rs\_byte\_t buf[RS\_MAX\_INT\_BYTES];}
\DoxyCodeLine{00047     \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{00048 }
\DoxyCodeLine{00049     assert(len <= RS\_MAX\_INT\_BYTES);}
\DoxyCodeLine{00050     \textcolor{comment}{/* Fill the output buffer with a bigendian representation of the number. */}}
\DoxyCodeLine{00051     \textcolor{keywordflow}{for} (i = len -\/ 1; i >= 0; i-\/-\/) \{}
\DoxyCodeLine{00052         buf[i] = (rs\_byte\_t)val;       \textcolor{comment}{/* truncated */}}
\DoxyCodeLine{00053         val >>= 8;}
\DoxyCodeLine{00054     \}}
\DoxyCodeLine{00055     rs\_tube\_write(job, buf, len);}
\DoxyCodeLine{00056     \textcolor{keywordflow}{return} RS\_DONE;}
\DoxyCodeLine{00057 \}}
\DoxyCodeLine{00058 }
\DoxyCodeLine{00059 rs\_result rs\_squirt\_n4(rs\_job\_t *job, \textcolor{keywordtype}{int} val)}
\DoxyCodeLine{00060 \{}
\DoxyCodeLine{00061     \textcolor{keywordflow}{return} rs\_squirt\_netint(job, val, 4);}
\DoxyCodeLine{00062 \}}
\DoxyCodeLine{00063 }
\DoxyCodeLine{00064 rs\_result rs\_suck\_byte(rs\_job\_t *job, rs\_byte\_t *val)}
\DoxyCodeLine{00065 \{}
\DoxyCodeLine{00066     rs\_result result;}
\DoxyCodeLine{00067     rs\_byte\_t *buf;}
\DoxyCodeLine{00068 }
\DoxyCodeLine{00069     \textcolor{keywordflow}{if} ((result = rs\_scoop\_read(job, 1, (\textcolor{keywordtype}{void} **)\&buf)) == RS\_DONE)}
\DoxyCodeLine{00070         *val = *buf;}
\DoxyCodeLine{00071     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00072 \}}
\DoxyCodeLine{00073 }
\DoxyCodeLine{00074 rs\_result rs\_suck\_netint(rs\_job\_t *job, rs\_long\_t *val, \textcolor{keywordtype}{int} len)}
\DoxyCodeLine{00075 \{}
\DoxyCodeLine{00076     rs\_result result;}
\DoxyCodeLine{00077     rs\_byte\_t *buf;}
\DoxyCodeLine{00078     \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{00079 }
\DoxyCodeLine{00080     assert(len <= RS\_MAX\_INT\_BYTES);}
\DoxyCodeLine{00081     \textcolor{keywordflow}{if} ((result = rs\_scoop\_read(job, len, (\textcolor{keywordtype}{void} **)\&buf)) == RS\_DONE) \{}
\DoxyCodeLine{00082         *val = 0;}
\DoxyCodeLine{00083         \textcolor{keywordflow}{for} (i = 0; i < len; i++)}
\DoxyCodeLine{00084             *val = (*val << 8) | (rs\_long\_t)buf[i];}
\DoxyCodeLine{00085     \}}
\DoxyCodeLine{00086     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00087 \}}
\DoxyCodeLine{00088 }
\DoxyCodeLine{00089 rs\_result rs\_suck\_n4(rs\_job\_t *job, \textcolor{keywordtype}{int} *val)}
\DoxyCodeLine{00090 \{}
\DoxyCodeLine{00091     rs\_result result;}
\DoxyCodeLine{00092     rs\_long\_t buf;}
\DoxyCodeLine{00093 }
\DoxyCodeLine{00094     \textcolor{keywordflow}{if} ((result = rs\_suck\_netint(job, \&buf, 4)) == RS\_DONE)}
\DoxyCodeLine{00095         *val = (int)buf;}
\DoxyCodeLine{00096     \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00097 \}}
\DoxyCodeLine{00098 }
\DoxyCodeLine{00099 \textcolor{keywordtype}{int} rs\_int\_len(rs\_long\_t val)}
\DoxyCodeLine{00100 \{}
\DoxyCodeLine{00101     assert(val >= 0);}
\DoxyCodeLine{00102     \textcolor{keywordflow}{if} (!(val \& \string~(rs\_long\_t)0xff))}
\DoxyCodeLine{00103         \textcolor{keywordflow}{return} 1;}
\DoxyCodeLine{00104     \textcolor{keywordflow}{if} (!(val \& \string~(rs\_long\_t)0xffff))}
\DoxyCodeLine{00105         \textcolor{keywordflow}{return} 2;}
\DoxyCodeLine{00106     \textcolor{keywordflow}{if} (!(val \& \string~(rs\_long\_t)0xffffffff))}
\DoxyCodeLine{00107         \textcolor{keywordflow}{return} 4;}
\DoxyCodeLine{00108     assert(!(val \& \string~(rs\_long\_t)0xffffffffffffffff));}
\DoxyCodeLine{00109     \textcolor{keywordflow}{return} 8;}
\DoxyCodeLine{00110 \}}

\end{DoxyCode}
