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

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

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