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

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

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