3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "interface.h"
24 #include "pathconfig.h"
26 #include <lib_internal/command.h>
27 #include <lib_internal/util.h>
28 #include <ensc_fmt/fmt.h>
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
34 Iface_getIPv4Prefix(struct Interface const *iface)
36 uint32_t mask = iface->addr.ipv4.mask;
47 invokeIpAddr(struct Interface const *iface)
50 unsigned int prefix = Iface_getIPv4Prefix(iface);
51 char buf[sizeof("255.255.255.255/") + sizeof(unsigned int)*3 + 1];
52 char * tmp = inet_ntoa(*reinterpret_cast(struct in_addr *)(&iface->addr.ipv4.ip));
53 size_t l = strlen(tmp);
56 if (l>=sizeof("255.255.255.255")) {
60 ptr = Xmemcpy(buf, tmp, l);
62 l = utilvserver_fmt_uint(ptr, prefix);
65 Command_init(&cmd, 5);
66 Command_appendParameter(&cmd, "/bin/echo");
67 Command_appendParameter(&cmd, PROG_IP);
68 Command_appendParameter(&cmd, buf);
69 Command_appendParameter(&cmd, "broadcast");
70 if (iface->addr.ipv4.bcast!=0)
71 Command_appendParameter(&cmd, inet_ntoa(*reinterpret_cast(struct in_addr *)(&iface->addr.ipv4.bcast)));
73 Command_appendParameter(&cmd, "+");
75 size_t l1 = strlen(iface->dev);
76 size_t l2 = iface->name ? strlen(iface->name) : 0;
77 char devlabel[l1 + l2 + sizeof(":")];
80 ptr = Xmemcpy(devlabel, iface->dev, l1);
82 ptr = Xmemcpy(ptr, iface->name, l2);
85 Command_appendParameter(&cmd, "label");
86 Command_appendParameter(&cmd, devlabel);
89 Command_appendParameter(&cmd, "dev");
90 Command_appendParameter(&cmd, iface->dev);
92 if (!Command_exec(&cmd, true) ||
93 !Command_wait(&cmd, true))
102 addVLAN(struct Interface const *iface)
104 abort(); // TODO: implement me
108 addIndirect(struct Interface const *iface)
110 abort(); // TODO: implement me
114 addIP(struct Interface const *iface)
116 return invokeIpAddr(iface);
117 //invokeIpLink(iface);
121 Iface_add(struct Interface const *iface)
123 if (iface->nodev) return true;
124 if (strchr(iface->dev, '.')!=0) return addVLAN(iface);
125 if (!iface->direct) return addIndirect(iface);