5 * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include <sys/ioctl.h>
30 #include <sys/socket.h>
31 #include <arpa/inet.h>
34 #define CONNMAN_API_SUBJECT_TO_CHANGE
35 #include <connman/plugin.h>
36 #include <connman/log.h>
38 static int loopback_init(void)
41 struct sockaddr_in *addr;
44 sk = socket(PF_INET, SOCK_DGRAM, 0);
48 memset(&ifr, 0, sizeof(ifr));
49 strcpy(ifr.ifr_name, "lo");
51 if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
56 if (ifr.ifr_flags & IFF_UP) {
58 connman_info("The loopback interface is already up");
62 addr = (struct sockaddr_in *) &ifr.ifr_addr;
63 addr->sin_family = AF_INET;
64 addr->sin_addr.s_addr = inet_addr("127.0.0.0");
66 err = ioctl(sk, SIOCSIFADDR, &ifr);
69 connman_error("Setting address failed (%s)", strerror(-err));
73 addr = (struct sockaddr_in *) &ifr.ifr_netmask;
74 addr->sin_family = AF_INET;
75 addr->sin_addr.s_addr = inet_addr("255.0.0.0");
77 err = ioctl(sk, SIOCSIFNETMASK, &ifr);
80 connman_error("Setting netmask failed (%s)", strerror(-err));
84 if (ioctl(sk, SIOCGIFFLAGS, &ifr) < 0) {
89 ifr.ifr_flags |= IFF_UP;
91 if (ioctl(sk, SIOCSIFFLAGS, &ifr) < 0) {
93 connman_error("Activating loopback interface failed (%s)",
104 static void loopback_exit(void)
108 CONNMAN_PLUGIN_DEFINE(loopback, "Loopback device plugin", VERSION,
109 loopback_init, loopback_exit)