fix a bug in tun2socks
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -392,8 +392,15 @@ int main (int argc, char **argv)
|
||||
|
||||
#ifdef ANDROID
|
||||
// use supplied file descriptor
|
||||
if (!BTap_InitWithFD(&device, &ss, options.tun_fd, options.tun_mtu, device_error_handler, NULL, 1)) {
|
||||
BLog(BLOG_ERROR, "BTap_InitWithFD failed");
|
||||
|
||||
struct BTap_init_data init_data;
|
||||
init_data.dev_type = BTAP_DEV_TUN;
|
||||
init_data.init_type = BTAP_INIT_FD;
|
||||
init_data.init.fd.fd = options.tun_fd;
|
||||
init_data.init.fd.mtu = options.tun_mtu;
|
||||
|
||||
if (!BTap_Init2(&device, &ss, init_data, device_error_handler, NULL)) {
|
||||
BLog(BLOG_ERROR, "BTap_Init2 failed");
|
||||
goto fail3;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -195,51 +195,6 @@ int BTap_Init (BTap *o, BReactor *reactor, char *devname, BTap_handler_error han
|
||||
return BTap_Init2(o, reactor, init_data, handler_error, handler_error_user);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
int BTap_InitWithFD (BTap *o, BReactor *reactor, int fd, int mtu, BTap_handler_error handler_error, void *handler_error_user, int tun)
|
||||
{
|
||||
ASSERT(tun == 0 || tun == 1)
|
||||
|
||||
#ifndef BADVPN_LINUX
|
||||
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
|
||||
o->reactor = reactor;
|
||||
o->handler_error = handler_error;
|
||||
o->handler_error_user = handler_error_user;
|
||||
o->frame_mtu = mtu;
|
||||
o->fd = fd;
|
||||
|
||||
// init file descriptor object
|
||||
BFileDescriptor_Init(&o->bfd, o->fd, (BFileDescriptor_handler)fd_handler, o);
|
||||
if (!BReactor_AddFileDescriptor(o->reactor, &o->bfd)) {
|
||||
BLog(BLOG_ERROR, "BReactor_AddFileDescriptor failed");
|
||||
goto fail1;
|
||||
}
|
||||
o->poll_events = 0;
|
||||
|
||||
goto success;
|
||||
|
||||
fail1:
|
||||
ASSERT_FORCE(close(o->fd) == 0)
|
||||
fail0:
|
||||
return 0;
|
||||
|
||||
success:
|
||||
// init output
|
||||
PacketRecvInterface_Init(&o->output, o->frame_mtu, (PacketRecvInterface_handler_recv)output_handler_recv, o, BReactor_PendingGroup(o->reactor));
|
||||
|
||||
// set no output packet
|
||||
o->output_packet = NULL;
|
||||
|
||||
DebugError_Init(&o->d_err, BReactor_PendingGroup(o->reactor));
|
||||
DebugObject_Init(&o->d_obj);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int BTap_Init2 (BTap *o, BReactor *reactor, struct BTap_init_data init_data, BTap_handler_error handler_error, void *handler_error_user)
|
||||
{
|
||||
ASSERT(init_data.dev_type == BTAP_DEV_TUN || init_data.dev_type == BTAP_DEV_TAP)
|
||||
|
||||
@@ -107,10 +107,6 @@ typedef struct {
|
||||
*/
|
||||
int BTap_Init (BTap *o, BReactor *bsys, char *devname, BTap_handler_error handler_error, void *handler_error_user, int tun) WARN_UNUSED;
|
||||
|
||||
#ifdef ANDROID
|
||||
int BTap_InitWithFD (BTap *o, BReactor *bsys, int fd, int mtu, BTap_handler_error handler_error, void *handler_error_user, int tun) WARN_UNUSED;
|
||||
#endif
|
||||
|
||||
enum BTap_dev_type {BTAP_DEV_TUN, BTAP_DEV_TAP};
|
||||
|
||||
enum BTap_init_type {
|
||||
|
||||
Reference in New Issue
Block a user