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

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

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