summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-08-04 22:45:25 +0000
committerLennart Poettering <lennart@poettering.net>2003-08-04 22:45:25 +0000
commit3e05cdd09405cc6133ebf38ea9ee9afc50fb280f (patch)
tree22de63df1a8223e84fb1c028ca5ebf178e97cfc8
parent80f8eef17230e586d343d0c219f9eb2f2d1643e8 (diff)
Initial checkin
git-svn-id: file:///home/lennart/svn/public/ifmetric/trunk@3 b1ab5a0b-19c4-0310-9d9a-ef184d715f50
-rw-r--r--LICENSE340
-rw-r--r--Makefile.am35
-rwxr-xr-xbootstrap.sh39
-rw-r--r--configure.ac86
-rw-r--r--doc/Makefile.am36
-rw-r--r--doc/README.html.in133
-rw-r--r--doc/style.css12
-rw-r--r--man/Makefile.am30
-rw-r--r--man/ifmetric.8.xml.in73
-rw-r--r--src/Makefile.am23
-rw-r--r--src/getifn.c77
-rw-r--r--src/getifn.h7
-rw-r--r--src/ifmetric.c204
-rw-r--r--src/nlrequest.c139
-rw-r--r--src/nlrequest.h20
15 files changed, 1254 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d60c31a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..4d0daf7
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,35 @@
+# $Id$
+
+# This file is part of ifmetric.
+#
+# ifmetric is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifmetric is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifmetric; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+EXTRA_DIST=bootstrap.sh README LICENSE
+SUBDIRS=src man doc
+
+MAINTAINERCLEANFILES = README
+noinst_DATA = README
+
+README:
+ rm -f README
+ $(MAKE) -C doc README
+ ln -s doc/README README
+
+homepage:
+ test -d $$HOME/homepage/lennart
+ mkdir -p $$HOME/homepage/lennart/projects/ifmetric
+ cp *.tar.gz $$HOME/homepage/lennart/projects/ifmetric
+ cp doc/README.html doc/style.css doc/NEWS $$HOME/homepage/lennart/projects/ifmetric
+ cp $$HOME/homepage/lennart/projects/ifmetric/README.html $$HOME/homepage/lennart/projects/ifmetric/index.html
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..3ccd6e9
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# $Id$
+
+# This file is part of ifmetric.
+#
+# ifmetric is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifmetric is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifmetric; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+if [ "x$1" = "xam" ] ; then
+ set -ex
+ automake -a -c
+ ./config.status
+else
+ set -ex
+
+ make maintainer-clean || true
+
+ rm -rf autom4te.cache
+ rm -f config.cache
+
+ aclocal
+ autoheader
+ automake -a -c
+ autoconf -Wall
+
+ ./configure "$@"
+fi
+
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..913787a
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,86 @@
+# -*- Autoconf -*-
+# Process this file with autoconf to produce a configure script.
+
+# $Id$
+
+# This file is part of ifmetric.
+#
+# ifmetric is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifmetric is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifmetric; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+AC_PREREQ(2.57)
+AC_INIT([ifmetric], [0.1], [mzvszrgevp@itaparica.org])
+AC_CONFIG_SRCDIR([src/ifmetric.c])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([foreign -Wall])
+AM_MAINTAINER_MODE
+
+# Checks for programs.
+AC_PROG_CC
+AC_CHECK_FUNCS([memset socket strerror strrchr])
+AC_CHECK_HEADERS([stdlib.h string.h sys/socket.h unistd.h])
+AC_FUNC_MALLOC
+AC_FUNC_REALLOC
+AC_HEADER_STDC
+AC_PROG_LN_S
+AC_TYPE_PID_T
+
+AC_CHECK_HEADER([linux/version.h],, [AC_MSG_ERROR([*** Sorry, you have to install the kernel header files ***])])
+
+# If using GCC specifiy some additional parameters
+if test "x$GCC" = "xyes" ; then
+ CFLAGS="$CFLAGS -pipe -Wall"
+fi
+
+# LYNX documentation generation
+AC_ARG_ENABLE(lynx,
+ AC_HELP_STRING([--disable-lynx], [Turn off lynx usage for documentation generation]),
+[case "${enableval}" in
+ yes) lynx=yes ;;
+ no) lynx=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --disable-lynx) ;;
+esac],[lynx=yes])
+
+if test x$lynx = xyes ; then
+ AC_CHECK_PROG(have_lynx, lynx, yes, no)
+
+ if test x$have_lynx = xno ; then
+ AC_MSG_ERROR([*** Sorry, you have to install lynx or use --disable-lynx ***])
+ fi
+fi
+
+AM_CONDITIONAL([USE_LYNX], [test "x$lynx" = xyes])
+
+# XMLTOMAN manpage generation
+AC_ARG_ENABLE(xmltoman,
+ AC_HELP_STRING([--disable-xmltoman], [Disable rebuilding of man pages with xmltoman]),
+[case "${enableval}" in
+ yes) xmltoman=yes ;;
+ no) xmltoman=no ;;
+ *) AC_MSG_ERROR([bad value ${enableval} for --disable-xmltoman]) ;;
+esac],[xmltoman=yes])
+
+if test x$xmltoman = xyes ; then
+ AC_CHECK_PROG(have_xmltoman, xmltoman, yes, no)
+
+ if test x$have_xmltoman = xno ; then
+ AC_MSG_WARN([*** Not rebuilding man pages as xmltoman is not found ***])
+ xmltoman=no
+ fi
+fi
+
+AM_CONDITIONAL([USE_XMLTOMAN], [test "x$xmltoman" = xyes])
+
+AC_CONFIG_FILES([src/Makefile Makefile man/Makefile doc/Makefile doc/README.html])
+AC_OUTPUT
diff --git a/doc/Makefile.am b/doc/Makefile.am
new file mode 100644
index 0000000..7b7836e
--- /dev/null
+++ b/doc/Makefile.am
@@ -0,0 +1,36 @@
+# $Id$
+
+# This file is part of ifmetric.
+#
+# ifmetric is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifmetric is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifmetric; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+noinst_DATA = README.html README
+EXTRA_DIST = $(noinst_DATA) style.css README.html.in
+
+MAINTAINERCLEANFILES = README README.html
+CLEANFILES =
+
+if USE_LYNX
+README: README.html
+ lynx --dump $^ | sed 's,file://localhost/.*/doc/README.html,README,' > $@
+
+CLEANFILES += README
+endif
+
+tidy: README.html
+ tidy -e < README.html
+
+.PHONY: tidy
+
diff --git a/doc/README.html.in b/doc/README.html.in
new file mode 100644
index 0000000..46f4a23
--- /dev/null
+++ b/doc/README.html.in
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="iso-8895-15"?> <!-- -*-html-helper-*- -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+<title>ifmetric @PACKAGE_VERSION@</title>
+<link rel="stylesheet" type="text/css" href="style.css" />
+</head>
+
+<body>
+<h1><a name="top">ifmetric @PACKAGE_VERSION@</a></h1>
+
+<p><i>Copyright 2003 Lennart Poettering &lt;mzvszrgevp [at] itaparica.org&gt;</i></p>
+
+<ul class="toc">
+ <li><a href="#license">License</a></li>
+ <li><a href="#news">News</a></li>
+ <li><a href="#overview">Overview</a></li>
+ <li><a href="#status">Status</a></li>
+ <li><a href="#documentation">Documentation</a></li>
+ <li><a href="#requirements">Requirements</a></li>
+ <li><a href="#installation">Installation</a></li>
+ <li><a href="#acks">Acknowledgements</a></li>
+ <li><a href="#download">Download</a></li>
+</ul>
+
+<h2><a name="license">License</a></h2>
+
+<p>This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.</p>
+
+<p>This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.</p>
+
+<p>You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.</p>
+
+<h2><a name="news">News</a></h2>
+
+<div class="news-date">Mon Aug 4 2003: </div> <p class="news-text"><a
+href="http://www.stud.uni-hamburg.de/~lennart/projects/ifmetric/ifmetric-0.1.tar.gz">Version
+0.1</a> released</p>
+
+<h2><a name="overview">Overview</a></h2>
+
+<p><tt>ifmetric</tt> is a Linux tool for setting the metrics of all
+IPv4 routes attached to a given network interface at once. This
+may be used to change the priority of routing IPv4 traffic over
+the interface. Lower metrics correlate with higher
+priorities.</p>
+
+<h2><a name="status">Status</a></h2>
+
+<p>Version @PACKAGE_VERSION@ is stable and feature complete.</p>
+
+<h2><a name="documentation">Documentation</a></h2>
+
+<h3><tt>ifmetric</tt>'s purpose</h3>
+
+<p>Sometimes two network interfaces of different speeds with equal
+routes are available at the same time. (e.g. a laptop with both a
+wireless and a copper LAN card) The one with the greater througput
+should be preferred over the other. To achieve this, you may use the
+route's metric field. Routes with lower metrics are preferred over
+those with higher. Unfortunately many network configurators (like DHCP
+clients) do not support to set the metric for a
+route. <tt>ifmetric</tt> may be used to manipulate the metrics of
+routes a posteriori. The default metric for a route in the Linux
+kernel is 0, meaning the highest priority.</p>
+
+<p><tt>ifmetric</tt> makes use of the NETLINK interface of the Linux
+kernel for manipulating the routes. Thus, <tt>ifmetric</tt> is
+compatible with complex routes created with <tt>iproute2</tt>.</p>
+
+<p><tt>ifmetric</tt> doesn't modify the routes atomically. The is due
+to the NETLINK API. However, this should not hurt since
+<tt>ifmetric</tt> makes sure that not routes are ever lost while
+modifying them.</p>
+
+<h3>Usage</h3>
+
+<p>To give all other interfaces a higher priority than <tt>wlan0</tt> simply run:</p>
+
+<pre>ifmetric wlan0 1</pre>
+
+<p>To reset the metrics of the routes attached to <tt>wlan0</tt> simply run:
+
+<pre>ifmetric wlan0 0</pre>
+
+<h2><a name="requirements">Requirements</a></h2>
+
+<p>A newer Linux Kernel supporting the NETLINK API. (I think 2.2 is
+good enough).</p>
+
+<p><tt>ifmetric</tt> was developed and tested on Debian GNU/Linux
+"testing" from August 2003, it should work on most other Linux
+distributions since it uses GNU autoconf for
+source code configuration.</p>
+
+<h2><a name="installation">Installation</a></h2>
+
+<p>As this package is made with the GNU autotools you should run
+<tt>./configure</tt> inside the distribution directory for configuring
+the source tree. After that you should run <tt>make</tt> for
+compilation and <tt>make install</tt> (as root) for installation of
+<tt>ifmetric</tt>.</p>
+
+<p>The Linux kernel headers have to be available during compilation.</p>
+
+<h2><a name="acks">Acknowledgements</a></h2>
+
+<p>For the developers of <tt>iproute2</tt> and <tt>zebra</tt>, since I looked
+on their source codes for learning how to use NETLINK.</p>
+
+<h2><a name="download">Download</a></h2>
+
+<p>The newest release is always available from <a href="http://www.stud.uni-hamburg.de/~lennart/projects/ifmetric/">http://www.stud.uni-hamburg.de/~lennart/projects/ifmetric/</a></p>
+
+<p>The current release is <a href="http://www.stud.uni-hamburg.de/~lennart/projects/ifmetric/ifmetric-@PACKAGE_VERSION@.tar.gz">@PACKAGE_VERSION@</a></p>
+
+<hr/>
+
+<address>Lennart Poettering &lt;mzvszrgevp [at] itaparica.org&gt;, July 2003</address>
+
+<div><i>$Id$</i></div>
+
+</body>
+</html>
diff --git a/doc/style.css b/doc/style.css
new file mode 100644
index 0000000..0a40aef
--- /dev/null
+++ b/doc/style.css
@@ -0,0 +1,12 @@
+/* $Id$ */
+body { color: black; background-color: white; margin: 0.5cm; }
+a:link, a:visited { color: #900000; }
+p { margin-left: 0.5cm; margin-right: 0.5cm; }
+div.news-date { margin-left: 0.5cm; font-size: 80%; color: #4f0000; }
+p.news-text { margin-left: 1cm; }
+ul { margin-left: .5cm; }
+ol { margin-left: .5cm; }
+h1 { color: #00009F; }
+h2 { color: #00009F; }
+h3 { color: #00004F; margin-left: 0.5cm; }
+pre { margin-left: .5cm; background-color: #f0f0f0; padding: 0.4cm;}
diff --git a/man/Makefile.am b/man/Makefile.am
new file mode 100644
index 0000000..26be22c
--- /dev/null
+++ b/man/Makefile.am
@@ -0,0 +1,30 @@
+# $Id$
+
+# This file is part of ifmetric.
+#
+# ifmetric is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifmetric is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifmetric; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+man_MANS = ifmetric.8
+
+EXTRA_DIST = $(man_MANS) ifmetric.8.xml.in
+
+if USE_XMLTOMAN
+
+CLEANFILES = $(man_MANS)
+
+ifmetric.8: ifmetric.8.xml.in Makefile
+ sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' $< | xmltoman - > $@
+
+endif
diff --git a/man/ifmetric.8.xml.in b/man/ifmetric.8.xml.in
new file mode 100644
index 0000000..050cb4d
--- /dev/null
+++ b/man/ifmetric.8.xml.in
@@ -0,0 +1,73 @@
+<?xml version="1.0" standalone='no'?>
+<!DOCTYPE spec SYSTEM "man.dtd">
+
+<!-- $Id$ -->
+
+<!--
+ This file is part of ifmetric.
+
+ ifmetric is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your
+ option) any later version.
+
+ ifmetric is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ifmetric; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+-->
+
+ <manpage name="ifmetric" section="8" desc="An IPv4 route metrics manipulation tool">
+
+ <synopsis>
+ <cmd>ifmetric <arg>INTERFACE</arg> [<arg>METRIC</arg>]</cmd>
+ </synopsis>
+
+ <description> <p>ifmetric is a Linux tool for setting the metrics of all
+ IPv4 routes attached to a given network interface at once. This
+ may be used to change the priority of routing IPv4 traffic over
+ the interface. Lower metrics correlate with higher
+ priorities.</p>
+
+ <p>ifmetric uses the Linux NETLINK interface to manipulate the
+ routes. Because of that it is compatible with routes created with
+ the new iproute2 utility.</p>
+ </description>
+
+ <options>
+
+ <p>You should specify the interface name as first parameter. The
+ second parameter should be the new metric. If ommited the metric
+ 0 (highest) is used.</p>
+
+ </options>
+
+ <section name="Return values">
+ <p><arg>0</arg> Success</p>
+ <p><arg>1</arg> Failure</p>
+ </section>
+
+ <section name="Author">
+ <p>ifmetric was written by Lennart Poettering
+ &lt;@PACKAGE_BUGREPORT@&gt;. ifmetric is available
+ at <url
+ href="http://www.stud.uni-hamburg.de/users/lennart/projects/ifmetric/"/>
+ </p>
+ </section>
+
+ <section name="See also">
+ <p>
+ <manref name="route" section="8"/>, iproute2
+ </p>
+ </section>
+
+ <section name="Comments">
+ <p>This man page was written using <manref name="xml2man" section="1"
+ href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
+ </section>
+
+ </manpage>
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..ff501ea
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,23 @@
+# $Id$
+
+# This file is part of ifmetric.
+#
+# ifmetric is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ifmetric is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with ifmetric; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+
+sbin_PROGRAMS = ifmetric
+
+ifmetric_SOURCES = ifmetric.c getifn.h getifn.c nlrequest.h nlrequest.c
+
diff --git a/src/getifn.c b/src/getifn.c
new file mode 100644
index 0000000..74dfc72
--- /dev/null
+++ b/src/getifn.c
@@ -0,0 +1,77 @@
+#include <string.h>
+#include <stdio.h>
+
+#include "getifn.h"
+#include "nlrequest.h"
+
+struct getifn_info {
+ char ifname[IFNAMSIZ+1];
+ int idx;
+};
+
+int getifn_callback(struct nlmsghdr *n, void *u) {
+ struct rtattr *a = NULL;
+ int l;
+ struct getifn_info *gi = (struct getifn_info*) u;
+ struct ifinfomsg *i;
+
+ if (n->nlmsg_type != RTM_NEWLINK) {
+ fprintf(stderr, "NETLINK: Got response for wrong request.\n");
+ return -1;
+ }
+
+ i = NLMSG_DATA(n);
+ l = NLMSG_PAYLOAD(n, sizeof(struct ifinfomsg));
+ a = IFLA_RTA(i);
+
+ while(RTA_OK(a, l)) {
+
+ switch(a->rta_type) {
+ case IFLA_IFNAME:
+ if (strncmp(RTA_DATA(a), gi->ifname, IFNAMSIZ) == 0) {
+ gi->idx = i->ifi_index;
+ return 0;
+ }
+ }
+ a = RTA_NEXT(a, l);
+ }
+
+ return 0;
+}
+
+int getifn(int s, char *iface) {
+ struct getifn_info gi;
+
+ struct {
+ struct nlmsghdr n;
+ struct ifinfomsg i;
+ char a[1024];
+ } req;
+
+ memset(&req, 0, sizeof(req));
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_MATCH;
+ req.n.nlmsg_type = RTM_GETLINK;
+
+ req.i.ifi_family = AF_UNSPEC;
+ req.i.ifi_change = -1;
+
+ memset(&gi, 0, sizeof(gi));
+ strncpy(gi.ifname, iface, IFNAMSIZ);
+ gi.idx = -1;
+
+ if (addattr_l(&req.n, sizeof(req), IFLA_IFNAME, gi.ifname, IFNAMSIZ+1) < 0) {
+ fprintf(stderr, "Failed to add attribute to netlink message\n");
+ return -1;
+ }
+
+ if (netlink_request(s, (struct nlmsghdr*) &req, getifn_callback, &gi) < 0)
+ return -1;
+
+ if (gi.idx < 0) {
+ fprintf(stderr, "Interface '%s' not existent.\n", iface);
+ return -1;
+ }
+
+ return gi.idx;
+}
diff --git a/src/getifn.h b/src/getifn.h
new file mode 100644
index 0000000..3c4cff8
--- /dev/null
+++ b/src/getifn.h
@@ -0,0 +1,7 @@
+#ifndef foogetifnhfoo
+#define foogetifnhfoo
+
+/* Return the kernel index for the given interface. */
+int getifn(int s, char *iface);
+
+#endif
diff --git a/src/ifmetric.c b/src/ifmetric.c
new file mode 100644
index 0000000..a232061
--- /dev/null
+++ b/src/ifmetric.c
@@ -0,0 +1,204 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <linux/types.h>
+#include <linux/if.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "nlrequest.h"
+#include "getifn.h"
+
+#define MAX_ROUTES 64
+
+struct nlmsghdr* routes[MAX_ROUTES];
+int n_routes = 0;
+
+int enumerate_callback(struct nlmsghdr *n, void *u) {
+ struct rtmsg *r;
+ struct rtattr *a = NULL;
+ int l, *ifn = u;
+
+ if (n->nlmsg_type != RTM_NEWROUTE) {
+ fprintf(stderr, "NETLINK: Got response for wrong request.\n");
+ return -1;
+ }
+
+ r = NLMSG_DATA(n);
+ l = NLMSG_PAYLOAD(n, sizeof(struct rtmsg));
+ a = RTM_RTA(r);
+
+ if (r->rtm_table != RT_TABLE_MAIN)
+ return 0;
+
+ while(RTA_OK(a, l)) {
+ switch(a->rta_type) {
+ case RTA_OIF:
+
+ if (RTA_PAYLOAD(a) != sizeof(int)) {
+ fprintf(stderr, "NETLINK: Recieved corrupt RTA_OIF payload.\n");
+ return -1;
+ }
+
+ if (*((int*) RTA_DATA(a)) == *ifn) {
+
+ if (n_routes < MAX_ROUTES) {
+ struct nlmsghdr* copy;
+
+ if (!(copy = malloc(n->nlmsg_len))) {
+ fprintf(stderr, "Could not allocate memory.\n");
+ return -1;
+ }
+
+ memcpy(copy, n, n->nlmsg_len);
+ routes[n_routes++] = copy;
+
+ } else
+ fprintf(stderr, "Found too many routes.\n");
+
+ break;
+ }
+
+
+ }
+
+ a = RTA_NEXT(a, l);
+ }
+
+ return 0;
+}
+
+int enumerate(int s, int ifn) {
+ struct {
+ struct nlmsghdr n;
+ struct rtmsg r;
+ char a[1024];
+ } req;
+
+ memset(&req, 0, sizeof(req));
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_MATCH;
+ req.n.nlmsg_type = RTM_GETROUTE;
+
+ req.r.rtm_family = AF_INET;
+ req.r.rtm_table = RT_TABLE_MAIN;
+
+ return netlink_request(s, (struct nlmsghdr*) &req, enumerate_callback, &ifn);
+}
+
+struct nlmsghdr* set_route_metric(struct nlmsghdr* n, int metric) {
+ struct rtmsg *r;
+ struct rtattr *a = NULL;
+ int l, t;
+
+ r = NLMSG_DATA(n);
+ l = NLMSG_PAYLOAD(n, sizeof(struct rtmsg));
+ a = RTM_RTA(r);
+
+ while(RTA_OK(a, l)) {
+ switch(a->rta_type) {
+ case RTA_PRIORITY:
+
+ if (RTA_PAYLOAD(a) != sizeof(int)) {
+ fprintf(stderr, "NETLINK: Recieved corrupt RTA_PRIORITY payload.\n");
+ return NULL;
+ }
+
+ *((int*) RTA_DATA(a)) = metric;
+ return n;
+ }
+
+ a = RTA_NEXT(a, l);
+ }
+
+ if ((n = realloc(n, (t = n->nlmsg_len+1024))))
+ addattr32(n, t, RTA_PRIORITY, metric);
+ else
+ fprintf(stderr, "realloc() failed.\n");
+
+ return n;
+}
+
+int delete_route(int s, struct nlmsghdr* n) {
+ assert(s >= 0 && n);
+
+ n->nlmsg_type = RTM_DELROUTE;
+ n->nlmsg_flags = NLM_F_REQUEST;
+
+ return netlink_request(s, n, NULL, NULL);
+}
+
+int add_route(int s, struct nlmsghdr* n) {
+ assert(s >= 0 && n);
+
+ n->nlmsg_type = RTM_NEWROUTE;
+ n->nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE;
+
+ return netlink_request(s, n, NULL, NULL);
+}
+
+
+int go(char *iface, int metric) {
+ int r = -1, j;
+ int s = -1, ifn;
+
+ if ((s = netlink_open()) < 0)
+ return -1;
+
+ if ((ifn = getifn(s, iface)) < 0)
+ goto finish;
+
+ n_routes = 0;
+ if (enumerate(s, ifn) < 0)
+ goto finish;
+
+ if (n_routes) {
+ for (j = 0; j < n_routes; j++) {
+ if (delete_route(s, routes[j]) >= 0)
+ if ((routes[j] = set_route_metric(routes[j], metric)))
+ add_route(s, routes[j]);
+
+ free(routes[j]);
+ }
+ }
+
+ r = 0;
+
+finish:
+
+ if (s >= 0)
+ close(s);
+
+ return r;
+}
+
+int main(int argc, char *argv[]) {
+ char *iface;
+ int metric;
+
+ if (argc <= 1 || (argc > 1 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))) {
+ char *b;
+
+ if ((b = strrchr(argv[0], '/')))
+ b++;
+ else
+ b = argv[0];
+
+ printf("Usage: %s <iface> [metric]\n"
+ "\n"
+ "%s is a tool for setting the metrics of all IPv4 routes\n"
+ "attached to a given network interface at once.\n"
+ "\n"
+ " <iface> The interface\n"
+ " <metric> The new metric (default: 0)\n", b, b);
+ return 0;
+ }
+
+ iface = argv[1];
+ metric = argc > 2 ? atoi(argv[2]) : 0;
+
+ return go(iface, metric) < 0 ? 1 : 0;
+
+}
diff --git a/src/nlrequest.c b/src/nlrequest.c
new file mode 100644
index 0000000..1f72357
--- /dev/null
+++ b/src/nlrequest.c
@@ -0,0 +1,139 @@
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "nlrequest.h"
+
+int netlink_open(void) {
+ struct sockaddr_nl addr;
+ int s;
+
+ if ((s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0) {
+ fprintf(stderr, "socket(PF_NETLINK): %s\n", strerror(errno));
+ return -1;
+ }
+
+ memset(&addr, 0, sizeof(addr));
+ addr.nl_family = AF_NETLINK;
+ addr.nl_groups = 0;
+ addr.nl_pid = getpid();
+
+ if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ fprintf(stderr, "bind(): %s\n", strerror(errno));
+ return -1;
+ }
+
+ return s;
+}
+
+
+int netlink_request(int s, struct nlmsghdr *n, int (*callback) (struct nlmsghdr *n, void *u), void *u) {
+ static int seq = 0;
+ pid_t pid = getpid();
+ assert(s >= 0 && n);
+
+ n->nlmsg_seq = seq++;
+ n->nlmsg_flags |= NLM_F_ACK;
+
+ if (send(s, n, n->nlmsg_len, 0) < 0) {
+ fprintf(stderr, "NETLINK: send(): %s\n", strerror(errno));
+ return -1;
+ }
+
+ for (;;) {
+ int bytes;
+ char replybuf[1024];
+ struct nlmsghdr *p = (struct nlmsghdr *) replybuf;
+
+ if ((bytes = recv(s, &replybuf, sizeof(replybuf), 0)) < 0) {
+ fprintf(stderr, "recv(): %s\n", strerror(errno));
+ return -1;
+ }
+
+ for (; bytes > 0; p = NLMSG_NEXT(p, bytes)) {
+ int ret;
+
+ if (!NLMSG_OK(p, bytes) || bytes < sizeof(struct nlmsghdr) || bytes < p->nlmsg_len) {
+ fprintf(stderr, "NETLINK: Packet too small or truncated!\n");
+ return -1;
+ }
+
+ if (p->nlmsg_type == NLMSG_DONE)
+ return 0;
+
+ if (p->nlmsg_type == NLMSG_ERROR) {
+ struct nlmsgerr *e = (struct nlmsgerr *) NLMSG_DATA (p);
+
+ if (e->error) {
+ fprintf(stderr, "NETLINK: Error: %s\n", strerror(-e->error));
+ return -1;
+ } else
+ return 0;
+ }
+
+ if (p->nlmsg_pid != pid)
+ continue;
+
+ if (p->nlmsg_seq != n->nlmsg_seq) {
+ fprintf(stderr, "NETLINK: Received message with bogus sequence number!\n");
+ continue;
+ }
+
+ if (callback)
+ if ((ret = callback(p, u)) < 0)
+ return ret;
+ }
+ }
+
+ return 0;
+}
+
+/*
+ * Utility function comes from iproute2.
+ * Author: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
+ */
+
+int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen) {
+ int len;
+ struct rtattr *rta;
+
+ len = RTA_LENGTH(alen);
+
+ if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen)
+ return -1;
+
+ rta = (struct rtattr*) (((char*)n) + NLMSG_ALIGN (n->nlmsg_len));
+ rta->rta_type = type;
+ rta->rta_len = len;
+ memcpy (RTA_DATA(rta), data, alen);
+ n->nlmsg_len = NLMSG_ALIGN (n->nlmsg_len) + len;
+
+ return 0;
+}
+
+/*
+ * Utility function comes from iproute2.
+ * Author: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
+ */
+
+
+int addattr32(struct nlmsghdr *n, int maxlen, int type, int data) {
+ int len;
+ struct rtattr *rta;
+
+ len = RTA_LENGTH(4);
+
+ if (NLMSG_ALIGN (n->nlmsg_len) + len > maxlen)
+ return -1;
+
+ rta = (struct rtattr*) (((char*)n) + NLMSG_ALIGN (n->nlmsg_len));
+ rta->rta_type = type;
+ rta->rta_len = len;
+ memcpy (RTA_DATA(rta), &data, 4);
+ n->nlmsg_len = NLMSG_ALIGN (n->nlmsg_len) + len;
+
+ return 0;
+}
+
diff --git a/src/nlrequest.h b/src/nlrequest.h
new file mode 100644
index 0000000..efe3450
--- /dev/null
+++ b/src/nlrequest.h
@@ -0,0 +1,20 @@
+#ifndef foonlrequesthfoo
+#define foonlrequesthfoo
+
+#include <sys/socket.h>
+#include <linux/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/if.h>
+
+/* Issue a netlink message and wait for a response, calling 'callback' for every response message */
+int netlink_request(int s, struct nlmsghdr *n, int (*callback) (struct nlmsghdr *n, void*u), void *u);
+
+int addattr32(struct nlmsghdr *n, int maxlen, int type, int data);
+int addattr_l(struct nlmsghdr *n, int maxlen, int type, void *data, int alen);
+
+int netlink_open(void);
+
+
+#endif
+