Initial revision

git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2004-06-24 14:18:37 +00:00
parent 51bb897c07
commit c39587c1c2
35 changed files with 11699 additions and 0 deletions

2
AUTHORS Normal file
View file

@ -0,0 +1,2 @@
Dan Williams <dcbw@redhat.com>

0
ChangeLog Normal file
View file

1
Makefile.am Normal file
View file

@ -0,0 +1 @@
SUBDIRS = src initscript test

493
Makefile.in Normal file
View file

@ -0,0 +1,493 @@
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = .
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
IWLIB = @IWLIB@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
NM_CFLAGS = @NM_CFLAGS@
NM_LIBS = @NM_LIBS@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build_alias = @build_alias@
datadir = @datadir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
SUBDIRS = src initscript test
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
DIST_SOURCES =
RECURSIVE_TARGETS = info-recursive dvi-recursive pdf-recursive \
ps-recursive install-info-recursive uninstall-info-recursive \
all-recursive install-data-recursive install-exec-recursive \
installdirs-recursive install-recursive uninstall-recursive \
check-recursive installcheck-recursive
DIST_COMMON = README $(srcdir)/Makefile.in $(srcdir)/configure AUTHORS \
COPYING ChangeLog INSTALL Makefile.am NEWS aclocal.m4 configure \
configure.in depcomp install-sh missing mkinstalldirs
DIST_SUBDIRS = $(SUBDIRS)
all: all-recursive
.SUFFIXES:
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
configure.lineno
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)
$(top_builddir)/config.status: $(srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
$(SHELL) ./config.status --recheck
$(srcdir)/configure: $(srcdir)/configure.in $(ACLOCAL_M4) $(CONFIGURE_DEPENDENCIES)
cd $(srcdir) && $(AUTOCONF)
$(ACLOCAL_M4): configure.in
cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
uninstall-info-am:
# This directory's subdirectories are mostly independent; you can cd
# into them and run `make' without going through this Makefile.
# To change the values of `make' variables: instead of editing Makefiles,
# (1) if the variable is set in `config.status', edit `config.status'
# (which will cause the Makefiles to be regenerated when you run `make');
# (2) otherwise, pass the desired values on the `make' command line.
$(RECURSIVE_TARGETS):
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done; \
if test "$$dot_seen" = "no"; then \
$(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
fi; test -z "$$fail"
mostlyclean-recursive clean-recursive distclean-recursive \
maintainer-clean-recursive:
@set fnord $$MAKEFLAGS; amf=$$2; \
dot_seen=no; \
case "$@" in \
distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
*) list='$(SUBDIRS)' ;; \
esac; \
rev=''; for subdir in $$list; do \
if test "$$subdir" = "."; then :; else \
rev="$$subdir $$rev"; \
fi; \
done; \
rev="$$rev ."; \
target=`echo $@ | sed s/-recursive//`; \
for subdir in $$rev; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
done && test -z "$$fail"
tags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
done
ctags-recursive:
list='$(SUBDIRS)'; for subdir in $$list; do \
test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
done
ETAGS = etags
ETAGSFLAGS =
CTAGS = ctags
CTAGSFLAGS =
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
TAGS: tags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
if (etags --etags-include --version) >/dev/null 2>&1; then \
include_option=--etags-include; \
else \
include_option=--include; \
fi; \
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -f $$subdir/TAGS && \
tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
fi; \
done; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique
ctags: CTAGS
CTAGS: ctags-recursive $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
top_distdir = .
distdir = $(PACKAGE)-$(VERSION)
am__remove_distdir = \
{ test ! -d $(distdir) \
|| { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
&& rm -fr $(distdir); }; }
GZIP_ENV = --best
distuninstallcheck_listfiles = find . -type f -print
distcleancheck_listfiles = find . -type f -print
distdir: $(DISTFILES)
$(am__remove_distdir)
mkdir $(distdir)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkinstalldirs) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
list='$(SUBDIRS)'; for subdir in $$list; do \
if test "$$subdir" = .; then :; else \
test -d $(distdir)/$$subdir \
|| mkdir $(distdir)/$$subdir \
|| exit 1; \
(cd $$subdir && \
$(MAKE) $(AM_MAKEFLAGS) \
top_distdir="$(top_distdir)" \
distdir=../$(distdir)/$$subdir \
distdir) \
|| exit 1; \
fi; \
done
-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
|| chmod -R a+r $(distdir)
dist-gzip: distdir
$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
dist dist-all: distdir
$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
$(am__remove_distdir)
# This target untars the dist file and tries a VPATH configuration. Then
# it guarantees that the distribution is self-contained by making another
# tarfile.
distcheck: dist
$(am__remove_distdir)
GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf -
chmod -R a-w $(distdir); chmod a+w $(distdir)
mkdir $(distdir)/_build
mkdir $(distdir)/_inst
chmod a-w $(distdir)
dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
&& dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
&& cd $(distdir)/_build \
&& ../configure --srcdir=.. --prefix="$$dc_install_base" \
$(DISTCHECK_CONFIGURE_FLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) \
&& $(MAKE) $(AM_MAKEFLAGS) dvi \
&& $(MAKE) $(AM_MAKEFLAGS) check \
&& $(MAKE) $(AM_MAKEFLAGS) install \
&& $(MAKE) $(AM_MAKEFLAGS) installcheck \
&& $(MAKE) $(AM_MAKEFLAGS) uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
distuninstallcheck \
&& chmod -R a-w "$$dc_install_base" \
&& ({ \
(cd ../.. && $(mkinstalldirs) "$$dc_destdir") \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
&& $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
} || { rm -rf "$$dc_destdir"; exit 1; }) \
&& rm -rf "$$dc_destdir" \
&& $(MAKE) $(AM_MAKEFLAGS) dist-gzip \
&& rm -f $(distdir).tar.gz \
&& $(MAKE) $(AM_MAKEFLAGS) distcleancheck
$(am__remove_distdir)
@echo "$(distdir).tar.gz is ready for distribution" | \
sed 'h;s/./=/g;p;x;p;x'
distuninstallcheck:
@cd $(distuninstallcheck_dir) \
&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
|| { echo "ERROR: files left after uninstall:" ; \
if test -n "$(DESTDIR)"; then \
echo " (check DESTDIR support)"; \
fi ; \
$(distuninstallcheck_listfiles) ; \
exit 1; } >&2
distcleancheck: distclean
@if test '$(srcdir)' = . ; then \
echo "ERROR: distcleancheck can only run from a VPATH build" ; \
exit 1 ; \
fi
@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
|| { echo "ERROR: files left in build directory after distclean:" ; \
$(distcleancheck_listfiles) ; \
exit 1; } >&2
check-am: all-am
check: check-recursive
all-am: Makefile
installdirs: installdirs-recursive
installdirs-am:
install: install-recursive
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-recursive
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-recursive
clean-am: clean-generic mostlyclean-am
distclean: distclean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -f Makefile
distclean-am: clean-am distclean-generic distclean-tags
dvi: dvi-recursive
dvi-am:
info: info-recursive
info-am:
install-data-am:
install-exec-am:
install-info: install-info-recursive
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-recursive
-rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-recursive
mostlyclean-am: mostlyclean-generic
pdf: pdf-recursive
pdf-am:
ps: ps-recursive
ps-am:
uninstall-am: uninstall-info-am
uninstall-info: uninstall-info-recursive
.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am clean \
clean-generic clean-recursive ctags ctags-recursive dist \
dist-all dist-gzip distcheck distclean distclean-generic \
distclean-recursive distclean-tags distcleancheck distdir \
distuninstallcheck dvi dvi-am dvi-recursive info info-am \
info-recursive install install-am install-data install-data-am \
install-data-recursive install-exec install-exec-am \
install-exec-recursive install-info install-info-am \
install-info-recursive install-man install-recursive \
install-strip installcheck installcheck-am installdirs \
installdirs-am installdirs-recursive maintainer-clean \
maintainer-clean-generic maintainer-clean-recursive mostlyclean \
mostlyclean-generic mostlyclean-recursive pdf pdf-am \
pdf-recursive ps ps-am ps-recursive tags tags-recursive \
uninstall uninstall-am uninstall-info-am \
uninstall-info-recursive uninstall-recursive
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

0
NEWS Normal file
View file

BIN
NetworkManager-0.1.tar.gz Normal file

Binary file not shown.

0
README Normal file
View file

893
aclocal.m4 vendored Normal file
View file

@ -0,0 +1,893 @@
# generated automatically by aclocal 1.7.9 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
# Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
# Do all the work for Automake. -*- Autoconf -*-
# This macro actually does too much some checks are only needed if
# your package does certain things. But this isn't really a big deal.
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# 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, 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.
# serial 10
AC_PREREQ([2.54])
# Autoconf 2.50 wants to disallow AM_ names. We explicitly allow
# the ones we care about.
m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
# AM_INIT_AUTOMAKE([OPTIONS])
# -----------------------------------------------
# The call with PACKAGE and VERSION arguments is the old style
# call (pre autoconf-2.50), which is being phased out. PACKAGE
# and VERSION should now be passed to AC_INIT and removed from
# the call to AM_INIT_AUTOMAKE.
# We support both call styles for the transition. After
# the next Automake release, Autoconf can make the AC_INIT
# arguments mandatory, and then we can depend on a new Autoconf
# release and drop the old call support.
AC_DEFUN([AM_INIT_AUTOMAKE],
[AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
AC_REQUIRE([AC_PROG_INSTALL])dnl
# test to see if srcdir already configured
if test "`cd $srcdir && pwd`" != "`pwd`" &&
test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
# test whether we have cygpath
if test -z "$CYGPATH_W"; then
if (cygpath --version) >/dev/null 2>/dev/null; then
CYGPATH_W='cygpath -w'
else
CYGPATH_W=echo
fi
fi
AC_SUBST([CYGPATH_W])
# Define the identity of the package.
dnl Distinguish between old-style and new-style calls.
m4_ifval([$2],
[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
AC_SUBST([PACKAGE], [$1])dnl
AC_SUBST([VERSION], [$2])],
[_AM_SET_OPTIONS([$1])dnl
AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
_AM_IF_OPTION([no-define],,
[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
# Some tools Automake needs.
AC_REQUIRE([AM_SANITY_CHECK])dnl
AC_REQUIRE([AC_ARG_PROGRAM])dnl
AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
AM_MISSING_PROG(AUTOCONF, autoconf)
AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
AM_MISSING_PROG(AUTOHEADER, autoheader)
AM_MISSING_PROG(MAKEINFO, makeinfo)
AM_MISSING_PROG(AMTAR, tar)
AM_PROG_INSTALL_SH
AM_PROG_INSTALL_STRIP
# We need awk for the "check" target. The system "awk" is bad on
# some platforms.
AC_REQUIRE([AC_PROG_AWK])dnl
AC_REQUIRE([AC_PROG_MAKE_SET])dnl
AC_REQUIRE([AM_SET_LEADING_DOT])dnl
_AM_IF_OPTION([no-dependencies],,
[AC_PROVIDE_IFELSE([AC_PROG_CC],
[_AM_DEPENDENCIES(CC)],
[define([AC_PROG_CC],
defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
AC_PROVIDE_IFELSE([AC_PROG_CXX],
[_AM_DEPENDENCIES(CXX)],
[define([AC_PROG_CXX],
defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
])
])
# When config.status generates a header, we must update the stamp-h file.
# This file resides in the same directory as the config header
# that is generated. The stamp files are numbered to have different names.
# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
# loop where config.status creates the headers, so we can generate
# our stamp files there.
AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
[# Compute $1's index in $config_headers.
_am_stamp_count=1
for _am_header in $config_headers :; do
case $_am_header in
$1 | $1:* )
break ;;
* )
_am_stamp_count=`expr $_am_stamp_count + 1` ;;
esac
done
echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count])
# Copyright 2002 Free Software Foundation, Inc.
# 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, 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
# AM_AUTOMAKE_VERSION(VERSION)
# ----------------------------
# Automake X.Y traces this macro to ensure aclocal.m4 has been
# generated from the m4 files accompanying Automake X.Y.
AC_DEFUN([AM_AUTOMAKE_VERSION],[am__api_version="1.7"])
# AM_SET_CURRENT_AUTOMAKE_VERSION
# -------------------------------
# Call AM_AUTOMAKE_VERSION so it can be traced.
# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
[AM_AUTOMAKE_VERSION([1.7.9])])
# Helper functions for option handling. -*- Autoconf -*-
# Copyright 2001, 2002 Free Software Foundation, Inc.
# 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, 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.
# serial 2
# _AM_MANGLE_OPTION(NAME)
# -----------------------
AC_DEFUN([_AM_MANGLE_OPTION],
[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
# _AM_SET_OPTION(NAME)
# ------------------------------
# Set option NAME. Presently that only means defining a flag for this option.
AC_DEFUN([_AM_SET_OPTION],
[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
# _AM_SET_OPTIONS(OPTIONS)
# ----------------------------------
# OPTIONS is a space-separated list of Automake options.
AC_DEFUN([_AM_SET_OPTIONS],
[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
# -------------------------------------------
# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
AC_DEFUN([_AM_IF_OPTION],
[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
#
# Check to make sure that the build environment is sane.
#
# Copyright 1996, 1997, 2000, 2001 Free Software Foundation, Inc.
# 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, 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.
# serial 3
# AM_SANITY_CHECK
# ---------------
AC_DEFUN([AM_SANITY_CHECK],
[AC_MSG_CHECKING([whether build environment is sane])
# Just in case
sleep 1
echo timestamp > conftest.file
# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
if test "$[*]" = "X"; then
# -L didn't work.
set X `ls -t $srcdir/configure conftest.file`
fi
rm -f conftest.file
if test "$[*]" != "X $srcdir/configure conftest.file" \
&& test "$[*]" != "X conftest.file $srcdir/configure"; then
# If neither matched, then we have a broken ls. This can happen
# if, for instance, CONFIG_SHELL is bash and it inherits a
# broken ls alias from the environment. This has actually
# happened. Such a system could not be considered "sane".
AC_MSG_ERROR([ls -t appears to fail. Make sure there is not a broken
alias in your environment])
fi
test "$[2]" = conftest.file
)
then
# Ok.
:
else
AC_MSG_ERROR([newly created file is older than distributed files!
Check your system clock])
fi
AC_MSG_RESULT(yes)])
# -*- Autoconf -*-
# Copyright 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
# 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, 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.
# serial 3
# AM_MISSING_PROG(NAME, PROGRAM)
# ------------------------------
AC_DEFUN([AM_MISSING_PROG],
[AC_REQUIRE([AM_MISSING_HAS_RUN])
$1=${$1-"${am_missing_run}$2"}
AC_SUBST($1)])
# AM_MISSING_HAS_RUN
# ------------------
# Define MISSING if not defined so far and test if it supports --run.
# If it does, set am_missing_run to use it, otherwise, to nothing.
AC_DEFUN([AM_MISSING_HAS_RUN],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"
# Use eval to expand $SHELL
if eval "$MISSING --run true"; then
am_missing_run="$MISSING --run "
else
am_missing_run=
AC_MSG_WARN([`missing' script is too old or missing])
fi
])
# AM_AUX_DIR_EXPAND
# Copyright 2001 Free Software Foundation, Inc.
# 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, 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.
# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
# $ac_aux_dir to `$srcdir/foo'. In other projects, it is set to
# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
#
# Of course, Automake must honor this variable whenever it calls a
# tool from the auxiliary directory. The problem is that $srcdir (and
# therefore $ac_aux_dir as well) can be either absolute or relative,
# depending on how configure is run. This is pretty annoying, since
# it makes $ac_aux_dir quite unusable in subdirectories: in the top
# source directory, any form will work fine, but in subdirectories a
# relative path needs to be adjusted first.
#
# $ac_aux_dir/missing
# fails when called from a subdirectory if $ac_aux_dir is relative
# $top_srcdir/$ac_aux_dir/missing
# fails if $ac_aux_dir is absolute,
# fails when called from a subdirectory in a VPATH build with
# a relative $ac_aux_dir
#
# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
# are both prefixed by $srcdir. In an in-source build this is usually
# harmless because $srcdir is `.', but things will broke when you
# start a VPATH build or use an absolute $srcdir.
#
# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
# iff we strip the leading $srcdir from $ac_aux_dir. That would be:
# am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
# and then we would define $MISSING as
# MISSING="\${SHELL} $am_aux_dir/missing"
# This will work as long as MISSING is not called from configure, because
# unfortunately $(top_srcdir) has no meaning in configure.
# However there are other variables, like CC, which are often used in
# configure, and could therefore not use this "fixed" $ac_aux_dir.
#
# Another solution, used here, is to always expand $ac_aux_dir to an
# absolute PATH. The drawback is that using absolute paths prevent a
# configured tree to be moved without reconfiguration.
# Rely on autoconf to set up CDPATH properly.
AC_PREREQ([2.50])
AC_DEFUN([AM_AUX_DIR_EXPAND], [
# expand $ac_aux_dir to an absolute path
am_aux_dir=`cd $ac_aux_dir && pwd`
])
# AM_PROG_INSTALL_SH
# ------------------
# Define $install_sh.
# Copyright 2001 Free Software Foundation, Inc.
# 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, 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.
AC_DEFUN([AM_PROG_INSTALL_SH],
[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
install_sh=${install_sh-"$am_aux_dir/install-sh"}
AC_SUBST(install_sh)])
# AM_PROG_INSTALL_STRIP
# Copyright 2001 Free Software Foundation, Inc.
# 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, 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.
# One issue with vendor `install' (even GNU) is that you can't
# specify the program used to strip binaries. This is especially
# annoying in cross-compiling environments, where the build's strip
# is unlikely to handle the host's binaries.
# Fortunately install-sh will honor a STRIPPROG variable, so we
# always use install-sh in `make install-strip', and initialize
# STRIPPROG with the value of the STRIP variable (set by the user).
AC_DEFUN([AM_PROG_INSTALL_STRIP],
[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
# Installed binaries are usually stripped using `strip' when the user
# run `make install-strip'. However `strip' might not be the right
# tool to use in cross-compilation environments, therefore Automake
# will honor the `STRIP' environment variable to overrule this program.
dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
if test "$cross_compiling" != no; then
AC_CHECK_TOOL([STRIP], [strip], :)
fi
INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s"
AC_SUBST([INSTALL_STRIP_PROGRAM])])
# -*- Autoconf -*-
# Copyright (C) 2003 Free Software Foundation, Inc.
# 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, 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.
# serial 1
# Check whether the underlying file-system supports filenames
# with a leading dot. For instance MS-DOS doesn't.
AC_DEFUN([AM_SET_LEADING_DOT],
[rm -rf .tst 2>/dev/null
mkdir .tst 2>/dev/null
if test -d .tst; then
am__leading_dot=.
else
am__leading_dot=_
fi
rmdir .tst 2>/dev/null
AC_SUBST([am__leading_dot])])
# serial 5 -*- Autoconf -*-
# Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
# 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, 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.
# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
# written in clear, in which case automake, when reading aclocal.m4,
# will think it sees a *use*, and therefore will trigger all it's
# C support machinery. Also note that it means that autoscan, seeing
# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
# _AM_DEPENDENCIES(NAME)
# ----------------------
# See how the compiler implements dependency checking.
# NAME is "CC", "CXX", "GCJ", or "OBJC".
# We try a few techniques and use that to set a single cache variable.
#
# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
# dependency, and given that the user is not expected to run this macro,
# just rely on AC_PROG_CC.
AC_DEFUN([_AM_DEPENDENCIES],
[AC_REQUIRE([AM_SET_DEPDIR])dnl
AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
AC_REQUIRE([AM_MAKE_INCLUDE])dnl
AC_REQUIRE([AM_DEP_TRACK])dnl
ifelse([$1], CC, [depcc="$CC" am_compiler_list=],
[$1], CXX, [depcc="$CXX" am_compiler_list=],
[$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
[$1], GCJ, [depcc="$GCJ" am_compiler_list='gcc3 gcc'],
[depcc="$$1" am_compiler_list=])
AC_CACHE_CHECK([dependency style of $depcc],
[am_cv_$1_dependencies_compiler_type],
[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
# We make a subdir and do the tests there. Otherwise we can end up
# making bogus files that we don't know about and never remove. For
# instance it was reported that on HP-UX the gcc test will end up
# making a dummy file named `D' -- because `-MD' means `put the output
# in D'.
mkdir conftest.dir
# Copy depcomp to subdir because otherwise we won't find it if we're
# using a relative directory.
cp "$am_depcomp" conftest.dir
cd conftest.dir
# We will build objects and dependencies in a subdirectory because
# it helps to detect inapplicable dependency modes. For instance
# both Tru64's cc and ICC support -MD to output dependencies as a
# side effect of compilation, but ICC will put the dependencies in
# the current directory while Tru64 will put them in the object
# directory.
mkdir sub
am_cv_$1_dependencies_compiler_type=none
if test "$am_compiler_list" = ""; then
am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
fi
for depmode in $am_compiler_list; do
# Setup a source with many dependencies, because some compilers
# like to wrap large dependency lists on column 80 (with \), and
# we should not choose a depcomp mode which is confused by this.
#
# We need to recreate these files for each test, as the compiler may
# overwrite some of them when testing with obscure command lines.
# This happens at least with the AIX C compiler.
: > sub/conftest.c
for i in 1 2 3 4 5 6; do
echo '#include "conftst'$i'.h"' >> sub/conftest.c
: > sub/conftst$i.h
done
echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
case $depmode in
nosideeffect)
# after this tag, mechanisms are not by side-effect, so they'll
# only be used when explicitly requested
if test "x$enable_dependency_tracking" = xyes; then
continue
else
break
fi
;;
none) break ;;
esac
# We check with `-c' and `-o' for the sake of the "dashmstdout"
# mode. It turns out that the SunPro C++ compiler does not properly
# handle `-M -o', and we need to detect this.
if depmode=$depmode \
source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
$SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
>/dev/null 2>conftest.err &&
grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
${MAKE-make} -s -f confmf > /dev/null 2>&1; then
# icc doesn't choke on unknown options, it will just issue warnings
# (even with -Werror). So we grep stderr for any message
# that says an option was ignored.
if grep 'ignoring option' conftest.err >/dev/null 2>&1; then :; else
am_cv_$1_dependencies_compiler_type=$depmode
break
fi
fi
done
cd ..
rm -rf conftest.dir
else
am_cv_$1_dependencies_compiler_type=none
fi
])
AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
AM_CONDITIONAL([am__fastdep$1], [
test "x$enable_dependency_tracking" != xno \
&& test "$am_cv_$1_dependencies_compiler_type" = gcc3])
])
# AM_SET_DEPDIR
# -------------
# Choose a directory name for dependency files.
# This macro is AC_REQUIREd in _AM_DEPENDENCIES
AC_DEFUN([AM_SET_DEPDIR],
[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
])
# AM_DEP_TRACK
# ------------
AC_DEFUN([AM_DEP_TRACK],
[AC_ARG_ENABLE(dependency-tracking,
[ --disable-dependency-tracking Speeds up one-time builds
--enable-dependency-tracking Do not reject slow dependency extractors])
if test "x$enable_dependency_tracking" != xno; then
am_depcomp="$ac_aux_dir/depcomp"
AMDEPBACKSLASH='\'
fi
AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
AC_SUBST([AMDEPBACKSLASH])
])
# Generate code to set up dependency tracking. -*- Autoconf -*-
# Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
# 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, 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.
#serial 2
# _AM_OUTPUT_DEPENDENCY_COMMANDS
# ------------------------------
AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
[for mf in $CONFIG_FILES; do
# Strip MF so we end up with the name of the file.
mf=`echo "$mf" | sed -e 's/:.*$//'`
# Check whether this is an Automake generated Makefile or not.
# We used to match only the files named `Makefile.in', but
# some people rename them; so instead we look at the file content.
# Grep'ing the first line is not enough: some people post-process
# each Makefile.in and add a new line on top of each file to say so.
# So let's grep whole file.
if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then
dirpart=`AS_DIRNAME("$mf")`
else
continue
fi
grep '^DEP_FILES *= *[[^ @%:@]]' < "$mf" > /dev/null || continue
# Extract the definition of DEP_FILES from the Makefile without
# running `make'.
DEPDIR=`sed -n -e '/^DEPDIR = / s///p' < "$mf"`
test -z "$DEPDIR" && continue
# When using ansi2knr, U may be empty or an underscore; expand it
U=`sed -n -e '/^U = / s///p' < "$mf"`
test -d "$dirpart/$DEPDIR" || mkdir "$dirpart/$DEPDIR"
# We invoke sed twice because it is the simplest approach to
# changing $(DEPDIR) to its actual value in the expansion.
for file in `sed -n -e '
/^DEP_FILES = .*\\\\$/ {
s/^DEP_FILES = //
:loop
s/\\\\$//
p
n
/\\\\$/ b loop
p
}
/^DEP_FILES = / s/^DEP_FILES = //p' < "$mf" | \
sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
# Make sure the directory exists.
test -f "$dirpart/$file" && continue
fdir=`AS_DIRNAME(["$file"])`
AS_MKDIR_P([$dirpart/$fdir])
# echo "creating $dirpart/$file"
echo '# dummy' > "$dirpart/$file"
done
done
])# _AM_OUTPUT_DEPENDENCY_COMMANDS
# AM_OUTPUT_DEPENDENCY_COMMANDS
# -----------------------------
# This macro should only be invoked once -- use via AC_REQUIRE.
#
# This code is only required when automatic dependency tracking
# is enabled. FIXME. This creates each `.P' file that we will
# need in order to bootstrap the dependency handling code.
AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
[AC_CONFIG_COMMANDS([depfiles],
[test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
[AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
])
# Check to see how 'make' treats includes. -*- Autoconf -*-
# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
# 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, 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.
# serial 2
# AM_MAKE_INCLUDE()
# -----------------
# Check to see how make treats includes.
AC_DEFUN([AM_MAKE_INCLUDE],
[am_make=${MAKE-make}
cat > confinc << 'END'
am__doit:
@echo done
.PHONY: am__doit
END
# If we don't find an include directive, just comment out the code.
AC_MSG_CHECKING([for style of include used by $am_make])
am__include="#"
am__quote=
_am_result=none
# First try GNU make style include.
echo "include confinc" > confmf
# We grep out `Entering directory' and `Leaving directory'
# messages which can occur if `w' ends up in MAKEFLAGS.
# In particular we don't look at `^make:' because GNU make might
# be invoked under some other name (usually "gmake"), in which
# case it prints its new name instead of `make'.
if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then
am__include=include
am__quote=
_am_result=GNU
fi
# Now try BSD make style include.
if test "$am__include" = "#"; then
echo '.include "confinc"' > confmf
if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then
am__include=.include
am__quote="\""
_am_result=BSD
fi
fi
AC_SUBST([am__include])
AC_SUBST([am__quote])
AC_MSG_RESULT([$_am_result])
rm -f confinc confmf
])
# AM_CONDITIONAL -*- Autoconf -*-
# Copyright 1997, 2000, 2001 Free Software Foundation, Inc.
# 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, 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.
# serial 5
AC_PREREQ(2.52)
# AM_CONDITIONAL(NAME, SHELL-CONDITION)
# -------------------------------------
# Define a conditional.
AC_DEFUN([AM_CONDITIONAL],
[ifelse([$1], [TRUE], [AC_FATAL([$0: invalid condition: $1])],
[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
AC_SUBST([$1_TRUE])
AC_SUBST([$1_FALSE])
if $2; then
$1_TRUE=
$1_FALSE='#'
else
$1_TRUE='#'
$1_FALSE=
fi
AC_CONFIG_COMMANDS_PRE(
[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
AC_MSG_ERROR([conditional "$1" was never defined.
Usually this means the macro was only invoked conditionally.])
fi])])
dnl PKG_CHECK_MODULES(GSTUFF, gtk+-2.0 >= 1.3 glib = 1.3.4, action-if, action-not)
dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
dnl also defines GSTUFF_PKG_ERRORS on error
AC_DEFUN(PKG_CHECK_MODULES, [
succeeded=no
if test -z "$PKG_CONFIG"; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
fi
if test "$PKG_CONFIG" = "no" ; then
echo "*** The pkg-config script could not be found. Make sure it is"
echo "*** in your path, or set the PKG_CONFIG environment variable"
echo "*** to the full path to pkg-config."
echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
else
PKG_CONFIG_MIN_VERSION=0.9.0
if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
AC_MSG_CHECKING(for $2)
if $PKG_CONFIG --exists "$2" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING($1_CFLAGS)
$1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
AC_MSG_RESULT($$1_CFLAGS)
AC_MSG_CHECKING($1_LIBS)
$1_LIBS=`$PKG_CONFIG --libs "$2"`
AC_MSG_RESULT($$1_LIBS)
else
$1_CFLAGS=""
$1_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
$1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
ifelse([$4], ,echo $$1_PKG_ERRORS,)
fi
AC_SUBST($1_CFLAGS)
AC_SUBST($1_LIBS)
else
echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
echo "*** See http://www.freedesktop.org/software/pkgconfig"
fi
fi
if test $succeeded = yes; then
ifelse([$3], , :, [$3])
else
ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4])
fi
])

68
autogen.sh Executable file
View file

@ -0,0 +1,68 @@
#!/bin/sh
# Run this to generate all the initial makefiles, etc.
srcdir=`dirname $0`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
PROJECT=NetworkManager
TEST_TYPE=-d
FILE=src
DIE=0
if $have_libtool ; then : ; else
echo
echo "You must have libtool 1.4 installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/"
DIE=1
fi
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/"
DIE=1
}
if automake-1.7 --version < /dev/null > /dev/null 2>&1 ; then
AUTOMAKE=automake-1.7
ACLOCAL=aclocal-1.7
else
echo
echo "You must have automake 1.7.x installed to compile $PROJECT."
echo "Install the appropriate package for your distribution,"
echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/"
DIE=1
fi
if test "$DIE" -eq 1; then
exit 1
fi
test $TEST_TYPE $FILE || {
echo "You must run this script in the top-level $PROJECT directory"
exit 1
}
if test -z "$AUTOGEN_SUBDIR_MODE"; then
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
fi
$ACLOCAL -I . $ACLOCALFLAGS || exit $?
$AUTOMAKE --add-missing || exit $?
autoconf || exit $?
cd $ORIGDIR || exit $?
if test -z "$AUTOGEN_SUBDIR_MODE"; then
$srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
echo
echo "Now type 'make' to compile $PROJECT."
fi

4802
configure vendored Executable file

File diff suppressed because it is too large Load diff

23
configure.in Normal file
View file

@ -0,0 +1,23 @@
AC_PREREQ(2.52)
AC_INIT(NetworkManager, 0.1)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AC_PROG_CC
AC_CHECK_HEADER(iwlib.h, [],
[AC_MSG_ERROR(iwlib.h not found. Install wireless-tools.)], [])
AC_CHECK_LIB(iw, iw_scan, [ IWLIB=-liw ],
[AC_MSG_ERROR(wireless-tools 27.pre23 not installed or not functional)], [])
AC_SUBST(IWLIB)
PKG_CHECK_MODULES(NM, dbus-glib-1 >= 0.20 hal >= 0.2.91 gthread-2.0)
AC_SUBST(NM_CFLAGS)
AC_SUBST(NM_LIBS)
AC_OUTPUT([
Makefile
test/Makefile
src/Makefile
initscript/Makefile
])

4
initscript/Makefile.am Normal file
View file

@ -0,0 +1,4 @@
EXTRA_DIST = NetworkManager
rcddir = $(sysconfdir)/rc.d/init.d
rcd_DATA = NetworkManager

272
initscript/Makefile.in Normal file
View file

@ -0,0 +1,272 @@
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
IWLIB = @IWLIB@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
NM_CFLAGS = @NM_CFLAGS@
NM_LIBS = @NM_LIBS@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build_alias = @build_alias@
datadir = @datadir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
EXTRA_DIST = NetworkManager
rcddir = $(sysconfdir)/rc.d/init.d
rcd_DATA = NetworkManager
subdir = initscript
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
DIST_SOURCES =
DATA = $(rcd_DATA)
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
all: all-am
.SUFFIXES:
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu initscript/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
uninstall-info-am:
rcdDATA_INSTALL = $(INSTALL_DATA)
install-rcdDATA: $(rcd_DATA)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(rcddir)
@list='$(rcd_DATA)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(rcdDATA_INSTALL) $$d$$p $(DESTDIR)$(rcddir)/$$f"; \
$(rcdDATA_INSTALL) $$d$$p $(DESTDIR)$(rcddir)/$$f; \
done
uninstall-rcdDATA:
@$(NORMAL_UNINSTALL)
@list='$(rcd_DATA)'; for p in $$list; do \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " rm -f $(DESTDIR)$(rcddir)/$$f"; \
rm -f $(DESTDIR)$(rcddir)/$$f; \
done
tags: TAGS
TAGS:
ctags: CTAGS
CTAGS:
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkinstalldirs) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(DATA)
installdirs:
$(mkinstalldirs) $(DESTDIR)$(rcddir)
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic mostlyclean-am
distclean: distclean-am
-rm -f Makefile
distclean-am: clean-am distclean-generic
dvi: dvi-am
dvi-am:
info: info-am
info-am:
install-data-am: install-rcdDATA
install-exec-am:
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-generic
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-info-am uninstall-rcdDATA
.PHONY: all all-am check check-am clean clean-generic distclean \
distclean-generic distdir dvi dvi-am info info-am install \
install-am install-data install-data-am install-exec \
install-exec-am install-info install-info-am install-man \
install-rcdDATA install-strip installcheck installcheck-am \
installdirs maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \
uninstall-am uninstall-info-am uninstall-rcdDATA
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

71
initscript/NetworkManager Executable file
View file

@ -0,0 +1,71 @@
#!/bin/sh
#
# NetworkManager: NetworkManager daemon
#
# chkconfig: 345 98 02
# description: This is a daemon for automatically switching network \
# connections to the best available connection. \
#
# processname: NetworkManager
# pidfile: /var/run/NetworkManager.pid
#
# Sanity checks.
[ -x /usr/bin/NetworkManager ] || exit 0
# Source function library.
. /etc/rc.d/init.d/functions
# so we can rearrange this easily
processname=NetworkManager
servicename=NetworkManager
RETVAL=0
start() {
echo -n $"Starting NetworkManager daemon: "
daemon --check $servicename $processname
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename && echo `/sbin/pidof $processname` > /var/run/NetworkManager.pid
}
stop() {
echo -n $"Stopping NetworkManager daemon: "
killproc $servicename -TERM
RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then
rm -f /var/lock/subsys/$servicename
rm -f /var/run/NetworkManager.pid
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $processname
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$servicename ]; then
stop
start
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
;;
esac
exit $RETVAL

124
inode.c Normal file
View file

@ -0,0 +1,124 @@
/* -*- mode: C; c-file-style: "linux" -*- */
/* MemProf -- memory profiler and leak detector
* Copyright 1999, 2000, 2001, Red Hat, Inc.
* Copyright 2002, Kristian Rietveld
*
* 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.
*/
/*====*/
#include <glib.h>
#include <sys/stat.h>
#include <dirent.h>
#include "memprof.h"
/************************************************************
* Inode finding code - not needed for kernel 2.2 or greater
************************************************************/
GHashTable *inode_table = NULL;
typedef struct {
dev_t device;
ino_t inode;
gchar *name;
} Inode;
static guint
inode_hash (gconstpointer data)
{
return (((Inode *)data)->device + (((Inode *)data)->inode << 11));
}
static gint
inode_compare (gconstpointer a, gconstpointer b)
{
return ((((Inode *)a)->device == ((Inode *)b)->device) &&
(((Inode *)a)->inode == ((Inode *)b)->inode));
}
void
read_inode (const gchar *path)
{
struct stat stbuf;
g_return_if_fail (path != NULL);
if (!inode_table)
inode_table = g_hash_table_new (inode_hash, inode_compare);
if (!stat (path, &stbuf)) {
Inode *inode = g_new (Inode, 1);
inode->device = stbuf.st_dev;
inode->inode = stbuf.st_ino;
if (!g_hash_table_lookup (inode_table, inode)) {
inode->name = g_strdup (path);
g_hash_table_insert (inode_table, inode, inode);
} else
g_free (inode);
}
}
static void
read_inodes ()
{
static const char *directories[] = {
"/lib",
"/usr/lib",
"/usr/X11R6/lib",
"/usr/local/lib",
"/opt/gnome/lib",
NULL
};
const char **dirname;
for (dirname = directories; *dirname; dirname++)
{
DIR *dir = opendir (*dirname);
if (dir) {
struct dirent *ent;
while ((ent = readdir (dir))) {
gchar buf[1024];
snprintf(buf, 1024-1, "%s/%s", *dirname, ent->d_name);
read_inode (buf);
}
closedir (dir);
}
}
}
gchar *
locate_inode (dev_t device, ino_t inode)
{
Inode lookup;
Inode *result;
lookup.device = device;
lookup.inode = inode;
if (!inode_table)
read_inodes ();
result = g_hash_table_lookup (inode_table, &lookup);
if (result)
return result->name;
else
return NULL;
}

31
src/Makefile.am Normal file
View file

@ -0,0 +1,31 @@
EXTRA_DIST = NetworkManager.conf
INCLUDES = \
$(NM_CFLAGS) \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\"
bin_PROGRAMS = NetworkManager
NetworkManager_SOURCES = \
NetworkManagerAP.c \
NetworkManagerAP.h \
NetworkManagerDbus.c \
NetworkManagerDbus.h \
NetworkManagerDevice.c \
NetworkManagerDevice.h \
NetworkManager.c \
NetworkManager.h \
NetworkManagerPolicy.c \
NetworkManagerPolicy.h \
NetworkManagerUtils.c \
NetworkManagerUtils.h \
NetworkManagerWireless.c \
NetworkManagerWireless.h
NetworkManager_LDADD = $(NM_LIBS) $(IWLIB)
dbusservicedir = $(sysconfdir)/dbus-1/system.d
dbusservice_DATA = NetworkManager.conf

446
src/Makefile.in Normal file
View file

@ -0,0 +1,446 @@
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
IWLIB = @IWLIB@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
NM_CFLAGS = @NM_CFLAGS@
NM_LIBS = @NM_LIBS@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build_alias = @build_alias@
datadir = @datadir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
EXTRA_DIST = NetworkManager.conf
INCLUDES = \
$(NM_CFLAGS) \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\"
bin_PROGRAMS = NetworkManager
NetworkManager_SOURCES = \
NetworkManagerAP.c \
NetworkManagerAP.h \
NetworkManagerDbus.c \
NetworkManagerDbus.h \
NetworkManagerDevice.c \
NetworkManagerDevice.h \
NetworkManager.c \
NetworkManager.h \
NetworkManagerPolicy.c \
NetworkManagerPolicy.h \
NetworkManagerUtils.c \
NetworkManagerUtils.h \
NetworkManagerWireless.c \
NetworkManagerWireless.h
NetworkManager_LDADD = $(NM_LIBS) $(IWLIB)
dbusservicedir = $(sysconfdir)/dbus-1/system.d
dbusservice_DATA = NetworkManager.conf
subdir = src
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
bin_PROGRAMS = NetworkManager$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS)
am_NetworkManager_OBJECTS = NetworkManagerAP.$(OBJEXT) \
NetworkManagerDbus.$(OBJEXT) NetworkManagerDevice.$(OBJEXT) \
NetworkManager.$(OBJEXT) NetworkManagerPolicy.$(OBJEXT) \
NetworkManagerUtils.$(OBJEXT) NetworkManagerWireless.$(OBJEXT)
NetworkManager_OBJECTS = $(am_NetworkManager_OBJECTS)
NetworkManager_DEPENDENCIES =
NetworkManager_LDFLAGS =
DEFAULT_INCLUDES = -I. -I$(srcdir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/NetworkManager.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/NetworkManagerAP.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/NetworkManagerDbus.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/NetworkManagerDevice.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/NetworkManagerPolicy.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/NetworkManagerUtils.Po \
@AMDEP_TRUE@ ./$(DEPDIR)/NetworkManagerWireless.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(NetworkManager_SOURCES)
DATA = $(dbusservice_DATA)
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
SOURCES = $(NetworkManager_SOURCES)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .o .obj
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu src/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
install-binPROGRAMS: $(bin_PROGRAMS)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(bindir)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
if test -f $$p \
; then \
f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f"; \
$(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) $$p $(DESTDIR)$(bindir)/$$f || exit 1; \
else :; fi; \
done
uninstall-binPROGRAMS:
@$(NORMAL_UNINSTALL)
@list='$(bin_PROGRAMS)'; for p in $$list; do \
f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
echo " rm -f $(DESTDIR)$(bindir)/$$f"; \
rm -f $(DESTDIR)$(bindir)/$$f; \
done
clean-binPROGRAMS:
-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
NetworkManager$(EXEEXT): $(NetworkManager_OBJECTS) $(NetworkManager_DEPENDENCIES)
@rm -f NetworkManager$(EXEEXT)
$(LINK) $(NetworkManager_LDFLAGS) $(NetworkManager_OBJECTS) $(NetworkManager_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT) core *.core
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManager.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManagerAP.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManagerDbus.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManagerDevice.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManagerPolicy.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManagerUtils.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/NetworkManagerWireless.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`
uninstall-info-am:
dbusserviceDATA_INSTALL = $(INSTALL_DATA)
install-dbusserviceDATA: $(dbusservice_DATA)
@$(NORMAL_INSTALL)
$(mkinstalldirs) $(DESTDIR)$(dbusservicedir)
@list='$(dbusservice_DATA)'; for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " $(dbusserviceDATA_INSTALL) $$d$$p $(DESTDIR)$(dbusservicedir)/$$f"; \
$(dbusserviceDATA_INSTALL) $$d$$p $(DESTDIR)$(dbusservicedir)/$$f; \
done
uninstall-dbusserviceDATA:
@$(NORMAL_UNINSTALL)
@list='$(dbusservice_DATA)'; for p in $$list; do \
f="`echo $$p | sed -e 's|^.*/||'`"; \
echo " rm -f $(DESTDIR)$(dbusservicedir)/$$f"; \
rm -f $(DESTDIR)$(dbusservicedir)/$$f; \
done
ETAGS = etags
ETAGSFLAGS =
CTAGS = ctags
CTAGSFLAGS =
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkinstalldirs) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS) $(DATA)
installdirs:
$(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(dbusservicedir)
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
info: info-am
info-am:
install-data-am: install-dbusserviceDATA
install-exec-am: install-binPROGRAMS
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-binPROGRAMS uninstall-dbusserviceDATA \
uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
clean-generic ctags distclean distclean-compile \
distclean-generic distclean-tags distdir dvi dvi-am info \
info-am install install-am install-binPROGRAMS install-data \
install-data-am install-dbusserviceDATA install-exec \
install-exec-am install-info install-info-am install-man \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
tags uninstall uninstall-am uninstall-binPROGRAMS \
uninstall-dbusserviceDATA uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

688
src/NetworkManager.c Normal file
View file

@ -0,0 +1,688 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <hal/libhal.h>
#include <getopt.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "NetworkManager.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h"
#include "NetworkManagerPolicy.h"
#include "NetworkManagerWireless.h"
#include "NetworkManagerDbus.h"
/*
* Globals
*/
static GMainLoop *loop = NULL;
static NMData *nm_data = NULL;
gboolean debug = TRUE;
static gboolean quit = FALSE;
static void nm_data_free (NMData *data);
/*
* nm_create_device_and_add_to_list
*
* Create a new NLM device and add it to our device list.
*
* Returns: newly allocated device on success
* NULL on failure
*/
NMDevice * nm_create_device_and_add_to_list (NMData *data, const char *udi)
{
NMDevice *dev = NULL;
gboolean success = FALSE;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (udi != NULL, NULL);
if (hal_device_property_exists (data->hal_ctx, udi, "net.interface"))
{
gchar *iface_name = hal_device_get_property_string (data->hal_ctx, udi, "net.interface");
/* Make sure the device is not already in the device list */
dev = nm_get_device_by_iface (data, iface_name);
if (dev)
{
NM_DEBUG_PRINT_1 ("nm_create_device_and_add_to_list() device %s was already in the list\n", iface_name);
hal_free_string (iface_name);
return (NULL);
}
dev = nm_device_new (iface_name);
if (dev)
{
/* Build up the device structure */
nm_device_set_udi (dev, udi);
/* Attempt to acquire mutex for device list addition. If acquire fails,
* just ignore the device addition entirely.
*/
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
NM_DEBUG_PRINT_3( "nm_create_device_and_add_to_list() adding udi='%s', iface='%s', iface_type=%s\n",
nm_device_get_udi (dev), nm_device_get_iface (dev), nm_device_get_iface_type (dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET ? "wireless" : "wired" );
data->dev_list = g_slist_append (data->dev_list, dev);
/* Initialize and bring up all new devices */
if (nm_device_get_iface_type (dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
/* Disable WEP */
nm_device_bring_down (dev);
nm_device_set_wep_key (dev, NULL);
nm_device_set_essid (dev, NULL);
nm_device_bring_up (dev);
}
else
{
if (!nm_device_is_up (dev))
nm_device_bring_up (dev);
}
success = TRUE;
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_create_device_and_add_to_list() could not acquire device list mutex.\n" );
}
else
NM_DEBUG_PRINT( "nm_create_device_and_add_to_list() could not allocate device data.\n" );
hal_free_string (iface_name);
if (!success)
{
/* If we couldn't add the device to our list, free its data. */
nm_device_unref (dev);
dev = NULL;
}
}
else
NM_DEBUG_PRINT_1( "nm_create_device_and_add_to_list(): device %s does not have 'net.interface' property\n", udi );
return (dev);
}
/*
* nm_remove_device_from_list
*
* Searches for a device entry in the NLM device list by udi,
* and if found, removes that element from the list and frees
* its data.
*/
void nm_remove_device_from_list (NMData *data, const char *udi)
{
GSList *element;
g_return_if_fail (data != NULL);
g_return_if_fail (udi != NULL);
/* Attempt to acquire mutex for device list deletion. If acquire fails,
* just ignore the device deletion entirely.
*/
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
element = data->dev_list;
while (element)
{
NMDevice *dev = (NMDevice *)(element->data);
if (dev)
{
if (nm_null_safe_strcmp (nm_device_get_udi (dev), udi) == 0)
{
if ( data->active_device
&& (dev == data->active_device))
{
nm_device_unref (data->active_device);
data->active_device = NULL;
}
/* Remove the device entry from the device list and free its data */
data->dev_list = g_slist_remove_link (data->dev_list, element);
nm_device_unref (element->data);
g_slist_free (element);
break;
}
}
element = g_slist_next (element);
}
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_remove_device_from_list() could not acquire device list mutex.\n" );
}
/*
* nm_hal_mainloop_integration
*
*/
static void nm_hal_mainloop_integration (LibHalContext *ctx, DBusConnection * dbus_connection)
{
dbus_connection_setup_with_g_main (dbus_connection, NULL);
}
/*
* nm_hal_device_added
*
*/
static void nm_hal_device_added (LibHalContext *ctx, const char *udi)
{
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
g_return_if_fail (data != NULL);
NM_DEBUG_PRINT_1( "nm_hal_device_added() called with udi = %s\n", udi );
/* Sometimes the device's properties (like net.interface) are not set up yet,
* so this call will fail, and it will actually be added when hal sets the device's
* capabilities a bit later on.
*/
nm_create_device_and_add_to_list (data, udi);
}
/*
* nm_hal_device_removed
*
*/
static void nm_hal_device_removed (LibHalContext *ctx, const char *udi)
{
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
g_return_if_fail (data != NULL);
NM_DEBUG_PRINT_1( "nm_hal_device_removed() called with udi = %s\n", udi );
nm_remove_device_from_list (data, udi);
}
/*
* nm_hal_device_new_capability
*
*/
static void nm_hal_device_new_capability (LibHalContext *ctx, const char *udi, const char *capability)
{
NMData *data = (NMData *)hal_ctx_get_user_data (ctx);
g_return_if_fail (data != NULL);
NM_DEBUG_PRINT_2( "nm_hal_device_new_capability() called with udi = %s, capability = %s\n", udi, capability );
if (capability && (strcmp (capability, "net.ethernet") == 0))
nm_create_device_and_add_to_list (data, udi);
}
/*
* nm_hal_device_lost_capability
*
*/
static void nm_hal_device_lost_capability (LibHalContext *ctx, const char *udi, const char *capability)
{
NM_DEBUG_PRINT_2( "nm_hal_device_lost_capability() called with udi = %s, capability = %s\n", udi, capability );
}
/*
* nm_hal_device_property_modified
*
*/
static void nm_hal_device_property_modified (LibHalContext *ctx, const char *udi, const char *key, dbus_bool_t is_removed, dbus_bool_t is_added)
{
/*
NM_DEBUG_PRINT_4( "nm_hal_device_property_modified() called with udi = %s, key = %s, is_removed = %d, is_added = %d\n", udi, key, is_removed, is_added );
*/
}
/*
* nm_add_current_devices
*
* Add all devices that hal knows about right now (ie not hotplug devices)
*
*/
static void nm_add_current_devices (NMData *data)
{
char **net_devices;
int num_net_devices;
int i;
g_return_if_fail (data != NULL);
/* Grab a list of network devices */
net_devices = hal_find_device_by_capability (data->hal_ctx, "net.ethernet", &num_net_devices);
for (i = 0; i < num_net_devices; i++)
nm_create_device_and_add_to_list (data, net_devices[i]);
hal_free_string_array (net_devices);
}
/*
* nm_link_state_monitor
*
* Called every 2s to poll cards and determine if they have a link
* or not.
*
*/
gboolean nm_link_state_monitor (gpointer user_data)
{
NMData *data = (NMData *)user_data;
GSList *element;
g_return_val_if_fail (data != NULL, TRUE);
/* Attempt to acquire mutex for device list iteration.
* If the acquire fails, just ignore the device deletion entirely.
*/
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
element = data->dev_list;
while (element)
{
NMDevice *dev = (NMDevice *)(element->data);
if (dev)
{
/* Make sure the device is up first. It doesn't have to have
* an IP address or anything, but most devices cannot do link
* detection when they are down.
*/
if (!nm_device_is_up (dev))
nm_device_bring_up (dev);
nm_device_update_link_active (dev, FALSE);
}
element = g_slist_next (element);
}
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_link_state_monitor() could not acquire device list mutex.\n" );
return (TRUE);
}
/*
* nm_data_allowed_ap_list_free
*
* Frees the allowed access point list
*
*/
void nm_data_allowed_ap_list_free (NMData *data)
{
GSList *element;
g_return_if_fail (data != NULL);
if (!data->allowed_ap_list)
return;
element = data->allowed_ap_list;
while (element)
{
if (element->data)
{
nm_ap_unref (element->data);
element->data = NULL;
}
element = g_slist_next (element);
}
g_slist_free (data->allowed_ap_list);
data->allowed_ap_list = NULL;
}
/*
* libhal callback function structure
*/
static LibHalFunctions hal_functions =
{
nm_hal_mainloop_integration,
nm_hal_device_added,
nm_hal_device_removed,
nm_hal_device_new_capability,
nm_hal_device_lost_capability,
nm_hal_device_property_modified,
NULL
};
/*
* nm_data_new
*
* Create data structure used in callbacks from libhal.
*
*/
static NMData *nm_data_new (void)
{
NMData *data;
data = g_new0 (NMData, 1);
if (!data)
{
NM_DEBUG_PRINT("Could not allocate our NetworkManager data... Not enough memory?\n");
return (NULL);
}
/* Initialize the device list mutex to protect additions/deletions to it. */
data->dev_list_mutex = g_mutex_new ();
if (!data->dev_list_mutex)
{
nm_data_free (data);
NM_DEBUG_PRINT("Could not create device list mutex. Whacky shit going on?\n");
return (NULL);
}
/* Initialize the state modified mutex. */
data->state_modified_mutex = g_mutex_new ();
if (!data->state_modified_mutex)
{
nm_data_free (data);
NM_DEBUG_PRINT("Could not create state_modified mutex. Whacky shit going on?\n");
return (NULL);
}
/* Initialize the allowed access point list mutex */
data->allowed_ap_list_mutex = g_mutex_new ();
if (!data->allowed_ap_list_mutex)
{
nm_data_free (data);
NM_DEBUG_PRINT("Could not create state_modified mutex. Whacky shit going on?\n");
return (NULL);
}
data->state_modified = TRUE;
return (data);
}
/*
* nm_data_dev_list_element_free
*
* Frees each member of the device list before the list is
* disposed of.
*
*/
static void nm_data_dev_list_element_free (void *element, void *user_data)
{
nm_device_unref (element);
}
/*
* nm_data_free
*
* Free data structure used in callbacks.
*
*/
static void nm_data_free (NMData *data)
{
g_return_if_fail (data != NULL);
g_slist_foreach (data->dev_list, nm_data_dev_list_element_free, NULL);
g_slist_free (data->dev_list);
g_mutex_free (data->dev_list_mutex);
nm_device_unref (data->active_device);
nm_data_allowed_ap_list_free (data);
nm_ap_unref (data->desired_ap);
}
/*
* nm_get_global_data
*
* Return the global data structure
*
*/
NMData * nm_get_global_data (void)
{
return (nm_data);
}
/*
* nm_data_set_state_modified
*
* Locked function to protect state modification changes.
*
*/
void nm_data_set_state_modified (NMData *data, gboolean modified)
{
g_return_if_fail (data != NULL);
g_mutex_lock (data->state_modified_mutex);
data->state_modified = modified;
g_mutex_unlock (data->state_modified_mutex);
}
/*
* nm_print_usage
*
* Prints program usage.
*
*/
static void nm_print_usage (void)
{
fprintf (stderr, "\n" "usage : NetworkManager [--daemon=yes|no] [--help]\n");
fprintf (stderr,
"\n"
" --daemon=yes|no Become a daemon\n"
" --help Show this information and exit\n"
"\n"
"NetworkManager monitors all network connections and automatically\n"
"chooses the best connection to use. It also allows the user to\n"
"specify wireless access points which wireless cards in the computer\n"
"should associate with.\n"
"\n");
}
/*
* main
*
*/
int main( int argc, char *argv[] )
{
LibHalContext *ctx = NULL;
guint link_source;
guint policy_source;
guint wireless_scan_source;
gboolean become_daemon = TRUE;
/* Parse options */
while (1)
{
int c;
int option_index = 0;
const char *opt;
static struct option options[] = {
{"daemon", 1, NULL, 0},
{"help", 0, NULL, 0},
{NULL, 0, NULL, 0}
};
c = getopt_long (argc, argv, "", options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
opt = options[option_index].name;
if (strcmp (opt, "help") == 0)
{
nm_print_usage ();
return 0;
}
else if (strcmp (opt, "daemon") == 0)
{
if (strcmp ("yes", optarg) == 0)
become_daemon = TRUE;
else if (strcmp ("no", optarg) == 0)
become_daemon = FALSE;
else
{
nm_print_usage ();
return 1;
}
}
break;
default:
nm_print_usage ();
return 1;
break;
}
}
if (become_daemon)
{
int child_pid;
int dev_null_fd;
if (chdir ("/") < 0)
{
fprintf( stderr, "NetworkManager could not chdir to /. errno=%d", errno);
return 1;
}
child_pid = fork ();
switch (child_pid)
{
case -1:
fprintf( stderr, "NetworkManager could not daemonize. errno = %d\n", errno );
break;
case 0:
/* Child */
break;
default:
exit (0);
break;
}
}
g_type_init ();
if (!g_thread_supported ())
g_thread_init (NULL);
/* Initialize libhal. We get a connection to the hal daemon here. */
if ((ctx = hal_initialize (&hal_functions, FALSE)) == NULL)
{
NM_DEBUG_PRINT("hal_initialize() failed, exiting... Make sure the hal daemon is running?\n");
exit (1);
}
/* Initialize our instance data */
nm_data = nm_data_new ();
if (!nm_data)
{
NM_DEBUG_PRINT("nm_data_new() failed... Not enough memory?\n");
exit (1);
}
nm_data->hal_ctx = ctx;
hal_ctx_set_user_data (nm_data->hal_ctx, nm_data);
/* Grab network devices that are already present and add them to our list */
nm_add_current_devices (nm_data);
/* Initialize our list of allowed access points */
nm_policy_update_allowed_access_points (nm_data);
/* Create our dbus service */
nm_data->dbus_connection = nm_dbus_init ();
if (nm_data->dbus_connection)
{
/* Create a watch function that monitors cards for link status (hal doesn't do
* this for wireless cards yet).
*/
link_source = g_timeout_add (5000, nm_link_state_monitor, nm_data);
/* Another watch function which handles networking state changes and applies
* the correct policy on a change.
*/
policy_source = g_timeout_add (3000, nm_state_modification_monitor, nm_data);
/* Yet another watch function which scans for access points and
* attempts to associate with approved ones in a users' list.
*/
wireless_scan_source = g_timeout_add (10000, nm_wireless_scan_monitor, nm_data);
/* Watch all devices that HAL knows about for state changes */
/* Don't need this now because our polling function takes care of it and
* HAL drops the ball for some cards.
*/
hal_device_property_watch_all (nm_data->hal_ctx);
/* Since we do what dhclient does, and do it better, kill dhclient */
system ("killall dhclient");
/* Run the main loop, all events processed by callbacks from libhal. */
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
/* Kill the watch functions */
g_source_remove (link_source);
g_source_remove (policy_source);
g_source_remove (wireless_scan_source);
}
/* Cleanup */
if (hal_shutdown (nm_data->hal_ctx) != 0)
g_warning ("hal_shutdown() failed\n");
nm_data_free (nm_data);
return 0;
}

12
src/NetworkManager.conf Normal file
View file

@ -0,0 +1,12 @@
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy context="default">
<allow own="org.freedesktop.NetworkManager"/>
<allow send_destination="org.freedesktop.NetworkManager"/>
<allow send_interface="org.freedesktop.NetworkManager"/>
</policy>
</busconfig>

52
src/NetworkManager.h Normal file
View file

@ -0,0 +1,52 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_H
#define NETWORK_MANAGER_H
#include <glib.h>
#include <glib/gthread.h>
#include <hal/libhal.h>
#include "NetworkManagerAP.h"
struct NMData
{
LibHalContext *hal_ctx;
GSList *dev_list;
GMutex *dev_list_mutex;
struct NMDevice *active_device;
gboolean state_modified;
GMutex *state_modified_mutex;
GSList *allowed_ap_list;
GMutex *allowed_ap_list_mutex;
NMAccessPoint *desired_ap;
DBusConnection *dbus_connection;
};
typedef struct NMData NMData;
void nm_data_set_state_modified (NMData *data, gboolean modified);
void nm_data_allowed_ap_list_free (NMData *data);
NMData *nm_get_global_data (void);
#endif

289
src/NetworkManagerAP.c Normal file
View file

@ -0,0 +1,289 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include "NetworkManagerAP.h"
#include "NetworkManagerUtils.h"
extern gboolean debug;
/*
* Encapsulates Access Point information
*/
struct NMAccessPoint
{
guint refcount;
gchar *essid;
gchar *address;
guint8 quality;
double freq;
guint16 rate;
time_t stamp;
/* Things from user prefs */
gchar *wep_key;
guint priority;
};
/*
* nm_ap_new
*
* Create a new, blank user access point info structure
*
*/
NMAccessPoint * nm_ap_new (void)
{
NMAccessPoint *ap;
ap = g_new0 (NMAccessPoint, 1);
if (!ap)
NM_DEBUG_PRINT( "nm_ap_new() could not allocate a new user access point info structure. Not enough memory?" );
ap->priority = NM_AP_PRIORITY_WORST;
ap->refcount = 1;
return (ap);
}
/*
* nm_ap_new_from_ap
*
* Create a new user access point info structure, duplicating an existing one
*
*/
NMAccessPoint * nm_ap_new_from_ap (NMAccessPoint *src_ap)
{
NMAccessPoint *new_ap;
g_return_val_if_fail (src_ap != NULL, NULL);
new_ap = nm_ap_new();
if (!new_ap)
NM_DEBUG_PRINT( "nm_ap_new_from_uap() could not allocate a new user access point info structure. Not enough memory?" );
new_ap->refcount = 1;
if (src_ap->essid && (strlen (src_ap->essid) > 0))
new_ap->essid = g_strdup (src_ap->essid);
if (src_ap->address && (strlen (src_ap->address) > 0))
new_ap->address = g_strdup (src_ap->address);
new_ap->quality = src_ap->quality;
new_ap->freq = src_ap->freq;
new_ap->rate = src_ap->rate;
if (src_ap->wep_key && (strlen (src_ap->wep_key) > 0))
new_ap->wep_key = g_strdup (src_ap->wep_key);
new_ap->priority = src_ap->priority;
return (new_ap);
}
/*
* AP refcounting functions
*/
void nm_ap_ref (NMAccessPoint *ap)
{
g_return_if_fail (ap != NULL);
ap->refcount++;
}
void nm_ap_unref (NMAccessPoint *ap)
{
g_return_if_fail (ap != NULL);
ap->refcount--;
if (ap->refcount == 0)
{
g_free (ap->essid);
g_free (ap->address);
g_free (ap->wep_key);
ap->essid = NULL;
ap->wep_key = NULL;
g_free (ap);
}
}
/*
* Get/set functions for priority
*
*/
guint nm_ap_get_priority (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->priority);
}
void nm_ap_set_priority (NMAccessPoint *ap, guint priority)
{
g_return_if_fail (ap != NULL);
ap->priority = priority;
}
/*
* Get/set functions for essid
*
*/
gchar * nm_ap_get_essid (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
return (ap->essid);
}
void nm_ap_set_essid (NMAccessPoint *ap, gchar * essid)
{
g_return_if_fail (ap != NULL);
if (ap->essid)
g_free (ap->essid);
ap->essid = g_strdup (essid);
}
/*
* Get/set functions for WEP key
*
*/
gchar * nm_ap_get_wep_key (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
return (ap->wep_key);
}
void nm_ap_set_wep_key (NMAccessPoint *ap, gchar * wep_key)
{
g_return_if_fail (ap != NULL);
if (ap->wep_key)
g_free (ap->wep_key);
ap->wep_key = g_strdup (wep_key);
}
/*
* Get/set functions for address
*
*/
gchar * nm_ap_get_address (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, NULL);
return (ap->address);
}
void nm_ap_set_address (NMAccessPoint *ap, gchar * address)
{
g_return_if_fail (ap != NULL);
if (ap->address)
g_free (ap->address);
ap->address = g_strdup (address);
}
/*
* Get/set functions for quality
*
*/
guint8 nm_ap_get_quality (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->quality);
}
void nm_ap_set_quality (NMAccessPoint *ap, guint8 quality)
{
g_return_if_fail (ap != NULL);
ap->quality = quality;
}
/*
* Get/set functions for frequency
*
*/
double nm_ap_get_freq (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->freq);
}
void nm_ap_set_freq (NMAccessPoint *ap, double freq)
{
g_return_if_fail (ap != NULL);
ap->freq = freq;
}
/*
* Get/set functions for rate
*
*/
guint16 nm_ap_get_rate (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->rate);
}
void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate)
{
g_return_if_fail (ap != NULL);
ap->rate = rate;
}
/*
* Get/set functions for timestamp
*
*/
time_t nm_ap_get_stamp (NMAccessPoint *ap)
{
g_return_val_if_fail (ap != NULL, 0);
return (ap->stamp);
}
void nm_ap_set_stamp (NMAccessPoint *ap, time_t stamp)
{
g_return_if_fail (ap != NULL);
ap->stamp = stamp;
}

63
src/NetworkManagerAP.h Normal file
View file

@ -0,0 +1,63 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_AP_H
#define NETWORK_MANAGER_AP_H
#include <glib.h>
#include <time.h>
typedef struct NMAccessPoint NMAccessPoint;
#define NM_AP_PRIORITY_WORST 1000
NMAccessPoint *nm_ap_new (void);
NMAccessPoint *nm_ap_new_from_ap (NMAccessPoint *ap);
void nm_ap_unref (NMAccessPoint *ap);
void nm_ap_ref (NMAccessPoint *ap);
guint nm_ap_get_priority (NMAccessPoint *ap);
void nm_ap_set_priority (NMAccessPoint *ap, guint priority);
gchar * nm_ap_get_essid (NMAccessPoint *ap);
void nm_ap_set_essid (NMAccessPoint *ap, gchar * essid);
gchar * nm_ap_get_wep_key (NMAccessPoint *ap);
void nm_ap_set_wep_key (NMAccessPoint *ap, gchar * wep_key);
gchar * nm_ap_get_address (NMAccessPoint *ap);
void nm_ap_set_address (NMAccessPoint *ap, gchar * address);
guint8 nm_ap_get_quality (NMAccessPoint *ap);
void nm_ap_set_quality (NMAccessPoint *ap, guint8 quality);
double nm_ap_get_freq (NMAccessPoint *ap);
void nm_ap_set_freq (NMAccessPoint *ap, double freq);
guint16 nm_ap_get_rate (NMAccessPoint *ap);
void nm_ap_set_rate (NMAccessPoint *ap, guint16 rate);
time_t nm_ap_get_stamp (NMAccessPoint *ap);
void nm_ap_set_stamp (NMAccessPoint *ap, time_t stamp);
#endif

690
src/NetworkManagerDbus.c Normal file
View file

@ -0,0 +1,690 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <stdarg.h>
extern gboolean debug;
#include "NetworkManager.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerDevice.h"
#include "NetworkManagerDbus.h"
#include "NetworkManagerAP.h"
/*
* nm_dbus_create_error_message
*
* Make a DBus error message
*
*/
static DBusMessage *nm_dbus_create_error_message (DBusMessage *message, const char *exception_namespace,
const char *exception, const char *format, ...)
{
DBusMessage *reply_message;
va_list args;
char error_text[512];
va_start (args, format);
vsnprintf (error_text, 512, format, args);
va_end (args);
char *exception_text = g_strdup_printf ("%s.%s", exception_namespace, exception);
reply_message = dbus_message_new_error (message, exception_text, error_text);
g_free (exception_text);
return (reply_message);
}
/*
* nm_dbus_get_object_path_from_device
*
* Copies the object path for a device object into a provided buffer
*
*/
void nm_dbus_get_object_path_from_device (NMDevice *dev, unsigned char *buf, unsigned int buf_len, gboolean lock_dev_list)
{
NMData *data = nm_get_global_data ();
g_return_if_fail (buf != NULL);
g_return_if_fail (buf_len > 0);
memset (buf, 0, buf_len);
g_return_if_fail (dev != NULL);
g_return_if_fail (data != NULL);
/* Iterate over device list */
if (!lock_dev_list || nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
NMDevice *list_dev = NULL;
GSList *element = data->dev_list;
int i = 0;
while (element)
{
list_dev = (NMDevice *)(element->data);
if (dev == list_dev)
{
snprintf (buf, buf_len-1, "%s/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, i);
break;
}
i++;
element = g_slist_next (element);
}
if (lock_dev_list)
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
}
/*
* nm_dbus_get_device_from_object_path
*
* Returns the device associated with a dbus object path
*
*/
NMDevice *nm_dbus_get_device_from_object_path (const char *path, int *dev_index)
{
NMData *data = nm_get_global_data ();
NMDevice *dev = NULL;
*dev_index = -1;
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (data != NULL, NULL);
/* FIXME
* This function could be much more efficient, for example we could
* actually _parse_ the object path, but that's a lot more code and
* stupid stuff. The approach below is slower, less efficient, but
* less code and less error-prone.
*/
/* Iterate over device list */
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
GSList *element = data->dev_list;
char compare_path[100];
int i = 0;
while (element)
{
snprintf (compare_path, 100, "%s/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, i);
/* Compare against our constructed path, but ignore any trailing elements */
dev = (NMDevice *)(element->data);
if (dev && (strncmp (path, compare_path, strlen (compare_path)) == 0))
{
*dev_index = i;
break;
}
else
dev = NULL;
i++;
element = g_slist_next (element);
}
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
return (dev);
}
/*
* nm_dbus_get_network_by_object_path
*
* Returns the network (ap) associated with a dbus object path
*
*/
NMAccessPoint *nm_dbus_get_network_by_object_path (const char *path, NMDevice *dev, int dev_index, int *ap_index)
{
NMData *data;
NMAccessPoint *ap = NULL;
int i = 0;
char compare_path[100];
*ap_index = -1;
g_return_val_if_fail (path != NULL, NULL);
while (ap = nm_device_ap_list_get_ap (dev, i))
{
snprintf (compare_path, 100, "%s/%d/Networks/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, dev_index, i);
if (strncmp (path, compare_path, strlen (compare_path)) == 0)
{
*ap_index = i;
break;
}
else
ap = NULL;
i++;
}
return (ap);
}
/*
* nm_dbus_nm_get_active_device
*
* Returns the object path of the currently active device
*
*/
static DBusMessage *nm_dbus_nm_get_active_device (DBusConnection *connection, DBusMessage *message)
{
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
NMData *data;
data = nm_get_global_data ();
if (!data)
{
/* If we can't get our global data, something is really wrong... */
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NoGlobalData",
"NetworkManager couldn't get its global data.");
goto end;
}
if (!data->active_device)
{
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_string (&iter, "");
goto end;
}
/* Iterate over device list and grab index of "active device" */
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
GSList *element = data->dev_list;
int i = 0;
while (element)
{
NMDevice *dev = (NMDevice *)(element->data);
if (dev && (dev == data->active_device))
{
char *object_path = g_strdup_printf ("%s/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, i);
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_string (&iter, object_path);
g_free (object_path);
break;
}
i++;
element = g_slist_next (element);
}
if (!reply_message)
{
/* If the active device wasn't in the list, its been removed. */
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_string (&iter, "");
}
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "Retry",
"NetworkManager could not lock device list, try again.");
}
end:
return (reply_message);
}
/*
* nm_dbus_nm_get_devices
*
* Returns a string array of object paths corresponding to the
* devices in the device list.
*
*/
static DBusMessage *nm_dbus_nm_get_devices (DBusConnection *connection, DBusMessage *message)
{
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
DBusMessageIter iter_array;
NMData *data;
data = nm_get_global_data ();
if (!data)
{
/* If we can't get our global data, something is really wrong... */
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NoGlobalData",
"NetworkManager couldn't get its global data.");
goto end;
}
/* Check for no devices */
if (!data->dev_list)
{
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
dbus_message_iter_append_string (&iter_array, "");
goto end;
}
/* Iterate over device list and grab index of "active device" */
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
GSList *element = data->dev_list;
int i = 0;
gboolean appended = FALSE;
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
while (element)
{
NMDevice *dev = (NMDevice *)(element->data);
if (dev)
{
char *object_path = g_strdup_printf ("%s/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, i);
dbus_message_iter_append_string (&iter_array, object_path);
g_free (object_path);
appended = TRUE;
}
i++;
element = g_slist_next (element);
}
/* If by some chance there is a device list, but it has no devices in it
* (something which should never happen), append an empty string like
* there are no devices in the list.
*/
if (!appended)
dbus_message_iter_append_string (&iter_array, "");
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "Retry",
"NetworkManager could not lock device list, try again.");
}
end:
return (reply_message);
}
/*-------------------------------------------------------------*/
/* Handler code */
/*-------------------------------------------------------------*/
/*
* nm_dbus_signal_device_no_longer_active
*
* Notifies the bus that a particular device is no longer active.
*
*/
void nm_dbus_signal_device_no_longer_active (DBusConnection *connection, NMDevice *dev)
{
DBusMessage *message;
unsigned char *object_path = g_new0 (unsigned char, 100);
g_return_if_fail (object_path != NULL);
message = dbus_message_new_signal (NM_DBUS_NM_OBJECT_PATH_PREFIX, NM_DBUS_NM_NAMESPACE, "DeviceNoLongerActive");
if (!message)
{
NM_DEBUG_PRINT ("nm_dbus_signal_device_no_longer_active(): Not enough memory for new dbus message!\n");
}
nm_dbus_get_object_path_from_device (dev, object_path, 100, FALSE);
dbus_message_append_args (message, DBUS_TYPE_STRING, object_path, DBUS_TYPE_INVALID);
g_free (object_path);
if (!dbus_connection_send (connection, message, NULL))
NM_DEBUG_PRINT ("nm_dbus_signal_device_no_longer_active(): Could not raise the DeviceNoLongerActive signal!\n");
dbus_message_unref (message);
}
/*
* nm_dbus_signal_device_now_active
*
* Notifies the bus that a particular device is newly active.
*
*/
void nm_dbus_signal_device_now_active (DBusConnection *connection, NMDevice *dev)
{
DBusMessage *message;
unsigned char *object_path = g_new0 (unsigned char, 100);
message = dbus_message_new_signal (NM_DBUS_NM_OBJECT_PATH_PREFIX, NM_DBUS_NM_NAMESPACE, "DeviceNowActive");
if (!message)
{
NM_DEBUG_PRINT ("nm_dbus_signal_device_now_active(): Not enough memory for new dbus message!\n");
}
nm_dbus_get_object_path_from_device (dev, object_path, 100, FALSE);
dbus_message_append_args (message, DBUS_TYPE_STRING, object_path, DBUS_TYPE_INVALID);
g_free (object_path);
if (!dbus_connection_send (connection, message, NULL))
NM_DEBUG_PRINT ("nm_dbus_signal_device_now_active(): Could not raise the DeviceNowActive signal!\n");
dbus_message_unref (message);
}
/*
* nm_dbus_devices_handle_networks_request
*
* Converts a property request on a _network_ into a dbus message.
*
*/
static DBusMessage *nm_dbus_devices_handle_networks_request (DBusConnection *connection, DBusMessage *message,
const char *path, const char *request, NMDevice *dev, int dev_index)
{
NMAccessPoint *ap;
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
int ap_index;
ap = nm_dbus_get_network_by_object_path (path, dev, dev_index, &ap_index);
if (!ap || (ap_index == -1))
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "NetworkNotFound",
"The requested network does not exist for this device.");
return (reply_message);
}
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
if (strcmp ("getName", request) == 0)
dbus_message_iter_append_string (&iter, nm_ap_get_essid (ap));
else if (strcmp ("getAddress", request) == 0)
dbus_message_iter_append_string (&iter, nm_ap_get_address (ap));
else if (strcmp ("getQuality", request) == 0)
dbus_message_iter_append_int32 (&iter, nm_ap_get_quality (ap));
else if (strcmp ("getFrequency", request) == 0)
dbus_message_iter_append_double (&iter, nm_ap_get_freq (ap));
else if (strcmp ("getRate", request) == 0)
dbus_message_iter_append_int32 (&iter, nm_ap_get_rate (ap));
else if (strcmp ("getStamp", request) == 0)
dbus_message_iter_append_int32 (&iter, nm_ap_get_stamp (ap));
else
{
/* Must destroy the allocated message */
dbus_message_unref (reply_message);
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "UnknownMethod",
"NetworkManager knows nothing about the method %s for object %s", request, path);
}
return (reply_message);
}
/*
* nm_dbus_devices_handle_request
*
* Converts a property request into a dbus message.
*
*/
static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection, DBusMessage *message, const char *path, const char *request)
{
NMDevice *dev;
DBusMessage *reply_message = NULL;
DBusMessageIter iter;
int dev_index;
char *object_path;
dev = nm_dbus_get_device_from_object_path (path, &dev_index);
if (!dev || (dev_index == -1))
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "DeviceNotFound",
"The requested network device does not exist.");
return (reply_message);
}
/* Test whether or not the _networks_ of a device were queried instead of the device itself */
object_path = g_strdup_printf ("%s/%d/Networks/", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, dev_index);
if (strncmp (path, object_path, strlen (object_path)) == 0)
{
free (object_path);
reply_message = nm_dbus_devices_handle_networks_request (connection, message, path, request, dev, dev_index);
return (reply_message);
}
free (object_path);
reply_message = dbus_message_new_method_return (message);
dbus_message_iter_init (reply_message, &iter);
if (strcmp ("getName", request) == 0)
dbus_message_iter_append_string (&iter, nm_device_get_iface (dev));
else if (strcmp ("getType", request) == 0)
dbus_message_iter_append_int32 (&iter, nm_device_get_iface_type (dev));
else if (strcmp ("getActiveNetwork", request) == 0)
{
NMAccessPoint *ap = NULL;
int i = 0;
while (ap = nm_device_ap_list_get_ap (dev, i))
{
if (nm_null_safe_strcmp (nm_ap_get_essid (ap), nm_device_get_essid (dev)) == 0)
{
object_path = g_strdup_printf ("%s/%d/Networks/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, dev_index, i);
dbus_message_iter_append_string (&iter, object_path);
g_free (object_path);
break;
}
i++;
ap = NULL;
}
/* If we didn't find the devices current network among the known networks, just append a blank item */
if (!ap)
dbus_message_iter_append_string (&iter, "");
}
else if (strcmp ("getNetworks", request) == 0)
{
DBusMessageIter iter_array;
NMAccessPoint *ap = NULL;
int i = 0;
dbus_message_iter_append_array (&iter, &iter_array, DBUS_TYPE_STRING);
while (ap = nm_device_ap_list_get_ap (dev, i))
{
object_path = g_strdup_printf ("%s/%d/Networks/%d", NM_DBUS_DEVICES_OBJECT_PATH_PREFIX, dev_index, i);
dbus_message_iter_append_string (&iter_array, object_path);
g_free (object_path);
i++;
}
}
else
{
/* Must destroy the allocated message */
dbus_message_unref (reply_message);
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "UnknownMethod",
"NetworkManager knows nothing about the method %s for object %s", request, path);
}
return (reply_message);
}
/*
* nm_dbus_nm_message_handler
*
* Dispatch messages against our NetworkManager object
*
*/
static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{
const char *method;
const char *path;
DBusMessage *reply_message = NULL;
method = dbus_message_get_member (message);
path = dbus_message_get_path (message);
NM_DEBUG_PRINT_2 ("nm_dbus_devices_message_handler() got method %s for path %s\n", method, path);
if (strcmp ("getActiveDevice", method) == 0)
{
reply_message = nm_dbus_nm_get_active_device (connection, message);
}
else if (strcmp ("getDevices", method) == 0)
{
reply_message = nm_dbus_nm_get_devices (connection, message);
}
else
{
reply_message = nm_dbus_create_error_message (message, NM_DBUS_NM_NAMESPACE, "UnknownMethod",
"NetworkManager knows nothing about the method %s for object %s", method, path);
}
dbus_connection_send (connection, reply_message, NULL);
return DBUS_HANDLER_RESULT_HANDLED;
}
/*
* nm_dbus_nm_unregister_handler
*
* Nothing happens here.
*
*/
void nm_dbus_nm_unregister_handler (DBusConnection *connection, void *user_data)
{
/* do nothing */
}
/*
* nm_dbus_devices_message_handler
*
* Dispatch messages against individual network devices
*
*/
static DBusHandlerResult nm_dbus_devices_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{
const char *method;
const char *path;
DBusMessage *reply_message = NULL;
method = dbus_message_get_member (message);
path = dbus_message_get_path (message);
/* NM_DEBUG_PRINT_2 ("nm_dbus_nm_message_handler() got method %s for path %s\n", method, path); */
reply_message = nm_dbus_devices_handle_request (connection, message, path, method);
dbus_connection_send (connection, reply_message, NULL);
return DBUS_HANDLER_RESULT_HANDLED;
}
/*
* nm_dbus_devices_unregister_handler
*
* Nothing happens here.
*
*/
void nm_dbus_devices_unregister_handler (DBusConnection *connection, void *user_data)
{
/* do nothing */
}
/*
* nm_dbus_init
*
* Connect to the system messagebus and register ourselves as a service.
*
*/
DBusConnection *nm_dbus_init (void)
{
DBusError dbus_error;
dbus_bool_t success;
DBusConnection *dbus_connection;
DBusObjectPathVTable nm_vtable = { &nm_dbus_nm_unregister_handler, &nm_dbus_nm_message_handler, NULL, NULL, NULL, NULL };
const char *nm_path[] = { "org", "freedesktop", "NetworkManager", NULL };
DBusObjectPathVTable devices_vtable = { &nm_dbus_devices_unregister_handler, &nm_dbus_devices_message_handler, NULL, NULL, NULL, NULL };
const char *devices_path[] = { "org", "freedesktop", "NetworkManager", "Devices", NULL };
dbus_connection_set_change_sigpipe (TRUE);
dbus_error_init (&dbus_error);
dbus_connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error);
if (dbus_connection == NULL)
{
NM_DEBUG_PRINT ("nm_dbus_init() could not get the system bus. Make sure the message bus daemon is running?\n");
return (NULL);
}
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
dbus_connection_setup_with_g_main (dbus_connection, NULL);
dbus_bus_acquire_service (dbus_connection, NM_DBUS_NM_NAMESPACE, 0, &dbus_error);
if (dbus_error_is_set (&dbus_error))
{
NM_DEBUG_PRINT_1 ("nm_dbus_init() could not acquire its service. dbus_bus_acquire_service() says: '%s'\n", dbus_error.message);
return (NULL);
}
success = dbus_connection_register_object_path (dbus_connection, nm_path, &nm_vtable, NULL);
if (!success)
{
NM_DEBUG_PRINT ("nm_dbus_init() could not register a handler for NetworkManager. Not enough memory?\n");
return (NULL);
}
success = dbus_connection_register_fallback (dbus_connection, devices_path, &devices_vtable, NULL);
if (!success)
{
NM_DEBUG_PRINT ("nm_dbus_init() could not register a handler for NetworkManager devices. Not enough memory?\n");
return (NULL);
}
return (dbus_connection);
}

41
src/NetworkManagerDbus.h Normal file
View file

@ -0,0 +1,41 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_DBUS_H
#define NETWORK_MANAGER_DBUS_H
#include <glib.h>
#include <dbus/dbus-glib.h>
#define NM_DBUS_NM_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManager"
#define NM_DBUS_NM_NAMESPACE "org.freedesktop.NetworkManager"
#define NM_DBUS_DEVICES_OBJECT_PATH_PREFIX "/org/freedesktop/NetworkManager/Devices"
#define NM_DBUS_DEVICES_NAMESPACE "org.freedesktop.NetworkManager.Devices"
DBusConnection * nm_dbus_init (void);
void nm_dbus_signal_device_no_longer_active (DBusConnection *connection, NMDevice *dev);
void nm_dbus_signal_device_now_active (DBusConnection *connection, NMDevice *dev);
#endif

837
src/NetworkManagerDevice.c Normal file
View file

@ -0,0 +1,837 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <errno.h>
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <hal/libhal.h>
#include <iwlib.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include "NetworkManager.h"
#include "NetworkManagerDevice.h"
#include "NetworkManagerUtils.h"
extern gboolean debug;
static gboolean mii_get_link (NMDevice *dev);
static void nm_device_link_detection_init (NMDevice *dev);
/*
* nm_device_is_wireless
*
* Test whether a given device is a wireless one or not.
*
*/
static gboolean nm_device_is_wireless (NMDevice *dev)
{
int iwlib_socket;
int error;
iwstats stats;
g_return_val_if_fail (dev != NULL, FALSE);
iwlib_socket = iw_sockets_open ();
error = iw_get_stats (iwlib_socket, nm_device_get_iface (dev), &stats, NULL, FALSE);
close (iwlib_socket);
return (error == 0);
}
/*
* nm_device_supports_wireless_scan
*
* Test whether a given device is a wireless one or not.
*
*/
static gboolean nm_device_supports_wireless_scan (NMDevice *dev)
{
int iwlib_socket;
int error;
iwstats stats;
gboolean can_scan = TRUE;
wireless_scan_head scan_data;
g_return_val_if_fail (dev != NULL, FALSE);
iwlib_socket = iw_sockets_open ();
error = iw_scan (iwlib_socket, nm_device_get_iface (dev), WIRELESS_EXT, &scan_data);
nm_dispose_scan_results (scan_data.result);
if ((error == -1) && (errno == EOPNOTSUPP))
can_scan = FALSE;
close (iwlib_socket);
return (can_scan);
}
/*
* nm_get_device_by_udi
*
* Search through the device list for a device with a given UDI.
*
* NOTE: the caller MUST hold the device list mutex already to make
* this routine thread-safe.
*
*/
NMDevice *nm_get_device_by_udi (NMData *data, const char *udi)
{
NMDevice *dev = NULL;
GSList *element;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (udi != NULL, NULL);
element = data->dev_list;
while (element)
{
dev = (NMDevice *)(element->data);
if (dev)
{
if (nm_null_safe_strcmp (nm_device_get_udi (dev), udi) == 0)
break;
}
element = g_slist_next (element);
}
return (dev);
}
/*
* nm_get_device_by_iface
*
* Search through the device list for a device with a given iface.
*
* NOTE: the caller MUST hold the device list mutex already to make
* this routine thread-safe.
*
*/
NMDevice *nm_get_device_by_iface (NMData *data, const char *iface)
{
NMDevice *iter_dev = NULL;
NMDevice *found_dev = NULL;
GSList *element;
g_return_val_if_fail (data != NULL, NULL);
g_return_val_if_fail (iface != NULL, NULL);
element = data->dev_list;
while (element)
{
iter_dev = (NMDevice *)(element->data);
if (iter_dev)
{
if (nm_null_safe_strcmp (nm_device_get_iface (iter_dev), iface) == 0)
{
found_dev = iter_dev;
break;
}
}
element = g_slist_next (element);
}
return (found_dev);
}
/*****************************************************************************/
/* NMDevice object routines */
/*****************************************************************************/
typedef struct NMDeviceWirelessOptions
{
gchar *cur_essid;
gboolean supports_wireless_scan;
GMutex *ap_list_mutex;
GSList *ap_list;
} NMDeviceWirelessOptions;
typedef struct NMDeviceWiredOptions
{
int foo;
} NMDeviceWiredOptions;
typedef union NMDeviceOptions
{
NMDeviceWirelessOptions wireless;
NMDeviceWiredOptions wired;
} NMDeviceOptions;
/*
* NetworkManager device structure
*/
struct NMDevice
{
guint refcount;
gchar *udi;
gchar *iface;
NMIfaceType iface_type;
gboolean link_active;
NMDeviceOptions dev_options;
};
/*
* nm_device_new
*
* Creates and initializes the structure representation of an NLM device.
*
*/
NMDevice *nm_device_new (const char *iface)
{
NMDevice *dev;
g_return_val_if_fail (iface != NULL, NULL);
dev = g_new0 (NMDevice, 1);
if (!dev)
{
NM_DEBUG_PRINT("nm_device_new() could not allocate a new device... Not enough memory?\n");
return (NULL);
}
dev->refcount = 1;
dev->iface = g_strdup (iface);
dev->iface_type = nm_device_is_wireless (dev) ?
NM_IFACE_TYPE_WIRELESS_ETHERNET : NM_IFACE_TYPE_WIRED_ETHERNET;
if (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
dev->dev_options.wireless.supports_wireless_scan = nm_device_supports_wireless_scan (dev);
dev->dev_options.wireless.ap_list_mutex = g_mutex_new();
if (!dev->dev_options.wireless.ap_list_mutex)
{
g_free (dev->iface);
return (NULL);
}
}
/* Have to bring the device up before checking link status. */
if (!nm_device_is_up (dev))
nm_device_bring_up (dev);
nm_device_update_link_active (dev, TRUE);
return (dev);
}
/*
* Refcounting functions
*/
void nm_device_ref (NMDevice *dev)
{
g_return_if_fail (dev != NULL);
dev->refcount++;
}
void nm_device_unref (NMDevice *dev)
{
g_return_if_fail (dev != NULL);
dev->refcount--;
if (dev->refcount == 0)
{
nm_device_ap_list_clear (dev);
dev->dev_options.wireless.ap_list = NULL;
g_free (dev->udi);
g_free (dev->iface);
if (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
g_free (dev->dev_options.wireless.cur_essid);
g_mutex_free (dev->dev_options.wireless.ap_list_mutex);
}
dev->udi = NULL;
dev->iface = NULL;
}
}
/*
* Get/set functions for UDI
*/
char * nm_device_get_udi (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, NULL);
return (dev->udi);
}
void nm_device_set_udi (NMDevice *dev, const char *udi)
{
g_return_if_fail (dev != NULL);
g_return_if_fail (udi != NULL);
if (dev->udi)
g_free (dev->udi);
dev->udi = g_strdup (udi);
}
/*
* Get/set functions for iface
*/
char * nm_device_get_iface (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, NULL);
return (dev->iface);
}
/*
* Get/set functions for iface_type
*/
guint nm_device_get_iface_type (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, NM_IFACE_TYPE_DONT_KNOW);
return (dev->iface_type);
}
/*
* Get/set functions for link_active
*/
gboolean nm_device_get_link_active (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
return (dev->link_active);
}
void nm_device_set_link_active (NMDevice *dev, const gboolean link_active)
{
g_return_if_fail (dev != NULL);
dev->link_active = link_active;
}
/*
* Get function for supports_wireless_scan
*/
gboolean nm_device_get_supports_wireless_scan (NMDevice *dev)
{
g_return_val_if_fail (dev != NULL, FALSE);
return (dev->dev_options.wireless.supports_wireless_scan);
}
/*
* nm_device_update_link_active
*
* Updates the link state for a particular device.
*
*/
gboolean nm_device_update_link_active (NMDevice *dev, gboolean check_mii)
{
gboolean link_active = FALSE;
g_return_val_if_fail (dev != NULL, FALSE);
/* FIXME
* For wireless cards, the best indicator of a "link" at this time
* seems to be whether the card has a valid access point MAC address.
* Is there a better way?
*/
switch (nm_device_get_iface_type (dev))
{
case NM_IFACE_TYPE_WIRELESS_ETHERNET:
{
struct iwreq wrq;
int iwlib_socket;
iwlib_socket = iw_sockets_open ();
if (iw_get_ext (iwlib_socket, nm_device_get_iface (dev), SIOCGIWAP, &wrq) >= 0)
{
struct ether_addr invalid_addr1;
struct ether_addr invalid_addr2;
struct ether_addr invalid_addr3;
struct ether_addr ap_addr;
/* Compare the AP address the card has with invalid ethernet MAC addresses.
*/
memcpy (&ap_addr, &(wrq.u.ap_addr.sa_data), sizeof (struct ether_addr));
memset (&invalid_addr1, 0xFF, sizeof(struct ether_addr));
memset (&invalid_addr2, 0x00, sizeof(struct ether_addr));
memset (&invalid_addr2, 0x44, sizeof(struct ether_addr));
if ( (memcmp(&ap_addr, &invalid_addr1, sizeof(struct ether_addr)) != 0)
&& (memcmp(&ap_addr, &invalid_addr2, sizeof(struct ether_addr)) != 0)
&& (memcmp(&ap_addr, &invalid_addr3, sizeof(struct ether_addr)) != 0))
link_active = TRUE;
}
close (iwlib_socket);
break;
}
case NM_IFACE_TYPE_WIRED_ETHERNET:
{
if (check_mii)
link_active = mii_get_link (dev);
else
if (hal_device_property_exists (nm_get_global_data()->hal_ctx, nm_device_get_udi (dev), "net.ethernet.link"))
link_active = hal_device_get_property_bool (nm_get_global_data()->hal_ctx, nm_device_get_udi (dev), "net.ethernet.link");
break;
}
default:
link_active = nm_device_get_link_active (dev); /* Can't get link info for this device, so don't change link status */
break;
}
/* Update device link status and global state variable if the status changed */
if (link_active != nm_device_get_link_active (dev))
{
nm_device_set_link_active (dev, link_active);
nm_data_set_state_modified (nm_get_global_data(), TRUE);
}
return (link_active);
}
/*
* nm_device_get_essid
*
* If a device is wireless, return the essid that it is attempting
* to use.
*
* Returns: allocated string containing essid. Must be freed by caller.
*
*/
char * nm_device_get_essid (NMDevice *dev)
{
int iwlib_socket;
int err;
struct iwreq wreq;
char essid[IW_ESSID_MAX_SIZE + 1];
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET, NULL);
iwlib_socket = iw_sockets_open ();
if (iwlib_socket >= 0)
{
wreq.u.essid.pointer = (caddr_t) essid;
wreq.u.essid.length = IW_ESSID_MAX_SIZE + 1;
wreq.u.essid.flags = 0;
err = iw_get_ext (iwlib_socket, nm_device_get_iface (dev), SIOCGIWESSID, &wreq);
if (err >= 0)
{
if (dev->dev_options.wireless.cur_essid)
g_free (dev->dev_options.wireless.cur_essid);
dev->dev_options.wireless.cur_essid = g_strdup (essid);
}
else
NM_DEBUG_PRINT_2 ("nm_device_get_essid(): error setting ESSID for device %s. errno = %d\n", nm_device_get_iface (dev), errno);
close (iwlib_socket);
}
return (dev->dev_options.wireless.cur_essid);
}
/*
* nm_device_set_essid
*
* If a device is wireless, set the essid that it should use.
*/
void nm_device_set_essid (NMDevice *dev, const char *essid)
{
int iwlib_socket;
int err;
struct iwreq wreq;
unsigned char safe_essid[IW_ESSID_MAX_SIZE + 1] = "\0";
g_return_if_fail (dev != NULL);
g_return_if_fail (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET);
/* Make sure the essid we get passed is a valid size */
if (!essid)
safe_essid[0] = '\0';
else
{
strncpy (safe_essid, essid, IW_ESSID_MAX_SIZE);
safe_essid[IW_ESSID_MAX_SIZE] = '\0';
}
iwlib_socket = iw_sockets_open ();
if (iwlib_socket >= 0)
{
wreq.u.essid.pointer = (caddr_t) safe_essid;
wreq.u.essid.length = strlen (safe_essid) + 1;
wreq.u.essid.flags = 1; /* Enable essid on card */
err = iw_set_ext (iwlib_socket, nm_device_get_iface (dev), SIOCSIWESSID, &wreq);
if (err == -1)
NM_DEBUG_PRINT_2 ("nm_device_set_essid(): error setting ESSID for device %s. errno = %d\n", nm_device_get_iface (dev), errno);
close (iwlib_socket);
}
}
/*
* nm_device_set_wep_key
*
* If a device is wireless, set the WEP key that it should use.
*
* wep_key: WEP key to use, or NULL or "" to disable WEP
*/
void nm_device_set_wep_key (NMDevice *dev, const char *wep_key)
{
int iwlib_socket;
int err;
struct iwreq wreq;
int keylen;
unsigned char safe_key[IW_ENCODING_TOKEN_MAX];
gboolean set_key = FALSE;
char *it = NULL;
g_return_if_fail (dev != NULL);
g_return_if_fail (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET);
/* Make sure the essid we get passed is a valid size */
if (!wep_key)
safe_key[0] = '\0';
else
{
strncpy (safe_key, wep_key, IW_ENCODING_TOKEN_MAX);
safe_key[IW_ENCODING_TOKEN_MAX] = '\0';
}
iwlib_socket = iw_sockets_open ();
if (iwlib_socket >= 0)
{
wreq.u.data.pointer = (caddr_t) NULL;
wreq.u.data.flags = IW_ENCODE_ENABLED;
wreq.u.data.length = 0;
if (strlen (safe_key) == 0)
{
wreq.u.data.flags = IW_ENCODE_DISABLED | IW_ENCODE_NOKEY; /* Disable WEP */
set_key = TRUE;
}
else
{
keylen = iw_in_key_full(iwlib_socket, nm_device_get_iface (dev), "", safe_key, &wreq.u.data.flags);
if (keylen > 0)
{
wreq.u.data.pointer = (caddr_t) safe_key;
wreq.u.data.length = keylen;
set_key = TRUE;
}
}
if (set_key)
{
err = iw_set_ext (iwlib_socket, nm_device_get_iface (dev), SIOCSIWENCODE, &wreq);
if (err == -1)
NM_DEBUG_PRINT_2 ("nm_device_set_wep_key(): error setting key for device %s. errno = %d\n", nm_device_get_iface (dev), errno);
}
close (iwlib_socket);
}
}
/*
* nm_device_set_up_down
*
* Set the up flag on the device on or off
*
*/
static void nm_device_set_up_down (NMDevice *dev, gboolean up)
{
struct ifreq ifr;
int iface_fd;
int err;
guint32 flags = up ? IFF_UP : ~IFF_UP;
g_return_if_fail (dev != NULL);
iface_fd = nm_get_network_control_socket ();
if (iface_fd < 0)
return;
/* Get flags already there */
strcpy (ifr.ifr_name, nm_device_get_iface (dev));
err = ioctl (iface_fd, SIOCGIFFLAGS, &ifr);
if (!err)
{
/* If the interface doesn't have those flags already,
* set them on it.
*/
if ((ifr.ifr_flags^flags) & IFF_UP)
{
ifr.ifr_flags &= ~IFF_UP;
ifr.ifr_flags |= IFF_UP & flags;
err = ioctl (iface_fd, SIOCSIFFLAGS, &ifr);
if (err)
NM_DEBUG_PRINT_3 ("nm_device_set_up_down() could not bring device %s %s. errno = %d\n", nm_device_get_iface (dev), (up ? "up" : "down"), errno );
}
}
else
NM_DEBUG_PRINT_2 ("nm_device_set_up_down() could not get flags for device %s. errno = %d\n", nm_device_get_iface (dev), errno );
close (iface_fd);
}
/*
* Interface state functions: bring up, down, check
*
*/
void nm_device_bring_up (NMDevice *dev)
{
g_return_if_fail (dev != NULL);
nm_device_set_up_down (dev, TRUE);
}
void nm_device_bring_down (NMDevice *dev)
{
int fd;
g_return_if_fail (dev != NULL);
nm_device_set_up_down (dev, FALSE);
}
gboolean nm_device_is_up (NMDevice *dev)
{
int iface_fd;
struct ifreq ifr;
int err;
g_return_if_fail (dev != NULL);
iface_fd = nm_get_network_control_socket ();
if (iface_fd < 0)
return (FALSE);
/* Get device's flags */
strcpy (ifr.ifr_name, nm_device_get_iface (dev));
err = ioctl (iface_fd, SIOCGIFFLAGS, &ifr);
close (iface_fd);
if (!err)
return (!((ifr.ifr_flags^IFF_UP) & IFF_UP));
NM_DEBUG_PRINT_2 ("nm_device_is_up() could not get flags for device %s. errno = %d\n", nm_device_get_iface (dev), errno );
return (FALSE);
}
/*
* nm_device_ap_list_add
*
* Add an access point to the devices internal AP list.
*
*/
void nm_device_ap_list_add (NMDevice *dev, NMAccessPoint *ap)
{
g_return_if_fail (dev != NULL);
g_return_if_fail (ap != NULL);
g_return_if_fail (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET);
if (nm_try_acquire_mutex (dev->dev_options.wireless.ap_list_mutex, __FUNCTION__))
{
nm_ap_ref (ap);
dev->dev_options.wireless.ap_list = g_slist_append (dev->dev_options.wireless.ap_list, ap);
nm_unlock_mutex (dev->dev_options.wireless.ap_list_mutex, __FUNCTION__);
}
}
/*
* nm_device_ap_list_clear
*
* Clears out the device's internal list of available access points.
*
*/
void nm_device_ap_list_clear (NMDevice *dev)
{
GSList *element;
g_return_if_fail (dev != NULL);
g_return_if_fail (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET);
if (!dev->dev_options.wireless.ap_list)
return;
if (nm_try_acquire_mutex (dev->dev_options.wireless.ap_list_mutex, __FUNCTION__))
{
element = dev->dev_options.wireless.ap_list;
while (element)
{
if (element->data)
{
nm_ap_unref (element->data);
element->data = NULL;
}
element = g_slist_next (element);
}
g_slist_free (dev->dev_options.wireless.ap_list);
dev->dev_options.wireless.ap_list = NULL;
nm_unlock_mutex (dev->dev_options.wireless.ap_list_mutex, __FUNCTION__);
}
}
/*
* nm_device_ap_list_get_copy
*
* Copy the list of ESSIDs
*
*/
NMAccessPoint *nm_device_ap_list_get_ap (NMDevice *dev, int index)
{
GSList *element;
NMAccessPoint *ap = NULL;
g_return_val_if_fail (dev != NULL, NULL);
g_return_val_if_fail (dev->iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET, NULL);
if (!dev->dev_options.wireless.ap_list)
return;
if (nm_try_acquire_mutex (dev->dev_options.wireless.ap_list_mutex, __FUNCTION__))
{
int i = 0;
element = dev->dev_options.wireless.ap_list;
while (element)
{
if (element->data && (index == i))
{
ap = (NMAccessPoint *)(element->data);
break;
}
i++;
element = g_slist_next (element);
}
nm_unlock_mutex (dev->dev_options.wireless.ap_list_mutex, __FUNCTION__);
}
return (ap);
}
/****************************************/
/* Code ripped from HAL */
/* minor modifications made for */
/* integration with NLM */
/****************************************/
/** Read a word from the MII transceiver management registers
*
* @param iface Which interface
* @param location Which register
* @return Word that is read
*/
static guint16 mdio_read (int sockfd, struct ifreq *ifr, int location, gboolean new_ioctl_nums)
{
guint16 *data = (guint16 *) &(ifr->ifr_data);
data[1] = location;
if (ioctl (sockfd, new_ioctl_nums ? 0x8948 : SIOCDEVPRIVATE + 1, ifr) < 0)
{
NM_DEBUG_PRINT_2("SIOCGMIIREG on %s failed: %s\n", ifr->ifr_name, strerror (errno));
return -1;
}
return data[3];
}
static gboolean mii_get_link (NMDevice *dev)
{
int sockfd;
struct ifreq ifr;
gboolean new_ioctl_nums;
guint16 status_word;
gboolean link_active = FALSE;
sockfd = socket (AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
NM_DEBUG_PRINT_2("cannot open socket on interface %s; errno=%d", nm_device_get_iface (dev), errno);
return (FALSE);
}
snprintf (ifr.ifr_name, IFNAMSIZ, nm_device_get_iface (dev));
if (ioctl (sockfd, 0x8947, &ifr) >= 0)
new_ioctl_nums = TRUE;
else if (ioctl (sockfd, SIOCDEVPRIVATE, &ifr) >= 0)
new_ioctl_nums = FALSE;
else
{
NM_DEBUG_PRINT_2("SIOCGMIIPHY on %s failed: %s", ifr.ifr_name, strerror (errno));
close (sockfd);
return (FALSE);
}
/* Refer to http://www.scyld.com/diag/mii-status.html for
* the full explanation of the numbers
*
* 0x8000 Capable of 100baseT4.
* 0x7800 Capable of 10/100 HD/FD (most common).
* 0x0040 Preamble suppression permitted.
* 0x0020 Autonegotiation complete.
* 0x0010 Remote fault.
* 0x0008 Capable of Autonegotiation.
* 0x0004 Link established ("sticky"* on link failure)
* 0x0002 Jabber detected ("sticky"* on transmit jabber)
* 0x0001 Extended MII register exist.
*
*/
/* We have to read it twice to clear any "sticky" bits */
status_word = mdio_read (sockfd, &ifr, 1, new_ioctl_nums);
status_word = mdio_read (sockfd, &ifr, 1, new_ioctl_nums);
if ((status_word & 0x0016) == 0x0004)
link_active = TRUE;
else
link_active = FALSE;
close (sockfd);
return (link_active);
}
/****************************************/
/* End Code ripped from HAL */
/****************************************/

View file

@ -0,0 +1,79 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_DEVICE_H
#define NETWORK_MANAGER_DEVICE_H
#include "NetworkManager.h"
/*
* Types of NetworkManager devices
*/
enum NMIfaceType
{
NM_IFACE_TYPE_DONT_KNOW,
NM_IFACE_TYPE_WIRED_ETHERNET,
NM_IFACE_TYPE_WIRELESS_ETHERNET
};
typedef struct NMDevice NMDevice;
typedef enum NMIfaceType NMIfaceType;
NMDevice * nm_device_new (const char *iface);
void nm_device_ref (NMDevice *dev);
void nm_device_unref (NMDevice *dev);
char * nm_device_get_udi (NMDevice *dev);
void nm_device_set_udi (NMDevice *dev, const char *udi);
char * nm_device_get_iface (NMDevice *dev);
NMIfaceType nm_device_get_iface_type (NMDevice *dev);
/* There is no nm_device_set_iface_type() because that's determined when you set the device's iface */
gboolean nm_device_get_link_active (NMDevice *dev);
void nm_device_set_link_active (NMDevice *dev, const gboolean active);
gboolean nm_device_update_link_active (NMDevice *dev, gboolean check_mii);
gboolean nm_device_check_link_status (NMDevice *dev);
char * nm_device_get_essid (NMDevice *dev);
void nm_device_set_essid (NMDevice *dev, const char *essid);
gboolean nm_device_get_supports_wireless_scan (NMDevice *dev);
/* There is no function to get the WEP key since that's a slight security risk */
void nm_device_set_wep_key (NMDevice *dev, const char *wep_key);
void nm_device_bring_up (NMDevice *dev);
void nm_device_bring_down (NMDevice *dev);
gboolean nm_device_is_up (NMDevice *dev);
void nm_device_ap_list_add (NMDevice *dev, NMAccessPoint *ap);
void nm_device_ap_list_clear (NMDevice *dev);
NMAccessPoint *nm_device_ap_list_get_ap (NMDevice *dev, int index);
NMDevice * nm_get_device_by_udi (NMData *data, const char *udi);
NMDevice * nm_get_device_by_iface (NMData *data, const char *iface);
#endif

437
src/NetworkManagerPolicy.c Normal file
View file

@ -0,0 +1,437 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h"
#include "NetworkManagerAP.h"
extern gboolean debug;
/*
* nm_policy_activate_interface
*
* Performs interface switching and related networking goo.
*
*/
static void nm_policy_switch_interface (NMData *data, NMDevice *switch_to_dev, NMDevice *old_dev)
{
unsigned char buf[500];
unsigned char hostname[500] = "\0";
const unsigned char *new_iface;
int host_err;
int dhclient_err;
FILE *pidfile;
unsigned char pid[20];
g_return_if_fail (data != NULL);
g_return_if_fail (switch_to_dev != NULL);
g_return_if_fail (nm_device_get_iface (switch_to_dev));
g_return_if_fail (strlen (nm_device_get_iface (switch_to_dev)) >= 0);
/* If its a wireless device, set the ESSID and WEP key */
if (nm_device_get_iface_type (switch_to_dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
/* If there is a desired AP to connect to, use that essid and possible WEP key */
if ( data->desired_ap
&& (nm_ap_get_essid (data->desired_ap) != NULL))
{
nm_device_bring_down (switch_to_dev);
nm_device_set_essid (switch_to_dev, nm_ap_get_essid (data->desired_ap));
/* Disable WEP */
nm_device_set_wep_key (switch_to_dev, NULL);
if (nm_ap_get_wep_key (data->desired_ap))
nm_device_set_wep_key (switch_to_dev, nm_ap_get_wep_key (data->desired_ap));
}
else
{
/* If the card isn't up, bring it up so that we can scan. We may be too early here to have
* gotten all the scanning results, and therefore have no desired_ap. Just wait.
*/
if (!nm_device_is_up (switch_to_dev));
nm_device_bring_up (switch_to_dev);
NM_DEBUG_PRINT ("nm_policy_activate_interface() could not find a desired AP. Card doesn't support scanning?\n");
return; /* Don't associate with any non-allowed access points */
}
NM_DEBUG_PRINT_1 ("nm_policy_activate_interface() using essid '%s'\n", nm_ap_get_essid (data->desired_ap));
}
host_err = gethostname (hostname, 500);
/* Take out any entries in the routing table and any IP address the old interface
* had.
*/
if (old_dev && strlen (nm_device_get_iface (old_dev)))
{
/* Remove routing table entries */
snprintf (buf, 500, "/sbin/ip route flush dev %s", nm_device_get_iface (old_dev));
system (buf);
/* Remove ip address */
snprintf (buf, 500, "/sbin/ip address flush dev %s", nm_device_get_iface (old_dev));
system (buf);
}
/* Bring the device up */
if (!nm_device_is_up (switch_to_dev));
nm_device_bring_up (switch_to_dev);
/* Kill the old default route */
snprintf (buf, 500, "/sbin/ip route del default");
system (buf);
/* Find and kill the previous dhclient process for this interface */
new_iface = nm_device_get_iface (switch_to_dev);
snprintf (buf, 500, "/var/run/dhclient-%s.pid", new_iface);
pidfile = fopen (buf, "r");
if (pidfile)
{
int len;
fgets (pid, 20, pidfile);
len = strnlen (buf, 20);
if (len >= 20)
pid[0] = '\0';
else
pid[len-1] = '\0';
fclose (pidfile);
snprintf (buf, 500, "kill -9 %s", pid);
system (buf);
}
snprintf (buf, 500, "/sbin/dhclient -1 -q -lf /var/lib/dhcp/dhclient-%s.leases -pf /var/run/dhclient-%s.pid -cf /etc/dhclient-%s.conf %s\n",
new_iface, new_iface, new_iface, new_iface);
dhclient_err = system (buf);
if (dhclient_err != 0)
{
/* Wireless devices cannot be down if they are the active interface,
* otherwise we cannot use them for scanning.
*/
if (nm_device_get_iface_type (switch_to_dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
nm_device_set_essid (switch_to_dev, "");
nm_device_set_wep_key (switch_to_dev, NULL);
nm_device_bring_up (switch_to_dev);
}
}
/* Set the hostname back to what it was before so that X11 doesn't
* puke when the hostname changes, so that users can actually launch stuff.
*/
if (host_err >= 0)
sethostname (hostname, strlen (hostname));
/* Restart the nameservice caching daemon to make apps aware of new DNS servers */
snprintf (buf, 500, "/sbin/service nscd restart");
system (buf);
}
/*
* nm_state_modification_monitor
*
* Called every 2s and figures out which interface to switch the active
* network connection to if our global network state has changed.
* Global network state changes are triggered by:
* 1) insertion/deletion of interfaces
* 2) link state change of an interface
* 3) appearance/disappearance of an allowed wireless access point
*
*/
gboolean nm_state_modification_monitor (gpointer user_data)
{
NMData *data = (NMData *)user_data;
gboolean modified = FALSE;
g_return_val_if_fail (data != NULL, TRUE);
/* Check global state modified variable, and reset it with
* appropriate locking.
*/
g_mutex_lock (data->state_modified_mutex);
modified = data->state_modified;
if (data->state_modified)
data->state_modified = FALSE;
g_mutex_unlock (data->state_modified_mutex);
/* If any modifications to the data model were made, update
* network state based on policy applied to the data model.
*/
if (modified)
{
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
GSList *element = data->dev_list;
NMDevice *dev = NULL;
NMDevice *best_wired_dev = NULL;
guint best_wired_prio = 0;
NMDevice *best_wireless_dev = NULL;
guint best_wireless_prio = 0;
guint highest_priority = 0;
NMDevice *highest_priority_dev = NULL;
gboolean essid_change_needed = FALSE;
while (element)
{
guint priority = 0;
guint iface_type;
gboolean link_active;
dev = (NMDevice *)(element->data);
iface_type = nm_device_get_iface_type (dev);
link_active = nm_device_get_link_active (dev);
if (iface_type == NM_IFACE_TYPE_WIRED_ETHERNET)
{
guint prio = 0;
if (link_active)
prio += 1;
if (data->active_device
&& (dev == data->active_device)
&& link_active)
prio += 1;
if (prio > best_wired_prio)
{
best_wired_dev = dev;
best_wired_prio = prio;
}
}
else if (iface_type == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
guint prio = 0;
if (link_active)
prio += 1;
if (nm_device_get_supports_wireless_scan (dev))
prio += 2;
if ( data->active_device
&& (dev == data->active_device)
&& link_active)
prio += 3;
if (prio > best_wireless_prio)
{
best_wireless_dev = dev;
best_wireless_prio = prio;
}
}
element = g_slist_next (element);
}
NM_DEBUG_PRINT_1 ("Best wired device = %s\n", best_wired_dev ? nm_device_get_iface (best_wired_dev) : "(null)");
NM_DEBUG_PRINT_1 ("Best wireless device = %s\n", best_wireless_dev ? nm_device_get_iface (best_wireless_dev) : "(null)");
if (best_wireless_dev || best_wired_dev)
{
if (best_wired_dev)
highest_priority_dev = best_wired_dev;
else
highest_priority_dev = best_wireless_dev;
}
else
{
/* No devices at all, wait for them to change status */
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
return (TRUE);
}
/* If the current essid of the wireless card and the desired ap's essid are different,
* trigger an interface switch. We switch to the same interface, but we still need to bring
* the device up again to get a new DHCP address. However, don't switch if there is no
* desired ap.
*/
if (nm_device_get_iface_type (highest_priority_dev) == NM_IFACE_TYPE_WIRELESS_ETHERNET)
{
/* If we don't yet have a desired AP, attempt to get one. */
if (!data->desired_ap)
nm_wireless_do_scan (data, highest_priority_dev);
if ( data->desired_ap
&& (nm_null_safe_strcmp (nm_device_get_essid (highest_priority_dev), nm_ap_get_essid (data->desired_ap)) != 0)
&& (strlen (nm_ap_get_essid (data->desired_ap)) > 0))
essid_change_needed = TRUE;
}
/* If the highest priority device is different than data->active_device, switch the connection. */
if ( essid_change_needed
|| (!data->active_device || (highest_priority_dev == data->active_device)))
{
NM_DEBUG_PRINT_2 ("**** Switching active interface from '%s' to '%s'\n",
data->active_device ? nm_device_get_iface (data->active_device) : "(null)",
nm_device_get_iface (highest_priority_dev));
/* FIXME
* How long should we wait between the signal to the bus,
* and deactivating the device?
*/
if (data->active_device)
{
nm_dbus_signal_device_no_longer_active (data->dbus_connection, data->active_device);
sleep (2);
}
nm_policy_switch_interface (data, highest_priority_dev, data->active_device);
if (data->active_device)
nm_device_unref (data->active_device);
data->active_device = highest_priority_dev;
nm_device_ref (data->active_device);
nm_dbus_signal_device_now_active (data->dbus_connection, data->active_device);
NM_DEBUG_PRINT ("**** Switched.\n");
}
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT("nm_state_modification_monitor() could not get device list mutex\n");
}
return (TRUE);
}
/*
* nm_policy_update_allowed_access_points
*
* Grabs a list of allowed access points from the user's preferences
*
*/
void nm_policy_update_allowed_access_points (NMData *data)
{
#define NM_ALLOWED_AP_FILE "/etc/sysconfig/networking/allowed_access_points"
FILE *ap_file;
g_return_if_fail (data != NULL);
if (nm_try_acquire_mutex (data->allowed_ap_list_mutex, NULL))
{
ap_file = fopen (NM_ALLOWED_AP_FILE, "r");
if (ap_file)
{
gchar line[ 500 ];
gchar prio[ 20 ];
gchar essid[ 50 ];
gchar wep_key[ 50 ];
/* Free the old list of allowed access points */
nm_data_allowed_ap_list_free (data);
while (fgets (line, 499, ap_file))
{
guint len = strnlen (line, 499);
gchar *p = &line[0];
gchar *end = strchr (line, '\n');
guint op = 0;
strcpy (prio, "\0");
strcpy (essid, "\0");
strcpy (wep_key, "\0");
if (end)
*end = '\0';
else
end = p + len - 1;
while ((end-p > 0) && (*p=='\t'))
p++;
while (end-p > 0)
{
switch (op)
{
case 0:
strncat (prio, p, 1);
break;
case 1:
strncat (essid, p, 1);
break;
case 2:
strncat (wep_key, p, 1);
break;
default:
break;
}
p++;
if ((end-p > 0) && (*p=='\t'))
{
op++;
while ((end-p > 0) && (*p=='\t'))
p++;
}
}
/* Create a new entry for this essid */
if (strlen (essid) > 0)
{
NMAccessPoint *ap;
guint prio_num = atoi (prio);
if (prio_num < 1)
prio_num = NM_AP_PRIORITY_WORST;
else if (prio_num > NM_AP_PRIORITY_WORST)
prio_num = NM_AP_PRIORITY_WORST;
ap = nm_ap_new ();
nm_ap_set_priority (ap, prio_num);
nm_ap_set_essid (ap, essid);
nm_ap_set_wep_key (ap, wep_key);
data->allowed_ap_list = g_slist_append (data->allowed_ap_list, ap);
/*
NM_DEBUG_PRINT_3( "FOUND: allowed ap, prio=%d essid=%s wep_key=%s\n", prio_num, essid, wep_key );
*/
}
}
fclose (ap_file);
}
else
NM_DEBUG_PRINT_1( "nm_policy_update_allowed_access_points() could not open and lock allowed ap list file %s. errno %d\n", NM_ALLOWED_AP_FILE );
nm_unlock_mutex (data->allowed_ap_list_mutex, NULL);
}
else
NM_DEBUG_PRINT( "nm_policy_update_allowed_access_points() could not lock allowed ap list mutex\n" );
}

View file

@ -0,0 +1,32 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_POLICY_H
#define NETWORK_MANAGER_POLICY_H
#include "NetworkManager.h"
#include "NetworkManagerDevice.h"
gboolean nm_state_modification_monitor (gpointer user_data);
void nm_policy_update_allowed_access_points (NMData *data);
#endif

147
src/NetworkManagerUtils.c Normal file
View file

@ -0,0 +1,147 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <glib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include "NetworkManager.h"
#include "NetworkManagerUtils.h"
extern gboolean debug;
/*
* nm_try_acquire_mutex
*
* Tries to acquire a given mutex, sleeping a bit between tries.
*
* Returns: FALSE if mutex was not acquired
* TRUE if mutex was successfully acquired
*/
gboolean nm_try_acquire_mutex (GMutex *mutex, const char *func)
{
gint i = 5;
g_return_val_if_fail (mutex != NULL, FALSE);
while (i > 0)
{
if (g_mutex_trylock (mutex))
{
/*
if (func)
NM_DEBUG_PRINT_1 ("MUTEX: %s got mutex\n", func);
*/
return (TRUE);
}
usleep (500);
i++;
}
return (FALSE);
}
/*
* nm_unlock_mutex
*
* Simply unlocks a mutex, balances nm_try_acquire_mutex()
*
*/
void nm_unlock_mutex (GMutex *mutex, const char *func)
{
g_return_if_fail (mutex != NULL);
/*
if (func)
NM_DEBUG_PRINT_1 ("MUTEX: %s released mutex\n", func);
*/
g_mutex_unlock (mutex);
}
/*
* nm_null_safe_strcmp
*
* Doesn't freaking segfault if s1/s2 are NULL
*
*/
int nm_null_safe_strcmp (const char *s1, const char *s2)
{
if (!s1 && !s2)
return 0;
if (!s1 && s2)
return -1;
if (s1 && !s2)
return 1;
return (strcmp (s1, s2));
}
/*
* nm_get_network_control_socket
*
* Get a control socket for network operations.
*
*/
int nm_get_network_control_socket (void)
{
int fd;
/* Try to grab a control socket */
fd = socket(PF_INET, SOCK_DGRAM, 0);
if (fd >= 0)
return (fd);
fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd >= 0)
return (fd);
fd = socket(PF_INET6, SOCK_DGRAM, 0);
if (fd >= 0)
return (fd);
NM_DEBUG_PRINT ("nm_get_network_control_socket() could not get network control socket.\n");
return (-1);
}
/*
* nm_dispose_scan_results
*
* Free memory used by the wireless scan results structure
*
*/
void nm_dispose_scan_results (wireless_scan *result_list)
{
wireless_scan *tmp = result_list;
while (tmp)
{
wireless_scan *tmp2 = tmp;
tmp = tmp->next;
free (tmp2);
}
}

47
src/NetworkManagerUtils.h Normal file
View file

@ -0,0 +1,47 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_UTILS_H
#define NETWORK_MANAGER_UTILS_H
#include <glib.h>
#include <stdio.h>
#include <iwlib.h>
#include "NetworkManager.h"
#define NM_DEBUG_PRINT( s ) if (debug) fprintf( stderr, s );
#define NM_DEBUG_PRINT_1( s, a ) if (debug) fprintf( stderr, s, a );
#define NM_DEBUG_PRINT_2( s, a, b ) if (debug) fprintf( stderr, s, a, b );
#define NM_DEBUG_PRINT_3( s, a, b, c ) if (debug) fprintf( stderr, s, a, b, c );
#define NM_DEBUG_PRINT_4( s, a, b, c, d ) if (debug) fprintf( stderr, s, a, b, c, d );
gboolean nm_try_acquire_mutex (GMutex *mutex, const char *func);
void nm_unlock_mutex (GMutex *mutex, const char *func);
int nm_null_safe_strcmp (const char *s1, const char *s2);
int nm_get_network_control_socket (void);
void nm_dispose_scan_results (wireless_scan *result_list);
#endif

View file

@ -0,0 +1,215 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#include <stdio.h>
#include <iwlib.h>
#include "NetworkManager.h"
#include "NetworkManagerDevice.h"
#include "NetworkManagerWireless.h"
#include "NetworkManagerPolicy.h"
#include "NetworkManagerUtils.h"
extern gboolean debug;
/*
* nm_wireless_is_most_prefered_ap
*
* For a given AP, filter it through the allowed list and return TRUE if its
* both allowed _and_ has a better priority than highest_priority.
*
*/
static gboolean nm_wireless_is_most_prefered_ap (NMAccessPoint *ap, int *highest_priority)
{
NMData *data = nm_get_global_data ();
GSList *element;
gboolean is_most_preferred = FALSE;
g_return_val_if_fail (ap != NULL, FALSE);
/* Attempt to acquire mutex for device list iteration.
* If the acquire fails, just ignore the scan completely.
*/
if (nm_try_acquire_mutex (data->allowed_ap_list_mutex, __FUNCTION__))
{
element = data->allowed_ap_list;
while (element)
{
NMAccessPoint *allowed_ap = (NMAccessPoint *)(element->data);
/* If the essid of the scanned ap matches one in our allowed list, and this AP is
* a higher priority than one we may possibly have already found.
*/
if ( allowed_ap
&& (nm_null_safe_strcmp (nm_ap_get_essid (allowed_ap), nm_ap_get_essid (ap)) == 0)
&& (nm_ap_get_priority (allowed_ap) < *highest_priority))
{
is_most_preferred = TRUE;
break;
}
element = g_slist_next (element);
}
nm_unlock_mutex (data->allowed_ap_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_wireless_is_most_prefered_ap() could not acquire allowed access point mutex.\n" );
return (is_most_preferred);
}
/*
* nm_wireless_do_scan
*
* Runs the actual scan fore access points.
*
*/
void nm_wireless_do_scan (NMData *data, NMDevice *dev)
{
int iwlib_socket;
g_return_if_fail (data != NULL);
g_return_if_fail (dev != NULL);
if (nm_device_get_iface_type (dev) != NM_IFACE_TYPE_WIRELESS_ETHERNET)
return;
if (nm_device_get_supports_wireless_scan (dev) == FALSE)
return;
/* Device must be up before we can scan */
if (!nm_device_is_up (dev))
nm_device_bring_up (dev);
iwlib_socket = iw_sockets_open ();
if (iwlib_socket >= 0)
{
wireless_scan_head scan_results = { NULL, 0 };
wireless_scan *tmp_ap;
int err;
NMAccessPoint *highest_priority_ap = NULL;
int highest_priority = NM_AP_PRIORITY_WORST;
/* Clear out the device's ap list */
nm_device_ap_list_clear (dev);
err = iw_scan (iwlib_socket, nm_device_get_iface (dev), WIRELESS_EXT, &scan_results);
/* Iterate over scan results and pick a "most" preferred access point. */
tmp_ap = scan_results.result;
while (tmp_ap)
{
/* Blank essids usually indicate an AP that is not broadcasting its essid,
* but since its not broadcasting the essid, we cannot use that ap yet.
*/
if (tmp_ap->b.has_essid && tmp_ap->b.essid_on && (strlen (tmp_ap->b.essid) > 0))
{
NMAccessPoint *nm_ap = nm_ap_new ();
/* Copy over info from scan to local structure */
nm_ap_set_essid (nm_ap, tmp_ap->b.essid);
if (tmp_ap->has_ap_addr)
{
char buf[20];
memset (&buf[0], 0, 20);
iw_ether_ntop((const struct ether_addr *) (tmp_ap->ap_addr.sa_data), &buf[0]);
nm_ap_set_address (nm_ap, buf);
}
nm_ap_set_quality (nm_ap, tmp_ap->stats.qual.qual);
if (tmp_ap->b.has_freq)
nm_ap_set_freq (nm_ap, tmp_ap->b.freq);
/* Add the AP to the device's AP list, no matter if its allowed or not */
nm_device_ap_list_add (dev, nm_ap);
if (nm_wireless_is_most_prefered_ap (nm_ap, &highest_priority))
{
if (highest_priority_ap)
nm_ap_unref (highest_priority_ap);
highest_priority_ap = nm_ap_new_from_ap (nm_ap);
}
nm_ap_unref (nm_ap);
}
tmp_ap = tmp_ap->next;
}
nm_dispose_scan_results (scan_results.result);
/* If we have the "most" preferred access point, and its different than the current
* access point, switch to it during the next cycle.
*/
if ( highest_priority_ap
&& (!data->desired_ap || (nm_null_safe_strcmp (nm_device_get_essid (dev), nm_ap_get_essid (highest_priority_ap)) != 0)))
{
if (data->desired_ap)
nm_ap_unref (data->desired_ap);
data->desired_ap = nm_ap_new_from_ap (highest_priority_ap);
data->state_modified = TRUE;
nm_ap_unref (highest_priority_ap);
}
close (iwlib_socket);
}
else
NM_DEBUG_PRINT ("nm_wireless_do_scan() could not get a control socket for the wireless card.\n" );
}
/*
* nm_wireless_scan_monitor
*
* Called every 10s to get a list of access points.
*
*/
gboolean nm_wireless_scan_monitor (gpointer user_data)
{
NMData *data = (NMData *)user_data;
GSList *element;
NMDevice *dev;
g_return_val_if_fail (data != NULL, TRUE);
if (!data->active_device)
return (TRUE);
/* Grab a current list of allowed access points */
nm_policy_update_allowed_access_points (data);
/* Attempt to acquire mutex for device list iteration.
* If the acquire fails, just ignore the scan completely.
*/
if (nm_try_acquire_mutex (data->dev_list_mutex, __FUNCTION__))
{
if (data->active_device && (nm_device_get_iface_type (data->active_device) == NM_IFACE_TYPE_WIRELESS_ETHERNET))
nm_wireless_do_scan (data, data->active_device);
nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
}
else
NM_DEBUG_PRINT( "nm_wireless_scan_monitor() could not acquire device list mutex.\n" );
return (TRUE);
}

View file

@ -0,0 +1,28 @@
/* NetworkManager -- Network link manager
*
* Dan Williams <dcbw@redhat.com>
*
* 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.
*
* (C) Copyright 2004 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_WIRELESS_H
#define NETWORK_MANAGER_WIRELESS_H
gboolean nm_wireless_scan_monitor (gpointer user_data);
#endif

11
test/Makefile.am Normal file
View file

@ -0,0 +1,11 @@
INCLUDES = \
$(NM_CFLAGS) \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\"
noinst_PROGRAMS = nmclienttest
nmclienttest_SOURCES = nmclienttest.c
nmclienttest_LDADD = $(NM_LIBS)

366
test/Makefile.in Normal file
View file

@ -0,0 +1,366 @@
# Makefile.in generated by automake 1.7.9 from Makefile.am.
# @configure_input@
# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
top_builddir = ..
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
INSTALL = @INSTALL@
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
ACLOCAL = @ACLOCAL@
AMDEP_FALSE = @AMDEP_FALSE@
AMDEP_TRUE = @AMDEP_TRUE@
AMTAR = @AMTAR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CYGPATH_W = @CYGPATH_W@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
EXEEXT = @EXEEXT@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
IWLIB = @IWLIB@
LDFLAGS = @LDFLAGS@
LIBOBJS = @LIBOBJS@
LIBS = @LIBS@
LTLIBOBJS = @LTLIBOBJS@
MAKEINFO = @MAKEINFO@
NM_CFLAGS = @NM_CFLAGS@
NM_LIBS = @NM_LIBS@
OBJEXT = @OBJEXT@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PKG_CONFIG = @PKG_CONFIG@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
VERSION = @VERSION@
ac_ct_CC = @ac_ct_CC@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build_alias = @build_alias@
datadir = @datadir@
exec_prefix = @exec_prefix@
host_alias = @host_alias@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localstatedir = @localstatedir@
mandir = @mandir@
oldincludedir = @oldincludedir@
prefix = @prefix@
program_transform_name = @program_transform_name@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
INCLUDES = \
$(NM_CFLAGS) \
-DDBUS_API_SUBJECT_TO_CHANGE \
-DBINDIR=\"$(bindir)\" \
-DDATADIR=\"$(datadir)\"
noinst_PROGRAMS = nmclienttest
nmclienttest_SOURCES = nmclienttest.c
nmclienttest_LDADD = $(NM_LIBS)
subdir = test
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
noinst_PROGRAMS = nmclienttest$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)
am_nmclienttest_OBJECTS = nmclienttest.$(OBJEXT)
nmclienttest_OBJECTS = $(am_nmclienttest_OBJECTS)
nmclienttest_DEPENDENCIES =
nmclienttest_LDFLAGS =
DEFAULT_INCLUDES = -I. -I$(srcdir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/nmclienttest.Po
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
DIST_SOURCES = $(nmclienttest_SOURCES)
DIST_COMMON = $(srcdir)/Makefile.in Makefile.am
SOURCES = $(nmclienttest_SOURCES)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .o .obj
$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu test/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)
clean-noinstPROGRAMS:
-test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS)
nmclienttest$(EXEEXT): $(nmclienttest_OBJECTS) $(nmclienttest_DEPENDENCIES)
@rm -f nmclienttest$(EXEEXT)
$(LINK) $(nmclienttest_LDFLAGS) $(nmclienttest_OBJECTS) $(nmclienttest_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT) core *.core
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nmclienttest.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `test -f '$<' || echo '$(srcdir)/'`$<; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `test -f '$<' || echo '$(srcdir)/'`$<
.c.obj:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
@am__fastdepCC_TRUE@ -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; \
@am__fastdepCC_TRUE@ else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; \
@am__fastdepCC_TRUE@ fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(COMPILE) -c `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(srcdir)/$<'; fi`
uninstall-info-am:
ETAGS = etags
ETAGSFLAGS =
CTAGS = ctags
CTAGSFLAGS =
tags: TAGS
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
mkid -fID $$unique
TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(ETAGS_ARGS)$$tags$$unique" \
|| $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$tags $$unique
ctags: CTAGS
CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
$(TAGS_FILES) $(LISP)
tags=; \
here=`pwd`; \
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | \
$(AWK) ' { files[$$0] = 1; } \
END { for (i in files) print i; }'`; \
test -z "$(CTAGS_ARGS)$$tags$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$tags $$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& cd $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) $$here
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
top_distdir = ..
distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
distdir: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
list='$(DISTFILES)'; for file in $$list; do \
case $$file in \
$(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
$(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
esac; \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
if test "$$dir" != "$$file" && test "$$dir" != "."; then \
dir="/$$dir"; \
$(mkinstalldirs) "$(distdir)$$dir"; \
else \
dir=''; \
fi; \
if test -d $$d/$$file; then \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
fi; \
cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
else \
test -f $(distdir)/$$file \
|| cp -p $$d/$$file $(distdir)/$$file \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
all-am: Makefile $(PROGRAMS)
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
`test -z '$(STRIP)' || \
echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
mostlyclean-generic:
clean-generic:
distclean-generic:
-rm -f $(CONFIG_CLEAN_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-noinstPROGRAMS mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
info: info-am
info-am:
install-data-am:
install-exec-am:
install-info: install-info-am
install-man:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -rf ./$(DEPDIR)
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am: uninstall-info-am
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
clean-noinstPROGRAMS ctags distclean distclean-compile \
distclean-generic distclean-tags distdir dvi dvi-am info \
info-am install install-am install-data install-data-am \
install-exec install-exec-am install-info install-info-am \
install-man install-strip installcheck installcheck-am \
installdirs maintainer-clean maintainer-clean-generic \
mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \
ps ps-am tags uninstall uninstall-am uninstall-info-am
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:

435
test/nmclienttest.c Normal file
View file

@ -0,0 +1,435 @@
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <stdio.h>
char * get_active_device (DBusConnection *connection)
{
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
char *device_path;
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
"getActiveDevice");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return;
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
char *string;
string = dbus_message_iter_get_string (&iter);
if (!string)
{
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
return;
}
fprintf (stderr, "Active device: '%s'\n", string );
dbus_message_unref (reply);
dbus_message_unref (message);
device_path = g_strdup (string);
return (device_path);
}
void get_device_name (DBusConnection *connection, char *path)
{
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
path,
"org.freedesktop.NetworkManager",
"getName");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return;
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
char *string;
string = dbus_message_iter_get_string (&iter);
if (!string)
{
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
return;
}
fprintf (stderr, "Active device name: '%s'\n", string );
dbus_message_unref (reply);
dbus_message_unref (message);
}
void get_device_active_network (DBusConnection *connection, char *path)
{
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
path,
"org.freedesktop.NetworkManager",
"getActiveNetwork");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return;
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
char *string;
string = dbus_message_iter_get_string (&iter);
if (!string)
{
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
return;
}
fprintf (stderr, "Active device's Network: '%s' ", string );
dbus_message_unref (reply);
dbus_message_unref (message);
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
string,
"org.freedesktop.NetworkManager",
"getName");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return;
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
string = dbus_message_iter_get_string (&iter);
if (!string)
{
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
return;
}
fprintf (stderr, " (%s)\n", string );
dbus_message_unref (reply);
dbus_message_unref (message);
}
int get_device_type (DBusConnection *connection, char *path)
{
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
path,
"org.freedesktop.NetworkManager",
"getType");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return (-1);
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return (-1);
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return (-1);
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
int type;
type = dbus_message_iter_get_int32 (&iter);
fprintf (stderr, "Active device type: '%d'\n", type );
dbus_message_unref (reply);
dbus_message_unref (message);
return (type);
}
void get_device_networks (DBusConnection *connection, const char *path)
{
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
path,
"org.freedesktop.NetworkManager",
"getNetworks");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return;
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
char **networks;
int num_networks;
if (!dbus_message_iter_get_string_array (&iter, &networks, &num_networks))
{
fprintf (stderr, "NetworkManager returned no device list" );
return;
}
dbus_message_unref (reply);
dbus_message_unref (message);
int i;
fprintf( stderr, "Networks:\n" );
for (i = 0; i < num_networks; i++)
{
DBusMessage *message2;
DBusMessage *reply2;
DBusMessageIter iter2;
DBusError error2;
message2 = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
networks[i],
"org.freedesktop.NetworkManager",
"getName");
if (message2 == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error2);
reply2 = dbus_connection_send_with_reply_and_block (connection, message2, -1, &error2);
if (dbus_error_is_set (&error2))
{
fprintf (stderr, "%s raised:\n %s\n\n", error2.name, error2.message);
dbus_message_unref (message2);
return;
}
if (reply2 == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message2);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply2, &iter2);
const char *string2 = dbus_message_iter_get_string (&iter2);
if (!string2)
{
fprintf (stderr, "NetworkManager returned a NULL active device object path" );
return;
}
dbus_message_unref (reply2);
dbus_message_unref (message2);
fprintf( stderr, " %s (%s)\n", networks[i], string2 );
}
dbus_free_string_array (networks);
}
void get_devices (DBusConnection *connection)
{
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
DBusError error;
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
"getDevices");
if (message == NULL)
{
fprintf (stderr, "Couldn't allocate the dbus message\n");
return;
}
dbus_error_init (&error);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
dbus_message_unref (message);
return;
}
if (reply == NULL)
{
fprintf( stderr, "dbus reply message was NULL\n" );
dbus_message_unref (message);
return;
}
/* now analyze reply */
dbus_message_iter_init (reply, &iter);
char **devices;
int num_devices;
if (!dbus_message_iter_get_string_array (&iter, &devices, &num_devices))
{
fprintf (stderr, "NetworkManager returned no device list" );
return;
}
dbus_message_unref (reply);
dbus_message_unref (message);
int i;
fprintf( stderr, "Devices:\n" );
for (i = 0; i < num_devices; i++)
fprintf( stderr, " %s\n", devices[i] );
dbus_free_string_array (devices);
}
int main( int argc, char *argv[] )
{
DBusConnection *connection;
DBusError error;
g_type_init ();
dbus_error_init (&error);
connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
if (connection == NULL)
{
fprintf (stderr, "Error connecting to system bus: %s\n", error.message);
dbus_error_free (&error);
return 1;
}
char *path;
int type;
path = get_active_device (connection);
get_device_name (connection, path);
type = get_device_type (connection, path);
if (type == 2)
{
get_device_active_network (connection, path);
get_device_networks (connection, path);
}
get_devices (connection);
g_free (path);
return 0;
}