File:  [ELWIX - Embedded LightWeight unIX -] / libaitio / inc / aitio.h
Revision 1.38.10.9: download - view: text, annotated - select for diffs - revision graph
Sun Dec 8 20:43:22 2013 UTC (10 years, 7 months ago) by misho
Branches: io6_7
Diff to: branchpoint 1.38: preferred, unified
new api add

    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.9 2013/12/08 20:43:22 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: 	unsigned int			*prog_used;
  127: } prog_t;
  128: 
  129: 
  130: // io_GetErrno() Get error code of last operation
  131: int io_GetErrno();
  132: // io_GetError() Get error text of last operation
  133: const char *io_GetError();
  134: 
  135: 
  136: /*
  137:  * io_progInit() - Init program pool
  138:  *
  139:  * @progName = program name for execution
  140:  * @initNum = initial started programs
  141:  * @maxNum = maximum started programs
  142:  * return: NULL error or !=NULL allocated pool (must destroied with io_progDestroy())
  143:  */
  144: prog_t *io_progInit(const char *progName, 
  145: 		unsigned int initNum, unsigned int maxNum);
  146: /*
  147:  * io_progOpen() - Execute number of program(s)
  148:  *
  149:  * @prg = program pool
  150:  * @execNum = execute program(s) (0 max)
  151:  * return: 0 error, >0 executed programs and abs(<0) executed programs with logged error
  152:  */
  153: int io_progOpen(prog_t * __restrict prg, unsigned int execNum);
  154: /*
  155:  * io_progGrow() - Execute to number of programs in pool
  156:  *
  157:  * @prg = program pool
  158:  * @toNum = execute to number of programs (0 max)
  159:  * return: 0 error, >0 executed programs and abs(<0) executed programs with logged error
  160:  */
  161: int io_progGrow(prog_t * __restrict prg, unsigned int toNum);
  162: /*
  163:  * io_progVacuum() - Vacuum pool to running number of programs
  164:  *
  165:  * @prg = program pool
  166:  * @toNum = vacuum to number of programs (0 to init number)
  167:  * return: 0 error or >0 closed programs
  168:  */
  169: int io_progVacuum(prog_t * __restrict prg, unsigned int toNum);
  170: /*
  171:  * io_progCloseAt() - Close program at pool of certain position
  172:  *
  173:  * @prg = program pool
  174:  * @idx = index at pool
  175:  * return: 0 error or !=0 closed program
  176:  */
  177: int io_progCloseAt(prog_t * __restrict prg, unsigned int idx);
  178: /*
  179:  * io_progClose() - Close all programs in pool
  180:  *
  181:  * @prg = program pool
  182:  * @closeNum = close program(s) (0 all)
  183:  * return: 0 error, >0 closed programs
  184:  */
  185: int io_progClose(prog_t * __restrict prg, unsigned int closeNum);
  186: /*
  187:  * io_progDestroy() - Destroy entire program pool
  188:  *
  189:  * @pprg = program pool
  190:  * return: none
  191:  */
  192: void io_progDestroy(prog_t ** __restrict pprg);
  193: 
  194: /*
  195:  * io_progCheck() - Check exit status of program pool
  196:  *
  197:  * @prg = program pool
  198:  * return: -1 error or >-1 exited programs
  199:  */
  200: int io_progCheck(prog_t * __restrict prg);
  201: 
  202: /*
  203:  * io_progAttach() - Attach to open program
  204:  *
  205:  * @prg = program pool
  206:  * return: NULL error or !=NULL attached program handle
  207:  */
  208: #ifdef POPEN_STREAM
  209: FILE *io_progAttach(prog_t * __restrict prg);
  210: #else
  211: int io_progAttach(prog_t * __restrict prg);
  212: #endif
  213: /*
  214:  * io_progDetach() - Detch from open program
  215:  *
  216:  * @prg= program pool
  217:  * @pfd = attached program handle
  218:  * return: none
  219:  */
  220: #ifdef POPEN_STREAM
  221: void io_progDetach(prog_t * __restrict prg, FILE *pfd);
  222: #else
  223: void io_progDetach(prog_t * __restrict prg, int pfd);
  224: #endif
  225: 
  226: 
  227: /*
  228:  * ioInitSocket() - Init socket and allocate resources
  229:  *
  230:  * @role = Socket role
  231:  * @type = Socket type
  232:  * @proto = Socket protocol
  233:  * @addr = Bind to address
  234:  * @port = Bind to port
  235:  * @buflen = Socket buffer, optional if =0 == BUFSIZ
  236:  * return: NULL error or !=NULL created socket
  237:  */
  238: sock_t *ioInitSocket(int role, int type, int proto, 
  239: 		const char *addr, unsigned short port, size_t buflen);
  240: /*
  241:  * ioCloseSocket() - Close socket and free resources
  242:  *
  243:  * @s = Socket
  244:  * return: none
  245:  */
  246: void ioCloseSocket(sock_t ** __restrict s);
  247: #define ioKillSocket(x)		(assert((x)), (x)->sock_kill = 1)
  248: /*
  249:  * ioCloseClient() - Close client socket
  250:  *
  251:  * @c = Client socket
  252:  * return: 0 ok or !=0 error
  253:  */
  254: int ioCloseClient(sock_cli_t * __restrict c);
  255: /*
  256:  * ioUpSocket() - Setup socket for use
  257:  *
  258:  * @s = Socket
  259:  * @arg = Server role = listen backlog queue and Client role = peer address
  260:  * @timeout = Socket timeout in ms (default -1 infinit)
  261:  * return: -1 error or 0 ok
  262:  */
  263: int ioUpSocket(sock_t * __restrict s, void *arg, int timeout);
  264: /*
  265:  * ioUpdTimerSocket() - Update timeout of socket
  266:  *
  267:  * @c = Client socket
  268:  * return:  none
  269:  */
  270: void ioUpdTimerSocket(sock_cli_t * __restrict c);
  271: /*
  272:  * ioLoopSocket() - Start socket scheduler
  273:  *
  274:  * @s = Socket
  275:  * @rcb = Read callback
  276:  * return: -1 error or return result from scheduler
  277:  */
  278: int ioLoopSocket(sock_t * __restrict s, sched_task_func_t rcb);
  279: /*
  280:  * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket
  281:  *
  282:  * @s = Socket
  283:  * @prgname = Program name
  284:  * return: 0 ok or !=0 error
  285:  */
  286: int ioBridgeProg2Socket(sock_t * __restrict s, const char *prgname);
  287: 
  288: 
  289: /*
  290:  * ioPromptRead() - Read data from input h[0] with prompt to output h[1]
  291:  *
  292:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
  293:  * @csPrompt = Prompt before input, may be NULL
  294:  * @psData = Readed data
  295:  * @dataLen = Length of data
  296:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
  297: */
  298: int ioPromptRead(int *h, const char *csPrompt, 
  299: 		char * __restrict psData, int dataLen);
  300: /*
  301:  * ioPromptPassword() - Read password from input h[0] with prompt to output h[1]
  302:  *
  303:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
  304:  * @csPrompt = Prompt before input, may be NULL
  305:  * @psPass = Readed password
  306:  * @passLen = Length of password
  307:  * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
  308:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
  309: */
  310: int ioPromptPassword(int *h, const char *csPrompt, 
  311: 		char * __restrict psPass, int passLen, int confirm);
  312: 
  313: 
  314: /*
  315:  * ioMkDir() - Function for racursive directory creation and validation
  316:  *
  317:  * @csDir = Full directory path
  318:  * @mode = Mode for directory creation if missing dir
  319:  * return: -1 error, 0 directory path exist, >0 created missing dirs
  320: */
  321: int ioMkDir(const char *csDir, int mode);
  322: 
  323: /*
  324:  * ioWatchDirLoop() - Function for watching changes in directory and fire callback
  325:  *
  326:  * @csDir = Full directory path
  327:  * @callback = Callback if raise event! nOp -1 delete, 0 change/move, 1 create
  328:  * return: -1 error, !=-1 ok, number of total signaled events
  329: */
  330: int ioWatchDirLoop(const char *csDir, int (*callback)(const char *csName, int nOp));
  331: 
  332: 
  333: #ifdef AIO_OPS
  334: /*
  335:  * io_aiobulk() - AIO bulk R/W function
  336:  *
  337:  * @mode = Bulk wait mode
  338:  * @acbs = List of aiocb structures
  339:  * @nacb = Number of aiocb in list
  340:  * @sig = Event for completed operations, may be =NULL
  341:  * return: -1 error or 0 ok
  342:  */
  343: int io_aiobulk(int mode, struct aiocb ** __restrict acbs, int nacb, 
  344: 		struct sigevent *sig);
  345: #endif
  346: /*
  347:  * io_rreadv() - Raw VFS bulk read function
  348:  *
  349:  * @fd = File handle
  350:  * @bufs = Read buffers
  351:  * @nbufs = Number of read buffers
  352:  * @offset = Read from position, if -1 read nbytes from current position
  353:  * @update = Update file handle position !0
  354:  * return: -1 error or !=-1 readed bytes
  355:  */
  356: int io_rreadv(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset, 
  357: 		int update);
  358: /*
  359:  * io_rwritev() - Raw VFS bulk write function
  360:  *
  361:  * @fd = File handle
  362:  * @bufs = Write buffers
  363:  * @nbufs = Number of write buffers
  364:  * @offset = Write to position, if -1 write nbytes to current position
  365:  * @update = Update file handle position !0
  366:  * return: -1 error or !=-1 written bytes
  367:  */
  368: int io_rwritev(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset, 
  369: 		int update);
  370: /*
  371:  * io_rread() - Raw VFS read function
  372:  *
  373:  * @fd = File handle
  374:  * @buf = Read buffer
  375:  * @nbytes = Read buffer size
  376:  * @offset = Read from position, if -1 read nbytes from current position
  377:  * @update = Update file handle position !0
  378:  * return: -1 error or !=-1 readed bytes
  379:  */
  380: int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, 
  381: 		int update);
  382: /*
  383:  * io_rwrite() - Raw VFS write function
  384:  *
  385:  * @fd = File handle
  386:  * @buf = Write buffer
  387:  * @nbytes = Write bytes from buffer
  388:  * @offset = Write at position, if -1 write nbytes from current position
  389:  * @update = Update file handle position !0
  390:  * return: -1 error or !=-1 written bytes
  391:  */
  392: int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, 
  393: 		int update);
  394: 
  395: /* Disk I/O helper macros */
  396: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
  397: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
  398: 
  399: 
  400: /* Crypto framework */
  401: 
  402: /*
  403:  * ioCipher() - Cipher wrapper for all supported crypto algorythms
  404:  *
  405:  * @pInput = input buffer
  406:  * @inLen = input buffer len
  407:  * @ppOutput = output allocated buffe, must be e_free after use
  408:  * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
  409:  * @pKey = key
  410:  * @pIV = IV, salt (8 bytes)
  411:  * @nMode = Mode 0 - decrypting or 1 - encrypting
  412:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
  413: */
  414: int ioCipher(unsigned char *pInput, int inLen, unsigned char **ppOutput, const EVP_CIPHER *Cipher, 
  415: 		unsigned char *pKey, unsigned char *pIV, int nMode);
  416: 
  417: /*
  418:  * io_Blowfish() - Blowfish cipher algorythm, work with ASCII hex strings
  419:  *
  420:  * @pInput = input buffer
  421:  * @inLen = input buffer len
  422:  * @ppOutput = output allocated buffe, must be e_free after use
  423:  * @pKey = key
  424:  * @pIV = IV, salt (8 bytes)
  425:  * @nMode = Mode 0 - decrypting or 1 - encrypting
  426:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
  427: */
  428: int io_Blowfish(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
  429: 		unsigned char *pKey, unsigned char *pIV, int nMode);
  430: /*
  431:  * io_ctr_AES() - Encrypt/Decrypt stream cipher CTR_AES
  432:  *
  433:  * @pInput = Input buffer with ASCII
  434:  * @inLen = Input buffer data length
  435:  * @ppOutput = Output buffer with cipher data, must be e_free after use
  436:  * @pKey = Key
  437:  * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!
  438:  * return: -1 error or >-1 how many cipher blocks proceeded
  439:  */
  440: int io_ctr_AES(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
  441: 		unsigned char *pKey, unsigned char IV[AES_BLOCK_SIZE]);
  442: 
  443: 
  444: /*
  445:  * ioAllocPTY() - Allocate new PTY and TTY
  446:  *
  447:  * @ptyfd = master fd, pty
  448:  * @ttyfd = slave fd, tty
  449:  * @name = tty device name if not null
  450:  * @namesiz = name length, must be above 63 bytes.
  451:  * @term = termios for terminal
  452:  * @winz = winsize for terminal
  453:  * return: -1 error or 0 ok
  454:  */
  455: int ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz, 
  456: 		struct termios * __restrict term, struct winsize * __restrict winz);
  457: /*
  458:  * ioFreePTY() - Release PTY and TTY device
  459:  *
  460:  * @ptyfd = master fd, pty (==-1 skip closing pty)
  461:  * @ttyname = tty filename
  462:  * return: none
  463:  */
  464: void ioFreePTY(int ptyfd, const char *ttyname);
  465: /*
  466:  * ioChgWinPTY() - Change window size of PTY
  467:  *
  468:  * @ptyfd = master fd, pty
  469:  * @row = row
  470:  * @col = col
  471:  * @xpxl = x pixels
  472:  * @ypxl = y pixels
  473:  * return: -1 error or 0 ok
  474:  */
  475: int ioChgWinPTY(int ptyfd, unsigned short row, unsigned short col, 
  476: 		unsigned short xpxl, unsigned short ypxl);
  477: /*
  478:  * ioSetOwnerTTY() - Set owner to TTY
  479:  *
  480:  * @ttyname = tty filename
  481:  * @UID = uid
  482:  * @GID = gid
  483:  * return: -1 error or 0 ok
  484:  */
  485: int ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GID);
  486: /*
  487:  * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes.
  488:  *
  489:  * @ttyfd = slave fd, tty
  490:  * @ttyname = tty filename
  491:  * return: -1 error or 0 ok
  492:  */
  493: int ioSetSidTTY(int *ttyfd, const char *ttyname);
  494: /*
  495:  * ioSetRAWMode() - Enter into RAW mode
  496:  *
  497:  * @fd = tty fd
  498:  * @otio = saved old termios for later restore if !=NULL
  499:  * return: -1 error or 0 ok
  500:  */
  501: int ioSetRAWMode(int fd, struct termios *otio);
  502: /*
  503:  * ioRestoreMode() - Restore termios to tty fd
  504:  *
  505:  * @fd = tty fd
  506:  * @tio = termios structure for restore
  507:  * return: -1 error or 0 ok
  508:  */
  509: int ioRestoreMode(int fd, struct termios tio);
  510: /*
  511:  * ioForkPTY() - Fork new process with session leader and new TTY
  512:  *
  513:  * @ptyfd = master fd, pty
  514:  * @name = tty device name if not null
  515:  * @namesiz = name length, must be above 63 bytes.
  516:  * @term = termios for terminal
  517:  * @winz = winsize for terminal
  518:  * @otio = old termios structure for restore
  519:  * return: -1 error, 0 child process or >0 parent: pid of child
  520:  */
  521: pid_t ioForkPTY(int *ptyfd, char * __restrict name, int namesiz, struct termios * __restrict term, 
  522: 		struct winsize * __restrict winz, struct termios * __restrict otio);
  523: 
  524: /*
  525:  * ioCreatePIDFile() - Create PID file
  526:  *
  527:  * @csName = PID filename
  528:  * @ifExists = !=0 if filename exists return error
  529:  * return: -1 error or 0 ok
  530:  */
  531: int ioCreatePIDFile(const char *csName, int ifExists);
  532: 
  533: /*
  534:  * ioSendFile() - AITNET sendfile() userland implementation, not dependant from OS
  535:  *
  536:  * @s = socket
  537:  * @csFile = file for send
  538:  * @sendLen = bytes to send, if 0 send all data
  539:  * @offset = start file offset
  540:  * @sndbuf = SO_SNDBUF value, if 0 use default
  541:  * return: 0 error, >0 ok, sended bytes
  542:  */
  543: size_t ioSendFile(int s, const char *csFile, size_t sendLen, off_t offset, int sndbuf);
  544: /*
  545:  * ioRecvFile() - Receive file from socket, fastest (zero-copy) way
  546:  *
  547:  * @s = socket
  548:  * @csFile = file for receive
  549:  * @recvLen = receive bytes
  550:  * @over = overwrite file if exists with mode like 0644
  551:  * @rcvbuf = SO_RCVBUF value, if 0 use default
  552:  * return: 0 error, >0 ok, received bytes
  553:  */
  554: size_t ioRecvFile(int s, const char *csFile, size_t recvLen, int over, int rcvbuf);
  555: 
  556: /*
  557:  * ioRealFileName() - Get real file name
  558:  *
  559:  * @fname = filename
  560:  * return: =NULL error or !=NULL real filename, should be free with e_free()
  561:  */
  562: char *ioRealFileName(const char *fname);
  563: 
  564: /* Buffered file access over memory block */
  565: 
  566: /*
  567:  * io_fmemopen() - File buffered stream operations over memory block
  568:  *
  569:  * @base = Base address of memory block, if =NULL Infinit length(auto-grow)
  570:  * @basesize = Size of memory block
  571:  * return: NULL error or !=NULL Opened file resource
  572:  */
  573: FILE *io_fmemopen(void ** __restrict base, off_t basesize);
  574: /*
  575:  * io_fmapopen() - File buffered stream operations over MMAP block
  576:  *
  577:  * @csFile = Filename for MMAP, if =NULL private MMAP block
  578:  * @mode = File open mode
  579:  * @perm = If file not exists will be created with this access permissions
  580:  * @prot = MMAP protection
  581:  * @flags = MMAP mode flags
  582:  * @offset = Map from file offset, if csFile==NULL then this is size of MMAP private block
  583:  * return: NULL error or !=NULL Opened file resource
  584:  */
  585: FILE *io_fmapopen(const char *csFile, int mode, int perm, int prot, int flags, off_t offset);
  586: /*
  587:  * io_fd2buf() - Convert open file handle to buffered file I/O
  588:  *
  589:  * @fd = File handle
  590:  * @mode = Permissions for new buffered file I/O
  591:  * return: NULL error or open buffered file
  592:  */
  593: FILE *io_fd2buf(int fd, const char *mode);
  594: /*
  595:  * io_dumbFile() - Create empry or dumb file with fixed size
  596:  *
  597:  * @csFile = Filename for create
  598:  * @mode = File access permissions
  599:  * @size = File size
  600:  * return: -1 error or open file handle
  601:  */
  602: int io_dumbFile(const char *csFile, int mode, off_t size);
  603: 
  604: 
  605: /*
  606:  * io_get1stiface() - Get first interface of host
  607:  *
  608:  * @szIface = interface string buffer
  609:  * @iflen = size of interface buffer
  610:  * return: -1 error or 0 ok
  611:  */
  612: int io_get1stiface(char *szIface, int iflen);
  613: /*
  614:  * io_getmaciface() - Get MAC address from interface name
  615:  *
  616:  * @csIface = interface name
  617:  * @ea = ethernet address
  618:  * return: -1 error, 0 ok or 1 not found
  619:  */
  620: int io_getmaciface(const char *csIface, ether_addr_t * __restrict ea);
  621: /*
  622:  * io_etherOpen() - Open BPF interface to device
  623:  *
  624:  * @csIface = interface name
  625:  * @flags = open flags
  626:  * @whdr = with complete headers
  627:  * @wdlt = with data link type
  628:  * @buflen = buffer length
  629:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
  630:  * return: -1 error or >-1 bpf handle
  631:  */
  632: int io_etherOpen(const char *csIface, int flags, int whdr, int wdlt, 
  633: 		unsigned int *buflen, void **zcbuf);
  634: /*
  635:  * io_etherClose() - Close BPF interface
  636:  *
  637:  * @eth = bpf handle
  638:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
  639:  * return: none
  640:  */
  641: void io_etherClose(int eth, void **zcbuf);
  642: 
  643: /*
  644:  * io_etherFilter() - BPF filter routine
  645:  *
  646:  * @eth = bpf handle
  647:  * @io = filter direction 
  648:  *  (IO_ETHER_FILTER_PROMISC|IO_ETHER_FILTER_NOTREAD|IO_ETHER_FILTER_READ|IO_ETHER_FILTER_WRITE)
  649:  * @insn = BPF filter instruction array
  650:  * @insnlen = Length of BPF filter instruction array
  651:  * return: -1 error or 0 ok
  652:  */
  653: int io_etherFilter(int eth, int io, struct bpf_insn * __restrict insn, size_t insnlen);
  654: 
  655: /*
  656:  * io_etherSend() - Send packet to bpf
  657:  *
  658:  * @eth = bpf handle
  659:  * @buf = buffer
  660:  * @buflen = buffer length
  661:  * return: -1 error or !=-1 written bytes
  662:  */
  663: ssize_t io_etherSend(int eth, const void *buf, size_t buflen);
  664: /*
  665:  * io_etherRecv() - Receive packet from bpf
  666:  *
  667:  * @eth = bpf handle
  668:  * @buf = buffer
  669:  * @buflen = buffer length
  670:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
  671:  * return: -1 error or !=-1 readed bytes
  672:  */
  673: ssize_t io_etherRecv(int eth, void * __restrict buf, 
  674: 		size_t buflen, void * __restrict zcbuf);
  675: 
  676: 
  677: #endif

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