Skip to content

Commit cfc51e2

Browse files
committedFeb 6, 2012
Patched to build with Android NDK.
(Android.mk is in batphone tree).
1 parent bac62f0 commit cfc51e2

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed
 

‎Makefile

100644100755
+3-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ NO_POLICY_ROUTING = -DNO_POLICY_ROUTING
3131
CC = gcc
3232
CFLAGS += -pedantic -Wall -W -Os -g3 -std=gnu99
3333
EXTRA_CFLAGS = -DDEBUG_MALLOC -DMEMORY_USAGE -DPROFILE_DATA $(NO_POLICY_ROUTING) -DREVISION_VERSION=$(REVISION_VERSION)
34-
LDFLAGS += -lpthread -Xlinker -I/data/data/org.servalproject/lib/ld-linux.so.3 -R/data/data/org.servalproject/lib -Xlinker -rpath=/data/data/org.servalproject/lib
34+
LDFLAGS += -lpthread -Xlinker -I/data/data/org.servalproject/libs/ld-linux.so.3 -R/data/data/org.servalproject/libs -Xlinker -rpath=/data/data/org.servalproject/libs
3535

3636
SBINDIR = $(INSTALL_PREFIX)/usr/sbin
3737

@@ -77,7 +77,8 @@ REVISION_VERSION =\"\ rv$(REVISION)\"
7777

7878
BAT_VERSION = $(shell grep "^\#define SOURCE_VERSION " $(SOURCE_VERSION_HEADER) | sed -e '1p' -n | awk -F '"' '{print $$2}' | awk '{print $$1}')
7979
FILE_NAME = $(PACKAGE_NAME)_$(BAT_VERSION)-rv$(REVISION)_$@
80-
NUM_CPUS = $(shell NUM_CPUS=`cat /proc/cpuinfo | grep -v 'model name' | grep processor | tail -1 | awk -F' ' '{print $$3}'`;echo `expr $$NUM_CPUS + 1`)
80+
#NUM_CPUS = $(shell NUM_CPUS=`cat /proc/cpuinfo | grep -v 'model name' | grep processor | tail -1 | awk -F' ' '{print $$3}'`;echo `expr $$NUM_CPUS + 1`)
81+
NUM_CPUS = 1
8182

8283

8384
all:

‎batman.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void update_routes(struct orig_node *orig_node, struct neigh_node *neigh_node, u
401401

402402
#ifdef NO_POLICY_ROUTING
403403
/* add new route AGAIN, if not using policy based routing as the process of deleting the old route can actually delete the new route
404-
as well. */
404+
as well. */
405405
add_del_route(orig_node->orig, 32, neigh_node->addr, neigh_node->if_incoming->addr.sin_addr.s_addr,
406406
neigh_node->if_incoming->if_index, neigh_node->if_incoming->dev, BATMAN_RT_TABLE_HOSTS, ROUTE_TYPE_UNICAST, ROUTE_ADD);
407407

‎batman.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
#include <stdint.h>
3232
#include <stdio.h>
3333

34+
#include <poll.h>
35+
#include <sys/select.h>
36+
3437
#define TYPE_OF_WORD uintmax_t /* you should choose something big, if you don't want to waste cpu */
3538

3639
#include "list-batman.h"

‎bsd/tun.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <netinet/in.h>
3030
#include <arpa/inet.h>
3131
#include <net/if.h>
32-
#include <net/if_tun.h>
32+
//#include <net/if_tun.h>
3333
#include <fcntl.h>
3434
#include <stdio.h>
3535
#include <stdlib.h>
@@ -158,12 +158,12 @@ int8_t add_dev_tun(struct batman_if *batman_if, uint32_t tun_addr,
158158
{
159159
int so;
160160
struct ifreq ifr_tun, ifr_if;
161-
struct tuninfo ti;
161+
// struct tuninfo ti;
162162
char *tun_ifname;
163163

164164
memset(&ifr_tun, 0, sizeof(ifr_tun));
165165
memset(&ifr_if, 0, sizeof(ifr_if));
166-
memset(&ti, 0, sizeof(ti));
166+
// memset(&ti, 0, sizeof(ti));
167167

168168
if ((*fd = open_tun_any(tun_dev, tun_dev_size)) < 0) {
169169
perror("Could not open tun device");
@@ -173,11 +173,11 @@ int8_t add_dev_tun(struct batman_if *batman_if, uint32_t tun_addr,
173173
printf("Using %s\n", tun_dev);
174174

175175
/* Initialise tuninfo to defaults. */
176-
if (ioctl(*fd, TUNGIFINFO, &ti) < 0) {
177-
perror("TUNGIFINFO");
178-
del_dev_tun(*fd);
176+
// if (ioctl(*fd, TUNGIFINFO, &ti) < 0) {
177+
// perror("TUNGIFINFO");
178+
// del_dev_tun(*fd);
179179
return -1;
180-
}
180+
// }
181181

182182
/* Set name of interface to configure ("tunX") */
183183
tun_ifname = strstr(tun_dev, "tun");
@@ -224,12 +224,12 @@ int8_t add_dev_tun(struct batman_if *batman_if, uint32_t tun_addr,
224224
if (ifr_if.ifr_mtu < 100) {
225225
fprintf(stderr, "Warning: MTU smaller than 100 - cannot reduce MTU anymore\n" );
226226
} else {
227-
ti.mtu = ifr_if.ifr_mtu - 28;
228-
if (ioctl(*fd, TUNSIFINFO, &ti) < 0) {
229-
perror("TUNSIFINFO");
230-
del_dev_tun(*fd);
227+
// ti.mtu = ifr_if.ifr_mtu - 28;
228+
// if (ioctl(*fd, TUNSIFINFO, &ti) < 0) {
229+
// perror("TUNSIFINFO");
230+
// del_dev_tun(*fd);
231231
return -1;
232-
}
232+
// }
233233
}
234234

235235
strlcpy(tun_dev, ifr_tun.ifr_name, tun_dev_size);

‎dprintf.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdio.h>
2+
#include <stdarg.h>
3+
#include <unistd.h>
4+
5+
void dprintf(int fd,const char *fmt, ...)
6+
{
7+
va_list ap;
8+
va_start(ap, fmt);
9+
vdprintf(fd,fmt,ap);
10+
va_end(ap);
11+
}
12+
13+
void vdprintf(int fd,const char *fmt,va_list ap)
14+
{
15+
char buff[8192];
16+
int len=vsnprintf(buff,8192,fmt,ap);
17+
if (len>-1) write(fd,buff,len);
18+
}

‎linux/tun.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@
4646
#define IPTABLES_ADD_ACC "iptables -t nat -I POSTROUTING -s %s/%i -j ACCEPT"
4747
#define IPTABLES_DEL_ACC "iptables -t nat -D POSTROUTING -s %s/%i -j ACCEPT"
4848

49-
5049
int run_cmd(char *cmd) {
51-
int error, pipes[2], stderr = -1, ret = 0;
50+
int error; int pipes[2]; int stderrfd = -1; int ret = 0;
5251
char error_log[256];
5352

5453
if (pipe(pipes) < 0) {
@@ -59,7 +58,7 @@ int run_cmd(char *cmd) {
5958
memset(error_log, 0, 256);
6059

6160
/* save stderr */
62-
stderr = dup(STDERR_FILENO);
61+
stderrfd = dup(STDERR_FILENO);
6362

6463
/* connect the commands output with the pipe for later logging */
6564
dup2(pipes[1], STDERR_FILENO);
@@ -68,8 +67,8 @@ int run_cmd(char *cmd) {
6867
error = system(cmd);
6968

7069
/* copy stderr back */
71-
dup2(stderr, STDERR_FILENO);
72-
close(stderr);
70+
dup2(stderrfd, STDERR_FILENO);
71+
close(stderrfd);
7372

7473
if ((error < 0) || (WEXITSTATUS(error) != 0)) {
7574
ret = read(pipes[0], error_log, sizeof(error_log));

0 commit comments

Comments
 (0)
Please sign in to comment.