File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / inc / aitio.h
Revision 1.38.10.3: download - view: text, annotated - select for diffs - revision graph
Thu Dec 5 14:12:25 2013 UTC (10 years, 7 months ago) by misho
Branches: io6_7
Diff to: branchpoint 1.38: preferred, unified
add elwix replacement of popen/pclose api

    1: /*************************************************************************
    2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
    3: *  by Michael Pounov <misho@elwix.org>
    4: *
    5: * $Author: misho $
    6: * $Id: aitio.h,v 1.38.10.3 2013/12/05 14:12:25 misho Exp $
    7: *
    8: **************************************************************************
    9: The ELWIX and AITNET software is distributed under the following
   10: terms:
   11: 
   12: All of the documentation and software included in the ELWIX and AITNET
   13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   14: 
   15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
   16: 	by Michael Pounov <misho@elwix.org>.  All rights reserved.
   17: 
   18: Redistribution and use in source and binary forms, with or without
   19: modification, are permitted provided that the following conditions
   20: are met:
   21: 1. Redistributions of source code must retain the above copyright
   22:    notice, this list of conditions and the following disclaimer.
   23: 2. Redistributions in binary form must reproduce the above copyright
   24:    notice, this list of conditions and the following disclaimer in the
   25:    documentation and/or other materials provided with the distribution.
   26: 3. All advertising materials mentioning features or use of this software
   27:    must display the following acknowledgement:
   28: This product includes software developed by Michael Pounov <misho@elwix.org>
   29: ELWIX - Embedded LightWeight unIX and its contributors.
   30: 4. Neither the name of AITNET nor the names of its contributors
   31:    may be used to endorse or promote products derived from this software
   32:    without specific prior written permission.
   33: 
   34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
   35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   37: ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   44: SUCH DAMAGE.
   45: */
   46: #ifndef __AITIO_H
   47: #define __AITIO_H
   48: 
   49: 
   50: #define COMPAT_43TTY
   51: 
   52: #include <assert.h>
   53: #include <syslog.h>
   54: #include <openssl/evp.h>
   55: #include <openssl/aes.h>
   56: #include <sys/tty.h>
   57: #include <sys/ioctl_compat.h>
   58: #include <sys/socket.h>
   59: #include <sys/un.h>
   60: #include <sys/uio.h>
   61: #include <net/if_dl.h>
   62: #include <net/bpf.h>
   63: #include <netinet/in.h>
   64: #include <elwix.h>
   65: #include <aitsched.h>
   66: 
   67: 
   68: #ifndef STRSIZ
   69: #define STRSIZ			256
   70: #endif
   71: 
   72: #define IO_SOCK_ROLE_CLIENT	0
   73: #define IO_SOCK_ROLE_SERVER	1
   74: 
   75: #define IO_ETHER_FILTER_PROMISC	0
   76: #define IO_ETHER_FILTER_NOTREAD	-1
   77: #define IO_ETHER_FILTER_READ	1
   78: #define IO_ETHER_FILTER_WRITE	2
   79: 
   80: 
   81: typedef struct tagCliSock sock_cli_t;
   82: typedef void *(*sock_cb_t)(sock_cli_t*);
   83: struct tagCliSock {
   84: 	void				*cli_parent;
   85: 	int				cli_fd;
   86: 	int				cli_pty;
   87: 	sockaddr_t			cli_addr;
   88: 	char				cli_name[64];
   89: 	char				cli_cmdline[PATH_MAX];
   90: 	pid_t				cli_pid;
   91: 
   92: 	sched_task_func_t		cli_func;
   93: 
   94: 	ait_val_t			cli_buf[2];
   95: 
   96: 	TAILQ_ENTRY(tagCliSock)		cli_node;
   97: };
   98: 
   99: typedef struct {
  100: 	int				sock_role;
  101: 	int				sock_backq;
  102: 	int				sock_type;
  103: 	int				sock_proto;
  104: 	int 				sock_fd;
  105: 	struct timespec			sock_timeout;
  106: 	sockaddr_t			sock_addr;
  107: 	sockaddr_t			sock_peer;
  108: 
  109: 	ait_val_t			sock_buf;
  110: 
  111: 	volatile intptr_t		sock_kill;
  112: 	sched_root_task_t		*sock_root;
  113: 
  114: 	pthread_mutex_t			sock_mtx;
  115: 	TAILQ_HEAD(, tagCliSock)	sock_cli;
  116: } sock_t;
  117: 
  118: typedef struct {
  119: 	unsigned int			prog_inin;	/* init progs */
  120: 	unsigned int			prog_maxn;	/* max progs */
  121: 	unsigned int			prog_cnum;	/* current progs */
  122: 	char				prog_name[PATH_MAX];
  123: 
  124: 	pthread_mutex_t			prog_mtx;
  125: 	array_t				*prog_fds;
  126: } prog_t;
  127: 
  128: 
  129: // io_GetErrno() Get error code of last operation
  130: int io_GetErrno();
  131: // io_GetError() Get error text of last operation
  132: const char *io_GetError();
  133: 
  134: 
  135: /*
  136:  * io_popen() - ELWIX replacement of standard popen
  137:  *
  138:  * @command = command
  139:  * @type = type
  140:  * @ppid = return pid of child program
  141:  * return: NULL error or !=NULL open program
  142:  */
  143: FILE *io_popen(const char *command, const char *type, pid_t *ppid);
  144: /*
  145:  * io_pclose() - ELWIX replacement of standard pclose
  146:  *
  147:  * @iop = popen handle
  148:  * return: -1 error or !=-1 pid status
  149:  */
  150: int io_pclose(FILE *iop);
  151: 
  152: 
  153: /*
  154:  * io_progInit() - Init program pool
  155:  *
  156:  * @progName = program name for execution
  157:  * @initNum = initial started programs
  158:  * @maxNum = maximum started programs
  159:  * return: NULL error or !=NULL allocated pool (must destroied with io_progDestroy())
  160:  */
  161: prog_t *io_progInit(const char *progName, 
  162: 		unsigned int initNum, unsigned int maxNum);
  163: /*
  164:  * io_progOpen() - Execute number of program(s)
  165:  *
  166:  * @prg = program pool
  167:  * @execNum = execute program(s) (0 max)
  168:  * return: 0 error, >0 executed programs and abs(<0) executed programs with logged error
  169:  */
  170: int io_progOpen(prog_t * __restrict prg, unsigned int execNum);
  171: /*
  172:  * io_progVacuum() - Vacuum pool to running number of programs
  173:  *
  174:  * @prg = program pool
  175:  * @toNum = vacuum to number of programs (0 to init number)
  176:  * return: 0 error or >0 closed programs
  177:  */
  178: int io_progVacuum(prog_t * __restrict prg, u_int toNum);
  179: /*
  180:  * io_progClose() - Close all programs in pool
  181:  *
  182:  * @prg = program pool
  183:  * @closeNum = close program(s) (0 all)
  184:  * return: 0 error, >0 closed programs
  185:  */
  186: int io_progClose(prog_t * __restrict prg, unsigned int closeNum);
  187: /*
  188:  * io_progDestroy() - Destroy entire program pool
  189:  *
  190:  * @pprg = program pool
  191:  * return: none
  192:  */
  193: void io_progDestroy(prog_t ** __restrict pprg);
  194: 
  195: 
  196: /*
  197:  * ioInitSocket() - Init socket and allocate resources
  198:  *
  199:  * @role = Socket role
  200:  * @type = Socket type
  201:  * @proto = Socket protocol
  202:  * @addr = Bind to address
  203:  * @port = Bind to port
  204:  * @buflen = Socket buffer, optional if =0 == BUFSIZ
  205:  * return: NULL error or !=NULL created socket
  206:  */
  207: sock_t *ioInitSocket(int role, int type, int proto, 
  208: 		const char *addr, unsigned short port, size_t buflen);
  209: /*
  210:  * ioCloseSocket() - Close socket and free resources
  211:  *
  212:  * @s = Socket
  213:  * return: none
  214:  */
  215: void ioCloseSocket(sock_t ** __restrict s);
  216: #define ioKillSocket(x)		(assert((x)), (x)->sock_kill = 1)
  217: /*
  218:  * ioCloseClient() - Close client socket
  219:  *
  220:  * @c = Client socket
  221:  * return: 0 ok or !=0 error
  222:  */
  223: int ioCloseClient(sock_cli_t * __restrict c);
  224: /*
  225:  * ioUpSocket() - Setup socket for use
  226:  *
  227:  * @s = Socket
  228:  * @arg = Server role = listen backlog queue and Client role = peer address
  229:  * @timeout = Socket timeout in ms (default -1 infinit)
  230:  * return: -1 error or 0 ok
  231:  */
  232: int ioUpSocket(sock_t * __restrict s, void *arg, int timeout);
  233: /*
  234:  * ioUpdTimerSocket() - Update timeout of socket
  235:  *
  236:  * @c = Client socket
  237:  * return:  none
  238:  */
  239: void ioUpdTimerSocket(sock_cli_t * __restrict c);
  240: /*
  241:  * ioLoopSocket() - Start socket scheduler
  242:  *
  243:  * @s = Socket
  244:  * @rcb = Read callback
  245:  * return: -1 error or return result from scheduler
  246:  */
  247: int ioLoopSocket(sock_t * __restrict s, sched_task_func_t rcb);
  248: /*
  249:  * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket
  250:  *
  251:  * @s = Socket
  252:  * @prgname = Program name
  253:  * return: 0 ok or !=0 error
  254:  */
  255: int ioBridgeProg2Socket(sock_t * __restrict s, const char *prgname);
  256: 
  257: 
  258: /*
  259:  * ioPromptRead() - Read data from input h[0] with prompt to output h[1]
  260:  *
  261:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
  262:  * @csPrompt = Prompt before input, may be NULL
  263:  * @psData = Readed data
  264:  * @dataLen = Length of data
  265:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
  266: */
  267: int ioPromptRead(int *h, const char *csPrompt, 
  268: 		char * __restrict psData, int dataLen);
  269: /*
  270:  * ioPromptPassword() - Read password from input h[0] with prompt to output h[1]
  271:  *
  272:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
  273:  * @csPrompt = Prompt before input, may be NULL
  274:  * @psPass = Readed password
  275:  * @passLen = Length of password
  276:  * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
  277:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
  278: */
  279: int ioPromptPassword(int *h, const char *csPrompt, 
  280: 		char * __restrict psPass, int passLen, int confirm);
  281: 
  282: 
  283: /*
  284:  * ioMkDir() - Function for racursive directory creation and validation
  285:  *
  286:  * @csDir = Full directory path
  287:  * @mode = Mode for directory creation if missing dir
  288:  * return: -1 error, 0 directory path exist, >0 created missing dirs
  289: */
  290: int ioMkDir(const char *csDir, int mode);
  291: 
  292: /*
  293:  * ioWatchDirLoop() - Function for watching changes in directory and fire callback
  294:  *
  295:  * @csDir = Full directory path
  296:  * @callback = Callback if raise event! nOp -1 delete, 0 change/move, 1 create
  297:  * return: -1 error, !=-1 ok, number of total signaled events
  298: */
  299: int ioWatchDirLoop(const char *csDir, int (*callback)(const char *csName, int nOp));
  300: 
  301: 
  302: #ifdef AIO_OPS
  303: /*
  304:  * io_aiobulk() - AIO bulk R/W function
  305:  *
  306:  * @mode = Bulk wait mode
  307:  * @acbs = List of aiocb structures
  308:  * @nacb = Number of aiocb in list
  309:  * @sig = Event for completed operations, may be =NULL
  310:  * return: -1 error or 0 ok
  311:  */
  312: int io_aiobulk(int mode, struct aiocb ** __restrict acbs, int nacb, 
  313: 		struct sigevent *sig);
  314: #endif
  315: /*
  316:  * io_rreadv() - Raw VFS bulk read function
  317:  *
  318:  * @fd = File handle
  319:  * @bufs = Read buffers
  320:  * @nbufs = Number of read buffers
  321:  * @offset = Read from position, if -1 read nbytes from current position
  322:  * @update = Update file handle position !0
  323:  * return: -1 error or !=-1 readed bytes
  324:  */
  325: int io_rreadv(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset, 
  326: 		int update);
  327: /*
  328:  * io_rwritev() - Raw VFS bulk write function
  329:  *
  330:  * @fd = File handle
  331:  * @bufs = Write buffers
  332:  * @nbufs = Number of write buffers
  333:  * @offset = Write to position, if -1 write nbytes to current position
  334:  * @update = Update file handle position !0
  335:  * return: -1 error or !=-1 written bytes
  336:  */
  337: int io_rwritev(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset, 
  338: 		int update);
  339: /*
  340:  * io_rread() - Raw VFS read function
  341:  *
  342:  * @fd = File handle
  343:  * @buf = Read buffer
  344:  * @nbytes = Read buffer size
  345:  * @offset = Read from position, if -1 read nbytes from current position
  346:  * @update = Update file handle position !0
  347:  * return: -1 error or !=-1 readed bytes
  348:  */
  349: int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, 
  350: 		int update);
  351: /*
  352:  * io_rwrite() - Raw VFS write function
  353:  *
  354:  * @fd = File handle
  355:  * @buf = Write buffer
  356:  * @nbytes = Write bytes from buffer
  357:  * @offset = Write at position, if -1 write nbytes from current position
  358:  * @update = Update file handle position !0
  359:  * return: -1 error or !=-1 written bytes
  360:  */
  361: int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, 
  362: 		int update);
  363: 
  364: /* Disk I/O helper macros */
  365: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
  366: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
  367: 
  368: 
  369: /* Crypto framework */
  370: 
  371: /*
  372:  * ioCipher() - Cipher wrapper for all supported crypto algorythms
  373:  *
  374:  * @pInput = input buffer
  375:  * @inLen = input buffer len
  376:  * @ppOutput = output allocated buffe, must be e_free after use
  377:  * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
  378:  * @pKey = key
  379:  * @pIV = IV, salt (8 bytes)
  380:  * @nMode = Mode 0 - decrypting or 1 - encrypting
  381:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
  382: */
  383: int ioCipher(unsigned char *pInput, int inLen, unsigned char **ppOutput, const EVP_CIPHER *Cipher, 
  384: 		unsigned char *pKey, unsigned char *pIV, int nMode);
  385: 
  386: /*
  387:  * io_Blowfish() - Blowfish cipher algorythm, work with ASCII hex strings
  388:  *
  389:  * @pInput = input buffer
  390:  * @inLen = input buffer len
  391:  * @ppOutput = output allocated buffe, must be e_free after use
  392:  * @pKey = key
  393:  * @pIV = IV, salt (8 bytes)
  394:  * @nMode = Mode 0 - decrypting or 1 - encrypting
  395:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
  396: */
  397: int io_Blowfish(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
  398: 		unsigned char *pKey, unsigned char *pIV, int nMode);
  399: /*
  400:  * io_ctr_AES() - Encrypt/Decrypt stream cipher CTR_AES
  401:  *
  402:  * @pInput = Input buffer with ASCII
  403:  * @inLen = Input buffer data length
  404:  * @ppOutput = Output buffer with cipher data, must be e_free after use
  405:  * @pKey = Key
  406:  * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!
  407:  * return: -1 error or >-1 how many cipher blocks proceeded
  408:  */
  409: int io_ctr_AES(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
  410: 		unsigned char *pKey, unsigned char IV[AES_BLOCK_SIZE]);
  411: 
  412: 
  413: /*
  414:  * ioAllocPTY() - Allocate new PTY and TTY
  415:  *
  416:  * @ptyfd = master fd, pty
  417:  * @ttyfd = slave fd, tty
  418:  * @name = tty device name if not null
  419:  * @namesiz = name length, must be above 63 bytes.
  420:  * @term = termios for terminal
  421:  * @winz = winsize for terminal
  422:  * return: -1 error or 0 ok
  423:  */
  424: int ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz, 
  425: 		struct termios * __restrict term, struct winsize * __restrict winz);
  426: /*
  427:  * ioFreePTY() - Release PTY and TTY device
  428:  *
  429:  * @ptyfd = master fd, pty (==-1 skip closing pty)
  430:  * @ttyname = tty filename
  431:  * return: none
  432:  */
  433: void ioFreePTY(int ptyfd, const char *ttyname);
  434: /*
  435:  * ioChgWinPTY() - Change window size of PTY
  436:  *
  437:  * @ptyfd = master fd, pty
  438:  * @row = row
  439:  * @col = col
  440:  * @xpxl = x pixels
  441:  * @ypxl = y pixels
  442:  * return: -1 error or 0 ok
  443:  */
  444: int ioChgWinPTY(int ptyfd, unsigned short row, unsigned short col, 
  445: 		unsigned short xpxl, unsigned short ypxl);
  446: /*
  447:  * ioSetOwnerTTY() - Set owner to TTY
  448:  *
  449:  * @ttyname = tty filename
  450:  * @UID = uid
  451:  * @GID = gid
  452:  * return: -1 error or 0 ok
  453:  */
  454: int ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GID);
  455: /*
  456:  * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes.
  457:  *
  458:  * @ttyfd = slave fd, tty
  459:  * @ttyname = tty filename
  460:  * return: -1 error or 0 ok
  461:  */
  462: int ioSetSidTTY(int *ttyfd, const char *ttyname);
  463: /*
  464:  * ioSetRAWMode() - Enter into RAW mode
  465:  *
  466:  * @fd = tty fd
  467:  * @otio = saved old termios for later restore if !=NULL
  468:  * return: -1 error or 0 ok
  469:  */
  470: int ioSetRAWMode(int fd, struct termios *otio);
  471: /*
  472:  * ioRestoreMode() - Restore termios to tty fd
  473:  *
  474:  * @fd = tty fd
  475:  * @tio = termios structure for restore
  476:  * return: -1 error or 0 ok
  477:  */
  478: int ioRestoreMode(int fd, struct termios tio);
  479: /*
  480:  * ioForkPTY() - Fork new process with session leader and new TTY
  481:  *
  482:  * @ptyfd = master fd, pty
  483:  * @name = tty device name if not null
  484:  * @namesiz = name length, must be above 63 bytes.
  485:  * @term = termios for terminal
  486:  * @winz = winsize for terminal
  487:  * @otio = old termios structure for restore
  488:  * return: -1 error, 0 child process or >0 parent: pid of child
  489:  */
  490: pid_t ioForkPTY(int *ptyfd, char * __restrict name, int namesiz, struct termios * __restrict term, 
  491: 		struct winsize * __restrict winz, struct termios * __restrict otio);
  492: 
  493: /*
  494:  * ioCreatePIDFile() - Create PID file
  495:  *
  496:  * @csName = PID filename
  497:  * @ifExists = !=0 if filename exists return error
  498:  * return: -1 error or 0 ok
  499:  */
  500: int ioCreatePIDFile(const char *csName, int ifExists);
  501: 
  502: /*
  503:  * ioSendFile() - AITNET sendfile() userland implementation, not dependant from OS
  504:  *
  505:  * @s = socket
  506:  * @csFile = file for send
  507:  * @sendLen = bytes to send, if 0 send all data
  508:  * @offset = start file offset
  509:  * @sndbuf = SO_SNDBUF value, if 0 use default
  510:  * return: 0 error, >0 ok, sended bytes
  511:  */
  512: size_t ioSendFile(int s, const char *csFile, size_t sendLen, off_t offset, int sndbuf);
  513: /*
  514:  * ioRecvFile() - Receive file from socket, fastest (zero-copy) way
  515:  *
  516:  * @s = socket
  517:  * @csFile = file for receive
  518:  * @recvLen = receive bytes
  519:  * @over = overwrite file if exists with mode like 0644
  520:  * @rcvbuf = SO_RCVBUF value, if 0 use default
  521:  * return: 0 error, >0 ok, received bytes
  522:  */
  523: size_t ioRecvFile(int s, const char *csFile, size_t recvLen, int over, int rcvbuf);
  524: 
  525: /*
  526:  * ioRealFileName() - Get real file name
  527:  *
  528:  * @fname = filename
  529:  * return: =NULL error or !=NULL real filename, should be free with e_free()
  530:  */
  531: char *ioRealFileName(const char *fname);
  532: 
  533: /* Buffered file access over memory block */
  534: 
  535: /*
  536:  * io_fmemopen() - File buffered stream operations over memory block
  537:  *
  538:  * @base = Base address of memory block, if =NULL Infinit length(auto-grow)
  539:  * @basesize = Size of memory block
  540:  * return: NULL error or !=NULL Opened file resource
  541:  */
  542: FILE *io_fmemopen(void ** __restrict base, off_t basesize);
  543: /*
  544:  * io_fmapopen() - File buffered stream operations over MMAP block
  545:  *
  546:  * @csFile = Filename for MMAP, if =NULL private MMAP block
  547:  * @mode = File open mode
  548:  * @perm = If file not exists will be created with this access permissions
  549:  * @prot = MMAP protection
  550:  * @flags = MMAP mode flags
  551:  * @offset = Map from file offset, if csFile==NULL then this is size of MMAP private block
  552:  * return: NULL error or !=NULL Opened file resource
  553:  */
  554: FILE *io_fmapopen(const char *csFile, int mode, int perm, int prot, int flags, off_t offset);
  555: /*
  556:  * io_fd2buf() - Convert open file handle to buffered file I/O
  557:  *
  558:  * @fd = File handle
  559:  * @mode = Permissions for new buffered file I/O
  560:  * return: NULL error or open buffered file
  561:  */
  562: FILE *io_fd2buf(int fd, const char *mode);
  563: /*
  564:  * io_dumbFile() - Create empry or dumb file with fixed size
  565:  *
  566:  * @csFile = Filename for create
  567:  * @mode = File access permissions
  568:  * @size = File size
  569:  * return: -1 error or open file handle
  570:  */
  571: int io_dumbFile(const char *csFile, int mode, off_t size);
  572: 
  573: 
  574: /*
  575:  * io_get1stiface() - Get first interface of host
  576:  *
  577:  * @szIface = interface string buffer
  578:  * @iflen = size of interface buffer
  579:  * return: -1 error or 0 ok
  580:  */
  581: int io_get1stiface(char *szIface, int iflen);
  582: /*
  583:  * io_getmaciface() - Get MAC address from interface name
  584:  *
  585:  * @csIface = interface name
  586:  * @ea = ethernet address
  587:  * return: -1 error, 0 ok or 1 not found
  588:  */
  589: int io_getmaciface(const char *csIface, ether_addr_t * __restrict ea);
  590: /*
  591:  * io_etherOpen() - Open BPF interface to device
  592:  *
  593:  * @csIface = interface name
  594:  * @flags = open flags
  595:  * @whdr = with complete headers
  596:  * @wdlt = with data link type
  597:  * @buflen = buffer length
  598:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
  599:  * return: -1 error or >-1 bpf handle
  600:  */
  601: int io_etherOpen(const char *csIface, int flags, int whdr, int wdlt, 
  602: 		unsigned int *buflen, void **zcbuf);
  603: /*
  604:  * io_etherClose() - Close BPF interface
  605:  *
  606:  * @eth = bpf handle
  607:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
  608:  * return: none
  609:  */
  610: void io_etherClose(int eth, void **zcbuf);
  611: 
  612: /*
  613:  * io_etherFilter() - BPF filter routine
  614:  *
  615:  * @eth = bpf handle
  616:  * @io = filter direction 
  617:  *  (IO_ETHER_FILTER_PROMISC|IO_ETHER_FILTER_NOTREAD|IO_ETHER_FILTER_READ|IO_ETHER_FILTER_WRITE)
  618:  * @insn = BPF filter instruction array
  619:  * @insnlen = Length of BPF filter instruction array
  620:  * return: -1 error or 0 ok
  621:  */
  622: int io_etherFilter(int eth, int io, struct bpf_insn * __restrict insn, size_t insnlen);
  623: 
  624: /*
  625:  * io_etherSend() - Send packet to bpf
  626:  *
  627:  * @eth = bpf handle
  628:  * @buf = buffer
  629:  * @buflen = buffer length
  630:  * return: -1 error or !=-1 written bytes
  631:  */
  632: ssize_t io_etherSend(int eth, const void *buf, size_t buflen);
  633: /*
  634:  * io_etherRecv() - Receive packet from bpf
  635:  *
  636:  * @eth = bpf handle
  637:  * @buf = buffer
  638:  * @buflen = buffer length
  639:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
  640:  * return: -1 error or !=-1 readed bytes
  641:  */
  642: ssize_t io_etherRecv(int eth, void * __restrict buf, 
  643: 		size_t buflen, void * __restrict zcbuf);
  644: 
  645: 
  646: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>