diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-12-24 03:00:36 +0100 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-12-24 03:00:36 +0100 |
commit | 5bc520d3b5025d29a1782fc093d2f8532580e767 (patch) | |
tree | 661f90b6245bdb156a1031223819a63a596ed23a | |
parent | 743f1f56acd3622f93d339370ea923c18814d241 (diff) | |
download | connman-5bc520d3b5025d29a1782fc093d2f8532580e767.tar.gz connman-5bc520d3b5025d29a1782fc093d2f8532580e767.tar.bz2 connman-5bc520d3b5025d29a1782fc093d2f8532580e767.zip |
Add helper script and configuration file for DHCP support
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.in | 8 | ||||
-rw-r--r-- | scripts/Makefile.am | 14 | ||||
-rw-r--r-- | scripts/dhclient-script.c | 110 | ||||
-rw-r--r-- | scripts/dhclient.conf | 3 |
5 files changed, 135 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am index 0a0969fa..52247b98 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ -SUBDIRS = include src plugins +SUBDIRS = include src plugins scripts MAINTAINERCLEANFILES = Makefile.in \ aclocal.m4 configure config.h.in config.sub config.guess \ diff --git a/configure.in b/configure.in index 930691af..8f13afcd 100644 --- a/configure.in +++ b/configure.in @@ -34,9 +34,15 @@ PKG_CHECK_MODULES(GDBUS, gdbus, dummy=yes, AC_SUBST(GDBUS_CFLAGS) AC_SUBST(GDBUS_LIBS) +PKG_CHECK_MODULES(DBUS, dbus-1 >= 1.0, dummy=yes, + AC_MSG_ERROR(libdbus is required)) +AC_SUBST(DBUS_CFLAGS) +AC_SUBST(DBUS_LIBS) + PKG_CHECK_MODULES(HAL, hal >= 0.5.8, dummy=yes, AC_MSG_ERROR(libhal is required)) AC_SUBST(HAL_CFLAGS) AC_SUBST(HAL_LIBS) -AC_OUTPUT(Makefile include/Makefile src/Makefile plugins/Makefile) +AC_OUTPUT(Makefile include/Makefile src/Makefile + plugins/Makefile scripts/Makefile) diff --git a/scripts/Makefile.am b/scripts/Makefile.am new file mode 100644 index 00000000..bb79358e --- /dev/null +++ b/scripts/Makefile.am @@ -0,0 +1,14 @@ + +scriptdir = $(libdir)/connman/scripts + +script_DATA = dhclient.conf + +script_PROGRAMS = dhclient-script + +dhclient_script_LDADD = @DBUS_LIBS@ + +AM_CFLAGS = @DBUS_CFLAGS@ + +EXTRA_DIST = $(script_DATA) + +MAINTAINERCLEANFILES = Makefile.in diff --git a/scripts/dhclient-script.c b/scripts/dhclient-script.c new file mode 100644 index 00000000..39b235c7 --- /dev/null +++ b/scripts/dhclient-script.c @@ -0,0 +1,110 @@ +/* + * + * Connection Manager + * + * Copyright (C) 2007 Intel Corporation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <dbus/dbus.h> + +extern char **environ; + +static void append(DBusMessageIter *dict, const char *pattern) +{ + DBusMessageIter entry; + const char *key, *value; + char *delim; + + delim = strchr(pattern, '='); + *delim = '\0'; + + key = pattern; + value = delim + 1; + + dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY, + NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value); + + dbus_message_iter_close_container(dict, &entry); +} + +int main(int argc, char *argv[]) +{ + DBusConnection *conn; + DBusMessage *msg; + DBusMessageIter iter, dict; + dbus_uint32_t pid; + char **envp, *busname, *reason, *interface; + + busname = getenv("BUSNAME"); + + pid = atoi(getenv("pid")); + reason = getenv("reason"); + interface = getenv("interface"); + + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) + exit(1); + + msg = dbus_message_new_method_call(busname, "/org/isc/dhclient", + "org.isc.dhclient", "notify"); + if (msg == NULL) { + dbus_connection_unref(conn); + exit(1); + } + + dbus_message_append_args(msg, DBUS_TYPE_UINT32, &pid, + DBUS_TYPE_STRING, &reason, DBUS_TYPE_INVALID); + + dbus_message_iter_init_append(msg, &iter); + + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + for (envp = environ; envp && *envp; envp++) { + if (strlen(*envp) < 5) + continue; + + if (strncmp(*envp, "new_", 4) == 0 || + strncmp(*envp, "old_", 4) == 0 || + strncmp(*envp, "alia", 4) == 0) + append(&dict, *envp); + } + + dbus_message_iter_close_container(&iter, &dict); + + dbus_connection_send(conn, msg, NULL); + + dbus_message_unref(msg); + + dbus_connection_unref(conn); + + return 0; +} diff --git a/scripts/dhclient.conf b/scripts/dhclient.conf new file mode 100644 index 00000000..4b206a3b --- /dev/null +++ b/scripts/dhclient.conf @@ -0,0 +1,3 @@ +send host-name "<hostname>"; +request subnet-mask, broadcast-address, time-offset, routers, + domain-name, domain-name-servers, host-name; |