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