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