1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*
VTun - Virtual Tunnel over TCP/IP network.
Copyright (C) 1998-2008 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: lib.h,v 1.7.2.2 2008/01/07 22:35:41 mtbishop Exp $
*/
#ifndef _VTUN_LIB_H
#define _VTUN_LIB_H
#include "config.h"
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
#ifndef HAVE_SETPROC_TITLE
void init_title(int argc,char *argv[],char *env[], char *name);
void set_title(const char *ftm, ...);
#else
#define init_title( a... )
#define set_title setproctitle
#endif /* HAVE_SETPROC_TITLE */
#ifndef min
#define min(a,b) ( (a)<(b) ? (a):(b) )
#endif
int readn_t(int fd, void *buf, size_t count, time_t timeout);
int print_p(int f, const char *ftm, ...);
int run_cmd(void *d, void *opt);
void free_sopt(struct vtun_sopt *opt);
/* IO cancelation */
extern volatile sig_atomic_t __io_canceled;
static inline void io_init(void)
{
__io_canceled = 0;
}
static inline void io_cancel(void)
{
__io_canceled = 1;
}
/* signal safe syslog function */
void vtun_syslog (int priority, char *format, ...);
/* Read exactly len bytes (Signal safe)*/
static inline int read_n(int fd, char *buf, int len)
{
register int t=0, w;
while (!__io_canceled && len > 0) {
if( (w = read(fd, buf, len)) < 0 ){
if( errno == EINTR || errno == EAGAIN )
continue;
return -1;
}
if( !w )
return 0;
len -= w; buf += w; t += w;
}
return t;
}
/* Write exactly len bytes (Signal safe)*/
static inline int write_n(int fd, char *buf, int len)
{
register int t=0, w;
while (!__io_canceled && len > 0) {
if( (w = write(fd, buf, len)) < 0 ){
if( errno == EINTR || errno == EAGAIN )
continue;
return -1;
}
if( !w )
return 0;
len -= w; buf += w; t += w;
}
return t;
}
#endif /* _VTUN_LIB_H */
|