rfe1744575 - cfg_file.y bugs (mf)
rfe1738167 - build on c5 still fails (bc) More -kkv cleanup on cvs macros
This commit is contained in:
54
generic/pipe_dev.c
Normal file
54
generic/pipe_dev.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: pipe_dev.c,v 1.4.2.1 2007/06/29 05:26:55 mtbishop Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "vtun.h"
|
||||
#include "lib.h"
|
||||
|
||||
/*
|
||||
* Create pipe. Return open fd.
|
||||
*/
|
||||
int pipe_open(int *fd)
|
||||
{
|
||||
return socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
|
||||
}
|
||||
|
||||
/* Write frames to pipe */
|
||||
int pipe_write(int fd, char *buf, int len)
|
||||
{
|
||||
return write_n(fd, buf, len);
|
||||
}
|
||||
|
||||
/* Read frames from pipe */
|
||||
int pipe_read(int fd, char *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
96
generic/pty_dev.c
Normal file
96
generic/pty_dev.c
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: pty_dev.c,v 1.4.2.1 2007/06/29 05:26:57 mtbishop Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "vtun.h"
|
||||
#include "lib.h"
|
||||
|
||||
/*
|
||||
* Allocate pseudo tty, returns master side fd.
|
||||
* Stores slave name in the first arg(must be large enough).
|
||||
*/
|
||||
int pty_open(char *sl_name)
|
||||
{
|
||||
int mr_fd;
|
||||
#if defined (HAVE_GETPT) && defined (HAVE_GRANTPT) && defined (HAVE_UNLOCKPT) && defined (HAVE_PTSNAME)
|
||||
char *ptyname;
|
||||
|
||||
if((mr_fd=getpt()) < 0)
|
||||
return -1;
|
||||
if(grantpt(mr_fd) != 0)
|
||||
return -1;
|
||||
if(unlockpt(mr_fd) != 0)
|
||||
return -1;
|
||||
if ((ptyname = (char*)ptsname(mr_fd)) == NULL)
|
||||
return -1;
|
||||
strcpy(sl_name, ptyname);
|
||||
return mr_fd;
|
||||
|
||||
#else
|
||||
|
||||
char ptyname[] = "/dev/ptyXY";
|
||||
char ch[] = "pqrstuvwxyz";
|
||||
char digit[] = "0123456789abcdefghijklmnopqrstuv";
|
||||
int l, m;
|
||||
|
||||
/* This algorithm should work for almost all standard Unices */
|
||||
for(l=0; ch[l]; l++ ) {
|
||||
for(m=0; digit[m]; m++ ) {
|
||||
ptyname[8] = ch[l];
|
||||
ptyname[9] = digit[m];
|
||||
/* Open the master */
|
||||
if( (mr_fd=open(ptyname, O_RDWR)) < 0 )
|
||||
continue;
|
||||
/* Check the slave */
|
||||
ptyname[5] = 't';
|
||||
if( (access(ptyname, R_OK | W_OK)) < 0 ){
|
||||
close(mr_fd);
|
||||
ptyname[5] = 'p';
|
||||
continue;
|
||||
}
|
||||
strcpy(sl_name,ptyname);
|
||||
return mr_fd;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Write frames to PTY device */
|
||||
int pty_write(int fd, char *buf, int len)
|
||||
{
|
||||
return write_n(fd, buf, len);
|
||||
}
|
||||
|
||||
/* Read frames from PTY device */
|
||||
int pty_read(int fd, char *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
75
generic/tap_dev.c
Normal file
75
generic/tap_dev.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: tap_dev.c,v 1.5.2.1 2007/06/29 05:26:59 mtbishop Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "vtun.h"
|
||||
#include "lib.h"
|
||||
|
||||
/*
|
||||
* Allocate Ether TAP device, returns opened fd.
|
||||
* Stores dev name in the first arg(must be large enough).
|
||||
*/
|
||||
int tap_open(char *dev)
|
||||
{
|
||||
char tapname[14];
|
||||
int i, fd;
|
||||
|
||||
if( *dev ) {
|
||||
sprintf(tapname, "/dev/%s", dev);
|
||||
return open(tapname, O_RDWR);
|
||||
}
|
||||
|
||||
for(i=0; i < 255; i++) {
|
||||
sprintf(tapname, "/dev/tap%d", i);
|
||||
/* Open device */
|
||||
if( (fd=open(tapname, O_RDWR)) > 0 ) {
|
||||
sprintf(dev, "tap%d",i);
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tap_close(int fd, char *dev)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
/* Write frames to TAP device */
|
||||
int tap_write(int fd, char *buf, int len)
|
||||
{
|
||||
return write(fd, buf, len);
|
||||
}
|
||||
|
||||
/* Read frames from TAP device */
|
||||
int tap_read(int fd, char *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
99
generic/tcp_proto.c
Normal file
99
generic/tcp_proto.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: tcp_proto.c,v 1.7.2.1 2007/06/29 05:27:02 mtbishop Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
#include "vtun.h"
|
||||
#include "lib.h"
|
||||
|
||||
int tcp_write(int fd, char *buf, int len)
|
||||
{
|
||||
register char *ptr;
|
||||
|
||||
ptr = buf - sizeof(short);
|
||||
|
||||
*((unsigned short *)ptr) = htons(len);
|
||||
len = (len & VTUN_FSIZE_MASK) + sizeof(short);
|
||||
|
||||
return write_n(fd, ptr, len);
|
||||
}
|
||||
|
||||
int tcp_read(int fd, char *buf)
|
||||
{
|
||||
unsigned short len, flen;
|
||||
register int rlen;
|
||||
|
||||
/* Read frame size */
|
||||
if( (rlen = read_n(fd, (char *)&len, sizeof(short)) ) <= 0)
|
||||
return rlen;
|
||||
|
||||
len = ntohs(len);
|
||||
flen = len & VTUN_FSIZE_MASK;
|
||||
|
||||
if( flen > VTUN_FRAME_SIZE + VTUN_FRAME_OVERHEAD ){
|
||||
/* Oversized frame, drop it. */
|
||||
while( flen ){
|
||||
len = min(flen, VTUN_FRAME_SIZE);
|
||||
if( (rlen = read_n(fd, buf, len)) <= 0 )
|
||||
break;
|
||||
flen -= rlen;
|
||||
}
|
||||
return VTUN_BAD_FRAME;
|
||||
}
|
||||
|
||||
if( len & ~VTUN_FSIZE_MASK ){
|
||||
/* Return flags */
|
||||
return len;
|
||||
}
|
||||
|
||||
/* Read frame */
|
||||
return read_n(fd, buf, flen);
|
||||
}
|
||||
74
generic/tun_dev.c
Normal file
74
generic/tun_dev.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: tun_dev.c,v 1.5.2.1 2007/06/29 05:27:06 mtbishop Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "vtun.h"
|
||||
#include "lib.h"
|
||||
|
||||
/*
|
||||
* Allocate TUN device, returns opened fd.
|
||||
* Stores dev name in the first arg(must be large enough).
|
||||
*/
|
||||
int tun_open(char *dev)
|
||||
{
|
||||
char tunname[14];
|
||||
int i, fd;
|
||||
|
||||
if( *dev ) {
|
||||
sprintf(tunname, "/dev/%s", dev);
|
||||
return open(tunname, O_RDWR);
|
||||
}
|
||||
|
||||
for(i=0; i < 255; i++){
|
||||
sprintf(tunname, "/dev/tun%d", i);
|
||||
/* Open device */
|
||||
if( (fd=open(tunname, O_RDWR)) > 0 ){
|
||||
sprintf(dev, "tun%d", i);
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tun_close(int fd, char *dev)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
/* Read/write frames from TUN device */
|
||||
int tun_write(int fd, char *buf, int len)
|
||||
{
|
||||
return write(fd, buf, len);
|
||||
}
|
||||
|
||||
int tun_read(int fd, char *buf, int len)
|
||||
{
|
||||
return read(fd, buf, len);
|
||||
}
|
||||
111
generic/udp_proto.c
Normal file
111
generic/udp_proto.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
VTun - Virtual Tunnel over TCP/IP network.
|
||||
|
||||
Copyright (C) 1998-2000 Maxim Krasnyansky <max_mk@yahoo.com>
|
||||
|
||||
VTun has been derived from VPPP package by Maxim Krasnyansky.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: udp_proto.c,v 1.10.2.1 2007/06/29 05:27:09 mtbishop Exp $
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/wait.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IN_SYSTM_H
|
||||
#include <netinet/in_systm.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_IP_H
|
||||
#include <netinet/ip.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
#include <netinet/udp.h>
|
||||
#endif
|
||||
|
||||
#include "vtun.h"
|
||||
#include "lib.h"
|
||||
|
||||
/* Functions to read/write UDP frames. */
|
||||
int udp_write(int fd, char *buf, int len)
|
||||
{
|
||||
register char *ptr;
|
||||
register int wlen;
|
||||
|
||||
ptr = buf - sizeof(short);
|
||||
|
||||
*((unsigned short *)ptr) = htons(len);
|
||||
len = (len & VTUN_FSIZE_MASK) + sizeof(short);
|
||||
|
||||
while( 1 ){
|
||||
if( (wlen = write(fd, ptr, len)) < 0 ){
|
||||
if( errno == EAGAIN || errno == EINTR )
|
||||
continue;
|
||||
if( errno == ENOBUFS )
|
||||
return 0;
|
||||
}
|
||||
/* Even if we wrote only part of the frame
|
||||
* we can't use second write since it will produce
|
||||
* another UDP frame */
|
||||
return wlen;
|
||||
}
|
||||
}
|
||||
|
||||
int udp_read(int fd, char *buf)
|
||||
{
|
||||
unsigned short hdr, flen;
|
||||
struct iovec iv[2];
|
||||
register int rlen;
|
||||
|
||||
/* Read frame */
|
||||
iv[0].iov_len = sizeof(short);
|
||||
iv[0].iov_base = (char *) &hdr;
|
||||
iv[1].iov_len = VTUN_FRAME_SIZE + VTUN_FRAME_OVERHEAD;
|
||||
iv[1].iov_base = buf;
|
||||
|
||||
while( 1 ){
|
||||
if( (rlen = readv(fd, iv, 2)) < 0 ){
|
||||
if( errno == EAGAIN || errno == EINTR )
|
||||
continue;
|
||||
else
|
||||
return rlen;
|
||||
}
|
||||
hdr = ntohs(hdr);
|
||||
flen = hdr & VTUN_FSIZE_MASK;
|
||||
|
||||
if( rlen < 2 || (rlen-2) != flen )
|
||||
return VTUN_BAD_FRAME;
|
||||
|
||||
return hdr;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user