Initial revision
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@2 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
11
test/Makefile.am
Normal file
11
test/Makefile.am
Normal 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
366
test/Makefile.in
Normal 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
435
test/nmclienttest.c
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user