*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2012 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
#include <connman/plugin.h>
#include <connman/utsname.h>
#include <connman/log.h>
+#include <connman/inet.h>
static in_addr_t loopback_address;
static in_addr_t loopback_netmask;
struct sockaddr_in addr;
int sk, err;
- sk = socket(PF_INET, SOCK_DGRAM, 0);
+ sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sk < 0)
return -errno;
static int loopback_set_hostname(const char *hostname)
{
- int err;
+ const char *ptr;
+ int err, len;
if (g_strcmp0(hostname, "<hostname>") == 0)
return 0;
- if (sethostname(hostname, strlen(hostname)) < 0) {
+ len = strlen(hostname);
+
+ if (connman_inet_check_hostname(hostname, len) == FALSE)
+ return -EINVAL;
+
+ if ((ptr = strstr(hostname, ".")) != NULL)
+ len = ptr - hostname;
+
+ if (sethostname(hostname, len) < 0) {
err = -errno;
connman_error("Failed to set hostname to %s", hostname);
return err;
static int loopback_set_domainname(const char *domainname)
{
- int err;
+ int err, len;
+
+ len = strlen(domainname);
+
+ if (connman_inet_check_hostname(domainname, len) == FALSE)
+ return -EINVAL;
- if (setdomainname(domainname, strlen(domainname)) < 0) {
+ if (setdomainname(domainname, len) < 0) {
err = -errno;
connman_error("Failed to set domainname to %s", domainname);
return err;