12 #include <sys/socket.h>
22 if (gate_addr ==
NULL)
24 if (
sscanf(gate_addr,
"%d.%d.%d.%d", &tap_addr[0],
25 &tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4) {
37 if ((gate_addr !=
NULL) &&
38 (
sscanf(gate_addr,
"%d.%d.%d.%d", &tap_addr[0],
39 &tap_addr[1], &tap_addr[2], &tap_addr[3]) == 4) &&
40 (eth_addr[0] == tap_addr[0]) &&
41 (eth_addr[1] == tap_addr[1]) &&
42 (eth_addr[2] == tap_addr[2]) &&
43 (eth_addr[3] == tap_addr[3])) {
45 "address must be different\n");
52 int remain,
ret, expected;
62 ret =
read(fd, &remain,
sizeof(remain));
64 if (ret !=
sizeof(remain)) {
67 expected =
sizeof(remain);
73 expected = (remain < len) ? remain : len;
74 ret =
read(fd, output, expected);
75 if (ret != expected) {
89 "errno = %d\n", str, -ret);
92 "%d of %d bytes\n", str, ret, expected);
99 n =
read(fd, buf, len);
127 n =
write(fd, buf, len);
172 static void change_pre_exec(
void *
arg)
180 static int change_tramp(
char **argv,
char *output,
int output_len)
191 pe_data.close_me = fds[0];
192 pe_data.stdout = fds[1];
193 pid =
run_helper(change_pre_exec, &pe_data, argv);
206 static void change(
char *
dev,
char *
what,
unsigned char *
addr,
207 unsigned char *netmask)
209 char addr_buf[
sizeof(
"255.255.255.255\0")];
210 char netmask_buf[
sizeof(
"255.255.255.255\0")];
211 char version[
sizeof(
"nnnnn\0")];
218 sprintf(addr_buf,
"%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
219 sprintf(netmask_buf,
"%d.%d.%d.%d", netmask[0], netmask[1],
220 netmask[2], netmask[3]);
222 output_len = UM_KERN_PAGE_SIZE;
228 pid = change_tramp(argv, output, output_len);
234 if (output !=
NULL) {
242 change(arg,
"add", addr, netmask);
247 change(arg,
"del", addr, netmask);