Annotation of libaitio/inc/aitio.h, revision 1.36.2.6

1.1       misho       1: /*************************************************************************
1.8       misho       2: * (C) 2010 AITNET ltd - Sofia/Bulgaria - <misho@aitnet.org>
                      3: *  by Michael Pounov <misho@elwix.org>
1.1       misho       4: *
                      5: * $Author: misho $
1.36.2.6! misho       6: * $Id: aitio.h,v 1.36.2.5 2013/11/21 18:26:40 misho Exp $
1.1       misho       7: *
1.8       misho       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: 
1.29      misho      15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
1.8       misho      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: */
1.1       misho      46: #ifndef __AITIO_H
                     47: #define __AITIO_H
                     48: 
                     49: 
1.12      misho      50: #define COMPAT_43TTY
                     51: 
1.8       misho      52: #include <assert.h>
1.24      misho      53: #include <syslog.h>
1.7       misho      54: #include <openssl/evp.h>
1.12      misho      55: #include <openssl/aes.h>
                     56: #include <sys/tty.h>
                     57: #include <sys/ioctl_compat.h>
1.13      misho      58: #include <sys/socket.h>
                     59: #include <sys/un.h>
1.24      misho      60: #include <sys/uio.h>
1.13      misho      61: #include <net/if_dl.h>
1.33      misho      62: #include <net/bpf.h>
1.13      misho      63: #include <netinet/in.h>
1.34      misho      64: #include <elwix.h>
1.36.2.1  misho      65: #include <aitsched.h>
1.7       misho      66: 
                     67: 
1.21      misho      68: #ifndef STRSIZ
1.34      misho      69: #define STRSIZ                 256
1.21      misho      70: #endif
                     71: 
1.34      misho      72: #define IO_SOCK_ROLE_CLIENT    0
                     73: #define IO_SOCK_ROLE_SERVER    1
                     74: 
1.36      misho      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: 
1.34      misho      80: 
1.35      misho      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];
1.36.2.6! misho      89:        char                            cli_cmdline[PATH_MAX];
1.35      misho      90: 
1.36.2.2  misho      91:        sched_task_func_t               cli_func;
1.35      misho      92: 
1.36.2.5  misho      93:        ait_val_t                       cli_buf[2];
1.35      misho      94: 
                     95:        TAILQ_ENTRY(tagCliSock)         cli_node;
                     96: };
1.36.2.2  misho      97: 
1.34      misho      98: typedef struct {
1.35      misho      99:        int                             sock_role;
                    100:        int                             sock_backq;
                    101:        int                             sock_type;
                    102:        int                             sock_proto;
                    103:        int                             sock_fd;
1.36.2.1  misho     104:        struct timespec                 sock_timeout;
1.35      misho     105:        sockaddr_t                      sock_addr;
                    106:        sockaddr_t                      sock_peer;
1.34      misho     107: 
1.35      misho     108:        ait_val_t                       sock_buf;
1.34      misho     109: 
1.36.2.1  misho     110:        volatile intptr_t               sock_kill;
                    111:        sched_root_task_t               *sock_root;
                    112: 
1.35      misho     113:        pthread_mutex_t                 sock_mtx;
                    114:        TAILQ_HEAD(, tagCliSock)        sock_cli;
1.34      misho     115: } sock_t;
                    116: 
1.15      misho     117: 
1.1       misho     118: // io_GetErrno() Get error code of last operation
1.30      misho     119: int io_GetErrno();
1.1       misho     120: // io_GetError() Get error text of last operation
1.30      misho     121: const char *io_GetError();
1.1       misho     122: 
                    123: 
1.12      misho     124: /*
1.34      misho     125:  * ioInitSocket() - Init socket and allocate resources
                    126:  *
                    127:  * @role = Socket role
                    128:  * @type = Socket type
                    129:  * @proto = Socket protocol
                    130:  * @addr = Bind to address
                    131:  * @port = Bind to port
                    132:  * @buflen = Socket buffer, optional if =0 == BUFSIZ
                    133:  * return: NULL error or !=NULL created socket
                    134:  */
                    135: sock_t *ioInitSocket(int role, int type, int proto, 
                    136:                const char *addr, unsigned short port, size_t buflen);
                    137: /*
                    138:  * ioCloseSocket() - Close socket and free resources
                    139:  *
                    140:  * @s = Socket
                    141:  * return: none
                    142:  */
                    143: void ioCloseSocket(sock_t ** __restrict s);
1.36.2.4  misho     144: #define ioKillSocket(x)                (assert((x)), (x)->sock_kill = 1)
                    145: /*
                    146:  * ioCloseClient() - Close client socket
                    147:  *
                    148:  * @c = Client socket
                    149:  * return: 0 ok or !=0 error
                    150:  */
                    151: int ioCloseClient(sock_cli_t * __restrict c);
1.34      misho     152: /*
                    153:  * ioUpSocket() - Setup socket for use
                    154:  *
                    155:  * @s = Socket
                    156:  * @arg = Server role = listen backlog queue and Client role = peer address
1.36.2.1  misho     157:  * @timeout = Socket timeout in ms (default -1 infinit)
1.34      misho     158:  * return: -1 error or 0 ok
                    159:  */
1.36.2.1  misho     160: int ioUpSocket(sock_t * __restrict s, void *arg, int timeout);
                    161: /*
1.36.2.2  misho     162:  * ioUpdTimerSocket() - Update timeout of socket
                    163:  *
                    164:  * @c = Client socket
                    165:  * return:  none
                    166:  */
                    167: void ioUpdTimerSocket(sock_cli_t * __restrict c);
                    168: /*
1.36.2.1  misho     169:  * ioLoopSocket() - Start socket scheduler
                    170:  *
                    171:  * @s = Socket
1.36.2.2  misho     172:  * @rcb = Read callback
1.36.2.1  misho     173:  * return: -1 error or return result from scheduler
                    174:  */
1.36.2.2  misho     175: int ioLoopSocket(sock_t * __restrict s, sched_task_func_t rcb);
1.36.2.6! misho     176: /*
        !           177:  * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket
        !           178:  *
        !           179:  * @s = Socket
        !           180:  * @prgname = Program name
        !           181:  * return: 0 ok or !=0 error
        !           182:  */
        !           183: int ioBridgeProg2Socket(sock_t * __restrict s, const char *prgname);
1.34      misho     184: 
                    185: /*
1.17      misho     186:  * ioPromptRead() - Read data from input h[0] with prompt to output h[1]
1.16      misho     187:  *
1.1       misho     188:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
                    189:  * @csPrompt = Prompt before input, may be NULL
                    190:  * @psData = Readed data
                    191:  * @dataLen = Length of data
                    192:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
                    193: */
1.36.2.6! misho     194: int ioPromptRead(int *h, const char *csPrompt, 
        !           195:                char * __restrict psData, int dataLen);
1.1       misho     196: /*
1.17      misho     197:  * ioPromptPassword() - Read password from input h[0] with prompt to output h[1]
1.16      misho     198:  *
1.1       misho     199:  * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
                    200:  * @csPrompt = Prompt before input, may be NULL
                    201:  * @psPass = Readed password
                    202:  * @passLen = Length of password
                    203:  * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
                    204:  * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
                    205: */
1.36.2.6! misho     206: int ioPromptPassword(int *h, const char *csPrompt, 
        !           207:                char * __restrict psPass, int passLen, int confirm);
1.1       misho     208: 
1.10      misho     209: 
                    210: /*
1.17      misho     211:  * ioMkDir() - Function for racursive directory creation and validation
1.16      misho     212:  *
1.5       misho     213:  * @csDir = Full directory path
                    214:  * @mode = Mode for directory creation if missing dir
                    215:  * return: -1 error, 0 directory path exist, >0 created missing dirs
                    216: */
                    217: int ioMkDir(const char *csDir, int mode);
                    218: 
1.6       misho     219: /*
1.17      misho     220:  * ioWatchDirLoop() - Function for watching changes in directory and fire callback
1.16      misho     221:  *
1.6       misho     222:  * @csDir = Full directory path
                    223:  * @callback = Callback if raise event! nOp -1 delete, 0 change/move, 1 create
                    224:  * return: -1 error, !=-1 ok, number of total signaled events
                    225: */
                    226: int ioWatchDirLoop(const char *csDir, int (*callback)(const char *csName, int nOp));
                    227: 
1.5       misho     228: 
1.24      misho     229: #ifdef AIO_OPS
                    230: /*
                    231:  * io_aiobulk() - AIO bulk R/W function
                    232:  *
                    233:  * @mode = Bulk wait mode
                    234:  * @acbs = List of aiocb structures
                    235:  * @nacb = Number of aiocb in list
                    236:  * @sig = Event for completed operations, may be =NULL
                    237:  * return: -1 error or 0 ok
                    238:  */
1.30      misho     239: int io_aiobulk(int mode, struct aiocb ** __restrict acbs, int nacb, 
1.24      misho     240:                struct sigevent *sig);
                    241: #endif
                    242: /*
                    243:  * io_rreadv() - Raw VFS bulk read function
                    244:  *
                    245:  * @fd = File handle
                    246:  * @bufs = Read buffers
                    247:  * @nbufs = Number of read buffers
                    248:  * @offset = Read from position, if -1 read nbytes from current position
                    249:  * @update = Update file handle position !0
                    250:  * return: -1 error or !=-1 readed bytes
                    251:  */
                    252: int io_rreadv(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset, 
                    253:                int update);
                    254: /*
                    255:  * io_rwritev() - Raw VFS bulk write function
                    256:  *
                    257:  * @fd = File handle
                    258:  * @bufs = Write buffers
                    259:  * @nbufs = Number of write buffers
                    260:  * @offset = Write to position, if -1 write nbytes to current position
                    261:  * @update = Update file handle position !0
                    262:  * return: -1 error or !=-1 written bytes
                    263:  */
                    264: int io_rwritev(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset, 
                    265:                int update);
1.5       misho     266: /*
1.17      misho     267:  * io_rread() - Raw VFS read function
1.16      misho     268:  *
1.5       misho     269:  * @fd = File handle
                    270:  * @buf = Read buffer
                    271:  * @nbytes = Read buffer size
                    272:  * @offset = Read from position, if -1 read nbytes from current position
                    273:  * @update = Update file handle position !0
                    274:  * return: -1 error or !=-1 readed bytes
                    275:  */
1.30      misho     276: int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, 
1.24      misho     277:                int update);
1.5       misho     278: /*
1.17      misho     279:  * io_rwrite() - Raw VFS write function
1.16      misho     280:  *
1.5       misho     281:  * @fd = File handle
                    282:  * @buf = Write buffer
                    283:  * @nbytes = Write bytes from buffer
                    284:  * @offset = Write at position, if -1 write nbytes from current position
                    285:  * @update = Update file handle position !0
1.24      misho     286:  * return: -1 error or !=-1 written bytes
1.5       misho     287:  */
1.30      misho     288: int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, 
1.24      misho     289:                int update);
1.5       misho     290: 
                    291: /* Disk I/O helper macros */
                    292: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
                    293: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
                    294: 
                    295: 
1.7       misho     296: /* Crypto framework */
                    297: 
                    298: /*
1.17      misho     299:  * ioCipher() - Cipher wrapper for all supported crypto algorythms
1.16      misho     300:  *
1.7       misho     301:  * @pInput = input buffer
                    302:  * @inLen = input buffer len
1.29      misho     303:  * @ppOutput = output allocated buffe, must be e_free after use
1.7       misho     304:  * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
                    305:  * @pKey = key
                    306:  * @pIV = IV, salt (8 bytes)
                    307:  * @nMode = Mode 0 - decrypting or 1 - encrypting
                    308:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
                    309: */
                    310: int ioCipher(unsigned char *pInput, int inLen, unsigned char **ppOutput, const EVP_CIPHER *Cipher, 
                    311:                unsigned char *pKey, unsigned char *pIV, int nMode);
                    312: 
                    313: /*
1.17      misho     314:  * io_Blowfish() - Blowfish cipher algorythm, work with ASCII hex strings
1.16      misho     315:  *
1.7       misho     316:  * @pInput = input buffer
                    317:  * @inLen = input buffer len
1.29      misho     318:  * @ppOutput = output allocated buffe, must be e_free after use
1.7       misho     319:  * @pKey = key
                    320:  * @pIV = IV, salt (8 bytes)
                    321:  * @nMode = Mode 0 - decrypting or 1 - encrypting
                    322:  * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
                    323: */
1.8       misho     324: int io_Blowfish(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
                    325:                unsigned char *pKey, unsigned char *pIV, int nMode);
1.12      misho     326: /*
1.17      misho     327:  * io_ctr_AES() - Encrypt/Decrypt stream cipher CTR_AES
1.16      misho     328:  *
1.12      misho     329:  * @pInput = Input buffer with ASCII
                    330:  * @inLen = Input buffer data length
1.29      misho     331:  * @ppOutput = Output buffer with cipher data, must be e_free after use
1.12      misho     332:  * @pKey = Key
                    333:  * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!
                    334:  * return: -1 error or >-1 how many cipher blocks proceeded
                    335:  */
                    336: int io_ctr_AES(unsigned char *pInput, int inLen, unsigned char **ppOutput, 
                    337:                unsigned char *pKey, unsigned char IV[AES_BLOCK_SIZE]);
                    338: 
                    339: 
                    340: /*
1.17      misho     341:  * ioAllocPTY() - Allocate new PTY and TTY
1.16      misho     342:  *
1.12      misho     343:  * @ptyfd = master fd, pty
                    344:  * @ttyfd = slave fd, tty
                    345:  * @name = tty device name if not null
                    346:  * @namesiz = name length, must be above 63 bytes.
                    347:  * @term = termios for terminal
                    348:  * @winz = winsize for terminal
                    349:  * return: -1 error or 0 ok
                    350:  */
1.30      misho     351: int ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz, 
1.12      misho     352:                struct termios * __restrict term, struct winsize * __restrict winz);
                    353: /*
1.17      misho     354:  * ioFreePTY() - Release PTY and TTY device
1.16      misho     355:  *
1.12      misho     356:  * @ptyfd = master fd, pty (==-1 skip closing pty)
                    357:  * @ttyname = tty filename
                    358:  * return: none
                    359:  */
1.30      misho     360: void ioFreePTY(int ptyfd, const char *ttyname);
1.12      misho     361: /*
1.17      misho     362:  * ioChgWinPTY() - Change window size of PTY
1.16      misho     363:  *
1.12      misho     364:  * @ptyfd = master fd, pty
                    365:  * @row = row
                    366:  * @col = col
                    367:  * @xpxl = x pixels
                    368:  * @ypxl = y pixels
                    369:  * return: -1 error or 0 ok
                    370:  */
1.30      misho     371: int ioChgWinPTY(int ptyfd, unsigned short row, unsigned short col, 
1.12      misho     372:                unsigned short xpxl, unsigned short ypxl);
                    373: /*
1.17      misho     374:  * ioSetOwnerTTY() - Set owner to TTY
1.16      misho     375:  *
1.12      misho     376:  * @ttyname = tty filename
                    377:  * @UID = uid
                    378:  * @GID = gid
                    379:  * return: -1 error or 0 ok
                    380:  */
                    381: int ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GID);
                    382: /*
1.17      misho     383:  * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes.
1.16      misho     384:  *
1.12      misho     385:  * @ttyfd = slave fd, tty
                    386:  * @ttyname = tty filename
                    387:  * return: -1 error or 0 ok
                    388:  */
                    389: int ioSetSidTTY(int *ttyfd, const char *ttyname);
                    390: /*
1.17      misho     391:  * ioSetRAWMode() - Enter into RAW mode
1.16      misho     392:  *
1.12      misho     393:  * @fd = tty fd
                    394:  * @otio = saved old termios for later restore if !=NULL
                    395:  * return: -1 error or 0 ok
                    396:  */
1.30      misho     397: int ioSetRAWMode(int fd, struct termios *otio);
1.12      misho     398: /*
1.17      misho     399:  * ioRestoreMode() - Restore termios to tty fd
1.16      misho     400:  *
1.12      misho     401:  * @fd = tty fd
                    402:  * @tio = termios structure for restore
                    403:  * return: -1 error or 0 ok
                    404:  */
1.30      misho     405: int ioRestoreMode(int fd, struct termios tio);
1.12      misho     406: /*
1.17      misho     407:  * ioForkPTY() - Fork new process with session leader and new TTY
1.16      misho     408:  *
1.12      misho     409:  * @ptyfd = master fd, pty
                    410:  * @name = tty device name if not null
                    411:  * @namesiz = name length, must be above 63 bytes.
                    412:  * @term = termios for terminal
                    413:  * @winz = winsize for terminal
                    414:  * @otio = old termios structure for restore
                    415:  * return: -1 error, 0 child process or >0 parent: pid of child
                    416:  */
                    417: pid_t ioForkPTY(int *ptyfd, char * __restrict name, int namesiz, struct termios * __restrict term, 
                    418:                struct winsize * __restrict winz, struct termios * __restrict otio);
                    419: 
                    420: /*
1.17      misho     421:  * ioCreatePIDFile() - Create PID file
1.16      misho     422:  *
1.12      misho     423:  * @csName = PID filename
                    424:  * @ifExists = !=0 if filename exists return error
                    425:  * return: -1 error or 0 ok
                    426:  */
1.30      misho     427: int ioCreatePIDFile(const char *csName, int ifExists);
1.7       misho     428: 
1.13      misho     429: /*
1.17      misho     430:  * ioSendFile() - AITNET sendfile() userland implementation, not dependant from OS
1.16      misho     431:  *
1.13      misho     432:  * @s = socket
                    433:  * @csFile = file for send
                    434:  * @sendLen = bytes to send, if 0 send all data
                    435:  * @offset = start file offset
                    436:  * @sndbuf = SO_SNDBUF value, if 0 use default
                    437:  * return: 0 error, >0 ok, sended bytes
                    438:  */
                    439: size_t ioSendFile(int s, const char *csFile, size_t sendLen, off_t offset, int sndbuf);
                    440: /*
1.17      misho     441:  * ioRecvFile() - Receive file from socket, fastest (zero-copy) way
1.16      misho     442:  *
1.13      misho     443:  * @s = socket
                    444:  * @csFile = file for receive
                    445:  * @recvLen = receive bytes
                    446:  * @over = overwrite file if exists with mode like 0644
                    447:  * @rcvbuf = SO_RCVBUF value, if 0 use default
                    448:  * return: 0 error, >0 ok, received bytes
                    449:  */
                    450: size_t ioRecvFile(int s, const char *csFile, size_t recvLen, int over, int rcvbuf);
                    451: 
1.31      misho     452: /*
                    453:  * ioRealFileName() - Get real file name
                    454:  *
                    455:  * @fname = filename
                    456:  * return: =NULL error or !=NULL real filename, should be free with e_free()
                    457:  */
                    458: char *ioRealFileName(const char *fname);
1.7       misho     459: 
1.14      misho     460: /* Buffered file access over memory block */
                    461: 
                    462: /*
1.17      misho     463:  * io_fmemopen() - File buffered stream operations over memory block
1.14      misho     464:  *
                    465:  * @base = Base address of memory block, if =NULL Infinit length(auto-grow)
                    466:  * @basesize = Size of memory block
                    467:  * return: NULL error or !=NULL Opened file resource
                    468:  */
                    469: FILE *io_fmemopen(void ** __restrict base, off_t basesize);
                    470: /*
1.17      misho     471:  * io_fmapopen() - File buffered stream operations over MMAP block
1.14      misho     472:  *
                    473:  * @csFile = Filename for MMAP, if =NULL private MMAP block
                    474:  * @mode = File open mode
                    475:  * @perm = If file not exists will be created with this access permissions
                    476:  * @prot = MMAP protection
                    477:  * @flags = MMAP mode flags
                    478:  * @offset = Map from file offset, if csFile==NULL then this is size of MMAP private block
                    479:  * return: NULL error or !=NULL Opened file resource
                    480:  */
                    481: FILE *io_fmapopen(const char *csFile, int mode, int perm, int prot, int flags, off_t offset);
                    482: /*
1.17      misho     483:  * io_fd2buf() - Convert open file handle to buffered file I/O
1.14      misho     484:  *
                    485:  * @fd = File handle
                    486:  * @mode = Permissions for new buffered file I/O
                    487:  * return: NULL error or open buffered file
                    488:  */
1.30      misho     489: FILE *io_fd2buf(int fd, const char *mode);
1.14      misho     490: /*
1.17      misho     491:  * io_dumbFile() - Create empry or dumb file with fixed size
1.14      misho     492:  *
                    493:  * @csFile = Filename for create
                    494:  * @mode = File access permissions
                    495:  * @size = File size
                    496:  * return: -1 error or open file handle
                    497:  */
                    498: int io_dumbFile(const char *csFile, int mode, off_t size);
                    499: 
                    500: 
1.32      misho     501: /*
                    502:  * io_get1stiface() - Get first interface of host
                    503:  *
                    504:  * @szIface = interface string buffer
                    505:  * @iflen = size of interface buffer
                    506:  * return: -1 error or 0 ok
                    507:  */
                    508: int io_get1stiface(char *szIface, int iflen);
                    509: /*
                    510:  * io_etherOpen() - Open BPF interface to device
                    511:  *
                    512:  * @csIface = interface name
                    513:  * @flags = open flags
                    514:  * @whdr = with complete headers
1.33      misho     515:  * @wdlt = with data link type
1.32      misho     516:  * @buflen = buffer length
                    517:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
                    518:  * return: -1 error or >-1 bpf handle
                    519:  */
1.33      misho     520: int io_etherOpen(const char *csIface, int flags, int whdr, int wdlt, 
1.32      misho     521:                unsigned int *buflen, void **zcbuf);
                    522: /*
                    523:  * io_etherClose() - Close BPF interface
                    524:  *
                    525:  * @eth = bpf handle
                    526:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
                    527:  * return: none
                    528:  */
                    529: void io_etherClose(int eth, void **zcbuf);
                    530: 
                    531: /*
1.36      misho     532:  * io_etherFilter() - BPF filter routine
                    533:  *
                    534:  * @eth = bpf handle
                    535:  * @io = filter direction 
                    536:  *  (IO_ETHER_FILTER_PROMISC|IO_ETHER_FILTER_NOTREAD|IO_ETHER_FILTER_READ|IO_ETHER_FILTER_WRITE)
                    537:  * @insn = BPF filter instruction array
                    538:  * @insnlen = Length of BPF filter instruction array
                    539:  * return: -1 error or 0 ok
                    540:  */
                    541: int io_etherFilter(int eth, int io, struct bpf_insn * __restrict insn, size_t insnlen);
                    542: 
                    543: /*
1.32      misho     544:  * io_etherSend() - Send packet to bpf
                    545:  *
                    546:  * @eth = bpf handle
                    547:  * @buf = buffer
                    548:  * @buflen = buffer length
                    549:  * return: -1 error or !=-1 written bytes
                    550:  */
                    551: ssize_t io_etherSend(int eth, const void *buf, size_t buflen);
                    552: /*
                    553:  * io_etherRecv() - Receive packet from bpf
                    554:  *
                    555:  * @eth = bpf handle
                    556:  * @buf = buffer
                    557:  * @buflen = buffer length
                    558:  * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
                    559:  * return: -1 error or !=-1 readed bytes
                    560:  */
                    561: ssize_t io_etherRecv(int eth, void * __restrict buf, 
                    562:                size_t buflen, void * __restrict zcbuf);
                    563: 
                    564: 
1.1       misho     565: #endif

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