Annotation of libaitio/inc/aitio.h, revision 1.38.10.6
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.6! misho 6: * $Id: aitio.h,v 1.38.10.5 2013/12/05 15:56:10 misho Exp $
1.1 misho 7: *
1.8 misho 8: **************************************************************************
9: The ELWIX and AITNET software is distributed under the following
10: terms:
11:
12: All of the documentation and software included in the ELWIX and AITNET
13: Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
14:
1.29 misho 15: Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
1.8 misho 16: by Michael Pounov <misho@elwix.org>. All rights reserved.
17:
18: Redistribution and use in source and binary forms, with or without
19: modification, are permitted provided that the following conditions
20: are met:
21: 1. Redistributions of source code must retain the above copyright
22: notice, this list of conditions and the following disclaimer.
23: 2. Redistributions in binary form must reproduce the above copyright
24: notice, this list of conditions and the following disclaimer in the
25: documentation and/or other materials provided with the distribution.
26: 3. All advertising materials mentioning features or use of this software
27: must display the following acknowledgement:
28: This product includes software developed by Michael Pounov <misho@elwix.org>
29: ELWIX - Embedded LightWeight unIX and its contributors.
30: 4. Neither the name of AITNET nor the names of its contributors
31: may be used to endorse or promote products derived from this software
32: without specific prior written permission.
33:
34: THIS SOFTWARE IS PROVIDED BY AITNET AND CONTRIBUTORS ``AS IS'' AND
35: ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36: IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37: ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38: FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39: DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40: OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42: LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43: OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44: SUCH DAMAGE.
45: */
1.1 misho 46: #ifndef __AITIO_H
47: #define __AITIO_H
48:
49:
1.12 misho 50: #define COMPAT_43TTY
51:
1.8 misho 52: #include <assert.h>
1.24 misho 53: #include <syslog.h>
1.7 misho 54: #include <openssl/evp.h>
1.12 misho 55: #include <openssl/aes.h>
56: #include <sys/tty.h>
57: #include <sys/ioctl_compat.h>
1.13 misho 58: #include <sys/socket.h>
59: #include <sys/un.h>
1.24 misho 60: #include <sys/uio.h>
1.13 misho 61: #include <net/if_dl.h>
1.33 misho 62: #include <net/bpf.h>
1.13 misho 63: #include <netinet/in.h>
1.34 misho 64: #include <elwix.h>
1.37 misho 65: #include <aitsched.h>
1.7 misho 66:
67:
1.21 misho 68: #ifndef STRSIZ
1.34 misho 69: #define STRSIZ 256
1.21 misho 70: #endif
71:
1.34 misho 72: #define IO_SOCK_ROLE_CLIENT 0
73: #define IO_SOCK_ROLE_SERVER 1
74:
1.36 misho 75: #define IO_ETHER_FILTER_PROMISC 0
76: #define IO_ETHER_FILTER_NOTREAD -1
77: #define IO_ETHER_FILTER_READ 1
78: #define IO_ETHER_FILTER_WRITE 2
79:
1.34 misho 80:
1.35 misho 81: typedef struct tagCliSock sock_cli_t;
82: typedef void *(*sock_cb_t)(sock_cli_t*);
83: struct tagCliSock {
84: void *cli_parent;
85: int cli_fd;
86: int cli_pty;
87: sockaddr_t cli_addr;
88: char cli_name[64];
1.37 misho 89: char cli_cmdline[PATH_MAX];
90: pid_t cli_pid;
1.35 misho 91:
1.37 misho 92: sched_task_func_t cli_func;
1.35 misho 93:
1.37 misho 94: ait_val_t cli_buf[2];
1.35 misho 95:
96: TAILQ_ENTRY(tagCliSock) cli_node;
97: };
1.37 misho 98:
1.34 misho 99: typedef struct {
1.35 misho 100: int sock_role;
101: int sock_backq;
102: int sock_type;
103: int sock_proto;
104: int sock_fd;
1.37 misho 105: struct timespec sock_timeout;
1.35 misho 106: sockaddr_t sock_addr;
107: sockaddr_t sock_peer;
1.34 misho 108:
1.35 misho 109: ait_val_t sock_buf;
1.34 misho 110:
1.37 misho 111: volatile intptr_t sock_kill;
112: sched_root_task_t *sock_root;
113:
1.35 misho 114: pthread_mutex_t sock_mtx;
115: TAILQ_HEAD(, tagCliSock) sock_cli;
1.34 misho 116: } sock_t;
117:
1.38.10.2 misho 118: typedef struct {
119: unsigned int prog_inin; /* init progs */
120: unsigned int prog_maxn; /* max progs */
121: unsigned int prog_cnum; /* current progs */
122: char prog_name[PATH_MAX];
123:
124: pthread_mutex_t prog_mtx;
125: array_t *prog_fds;
126: } prog_t;
127:
1.15 misho 128:
1.1 misho 129: // io_GetErrno() Get error code of last operation
1.30 misho 130: int io_GetErrno();
1.1 misho 131: // io_GetError() Get error text of last operation
1.30 misho 132: const char *io_GetError();
1.1 misho 133:
134:
1.12 misho 135: /*
1.38.10.2 misho 136: * io_progInit() - Init program pool
137: *
138: * @progName = program name for execution
139: * @initNum = initial started programs
140: * @maxNum = maximum started programs
141: * return: NULL error or !=NULL allocated pool (must destroied with io_progDestroy())
142: */
143: prog_t *io_progInit(const char *progName,
144: unsigned int initNum, unsigned int maxNum);
145: /*
146: * io_progOpen() - Execute number of program(s)
147: *
148: * @prg = program pool
149: * @execNum = execute program(s) (0 max)
150: * return: 0 error, >0 executed programs and abs(<0) executed programs with logged error
151: */
152: int io_progOpen(prog_t * __restrict prg, unsigned int execNum);
153: /*
1.38.10.6! misho 154: * io_progGrow() - Execute to number of programs in pool
! 155: *
! 156: * @prg = program pool
! 157: * @toNum = execute to number of programs (0 max)
! 158: * return: 0 error, >0 executed programs and abs(<0) executed programs with logged error
! 159: */
! 160: int io_progGrow(prog_t * __restrict prg, unsigned int toNum);
! 161: /*
1.38.10.2 misho 162: * io_progVacuum() - Vacuum pool to running number of programs
163: *
164: * @prg = program pool
165: * @toNum = vacuum to number of programs (0 to init number)
166: * return: 0 error or >0 closed programs
167: */
1.38.10.6! misho 168: int io_progVacuum(prog_t * __restrict prg, unsigned int toNum);
1.38.10.2 misho 169: /*
170: * io_progClose() - Close all programs in pool
171: *
172: * @prg = program pool
173: * @closeNum = close program(s) (0 all)
174: * return: 0 error, >0 closed programs
175: */
176: int io_progClose(prog_t * __restrict prg, unsigned int closeNum);
177: /*
178: * io_progDestroy() - Destroy entire program pool
179: *
180: * @pprg = program pool
181: * return: none
182: */
183: void io_progDestroy(prog_t ** __restrict pprg);
184:
1.38.10.5 misho 185: /*
186: * io_progCheck() - Check exit status of program pool
187: *
188: * @prg = program pool
189: * return: -1 error or >-1 exited programs
190: */
191: int io_progCheck(prog_t * __restrict prg);
192:
1.38.10.2 misho 193:
194: /*
1.34 misho 195: * ioInitSocket() - Init socket and allocate resources
196: *
197: * @role = Socket role
198: * @type = Socket type
199: * @proto = Socket protocol
200: * @addr = Bind to address
201: * @port = Bind to port
202: * @buflen = Socket buffer, optional if =0 == BUFSIZ
203: * return: NULL error or !=NULL created socket
204: */
205: sock_t *ioInitSocket(int role, int type, int proto,
206: const char *addr, unsigned short port, size_t buflen);
207: /*
208: * ioCloseSocket() - Close socket and free resources
209: *
210: * @s = Socket
211: * return: none
212: */
213: void ioCloseSocket(sock_t ** __restrict s);
1.37 misho 214: #define ioKillSocket(x) (assert((x)), (x)->sock_kill = 1)
215: /*
216: * ioCloseClient() - Close client socket
217: *
218: * @c = Client socket
219: * return: 0 ok or !=0 error
220: */
221: int ioCloseClient(sock_cli_t * __restrict c);
1.34 misho 222: /*
223: * ioUpSocket() - Setup socket for use
224: *
225: * @s = Socket
226: * @arg = Server role = listen backlog queue and Client role = peer address
1.37 misho 227: * @timeout = Socket timeout in ms (default -1 infinit)
1.34 misho 228: * return: -1 error or 0 ok
229: */
1.37 misho 230: int ioUpSocket(sock_t * __restrict s, void *arg, int timeout);
1.35 misho 231: /*
1.37 misho 232: * ioUpdTimerSocket() - Update timeout of socket
233: *
234: * @c = Client socket
235: * return: none
236: */
1.38 misho 237: void ioUpdTimerSocket(sock_cli_t * __restrict c);
1.37 misho 238: /*
239: * ioLoopSocket() - Start socket scheduler
240: *
241: * @s = Socket
242: * @rcb = Read callback
243: * return: -1 error or return result from scheduler
244: */
245: int ioLoopSocket(sock_t * __restrict s, sched_task_func_t rcb);
246: /*
247: * ioBridgeProg2Socket() - Start socket scheduler and bridge program to socket
1.35 misho 248: *
249: * @s = Socket
1.37 misho 250: * @prgname = Program name
251: * return: 0 ok or !=0 error
1.35 misho 252: */
1.37 misho 253: int ioBridgeProg2Socket(sock_t * __restrict s, const char *prgname);
1.34 misho 254:
1.38.10.2 misho 255:
1.34 misho 256: /*
1.17 misho 257: * ioPromptRead() - Read data from input h[0] with prompt to output h[1]
1.16 misho 258: *
1.1 misho 259: * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
260: * @csPrompt = Prompt before input, may be NULL
261: * @psData = Readed data
262: * @dataLen = Length of data
263: * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
264: */
1.37 misho 265: int ioPromptRead(int *h, const char *csPrompt,
266: char * __restrict psData, int dataLen);
1.1 misho 267: /*
1.17 misho 268: * ioPromptPassword() - Read password from input h[0] with prompt to output h[1]
1.16 misho 269: *
1.1 misho 270: * @h = file handles h[0] = input, h[1] = output, if NULL use stdin, stdout
271: * @csPrompt = Prompt before input, may be NULL
272: * @psPass = Readed password
273: * @passLen = Length of password
274: * @confirm = Confirm password, 0 - get password, !=0 Ask for confirmation
275: * return: 0 EOF; -1 error:: can`t read; >0 count of readed chars
276: */
1.37 misho 277: int ioPromptPassword(int *h, const char *csPrompt,
278: char * __restrict psPass, int passLen, int confirm);
1.1 misho 279:
1.10 misho 280:
281: /*
1.17 misho 282: * ioMkDir() - Function for racursive directory creation and validation
1.16 misho 283: *
1.5 misho 284: * @csDir = Full directory path
285: * @mode = Mode for directory creation if missing dir
286: * return: -1 error, 0 directory path exist, >0 created missing dirs
287: */
288: int ioMkDir(const char *csDir, int mode);
289:
1.6 misho 290: /*
1.17 misho 291: * ioWatchDirLoop() - Function for watching changes in directory and fire callback
1.16 misho 292: *
1.6 misho 293: * @csDir = Full directory path
294: * @callback = Callback if raise event! nOp -1 delete, 0 change/move, 1 create
295: * return: -1 error, !=-1 ok, number of total signaled events
296: */
297: int ioWatchDirLoop(const char *csDir, int (*callback)(const char *csName, int nOp));
298:
1.5 misho 299:
1.24 misho 300: #ifdef AIO_OPS
301: /*
302: * io_aiobulk() - AIO bulk R/W function
303: *
304: * @mode = Bulk wait mode
305: * @acbs = List of aiocb structures
306: * @nacb = Number of aiocb in list
307: * @sig = Event for completed operations, may be =NULL
308: * return: -1 error or 0 ok
309: */
1.30 misho 310: int io_aiobulk(int mode, struct aiocb ** __restrict acbs, int nacb,
1.24 misho 311: struct sigevent *sig);
312: #endif
313: /*
314: * io_rreadv() - Raw VFS bulk read function
315: *
316: * @fd = File handle
317: * @bufs = Read buffers
318: * @nbufs = Number of read buffers
319: * @offset = Read from position, if -1 read nbytes from current position
320: * @update = Update file handle position !0
321: * return: -1 error or !=-1 readed bytes
322: */
323: int io_rreadv(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset,
324: int update);
325: /*
326: * io_rwritev() - Raw VFS bulk write function
327: *
328: * @fd = File handle
329: * @bufs = Write buffers
330: * @nbufs = Number of write buffers
331: * @offset = Write to position, if -1 write nbytes to current position
332: * @update = Update file handle position !0
333: * return: -1 error or !=-1 written bytes
334: */
335: int io_rwritev(int fd, struct iovec * __restrict bufs, int nbufs, off_t offset,
336: int update);
1.5 misho 337: /*
1.17 misho 338: * io_rread() - Raw VFS read function
1.16 misho 339: *
1.5 misho 340: * @fd = File handle
341: * @buf = Read buffer
342: * @nbytes = Read buffer size
343: * @offset = Read from position, if -1 read nbytes from current position
344: * @update = Update file handle position !0
345: * return: -1 error or !=-1 readed bytes
346: */
1.30 misho 347: int io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset,
1.24 misho 348: int update);
1.5 misho 349: /*
1.17 misho 350: * io_rwrite() - Raw VFS write function
1.16 misho 351: *
1.5 misho 352: * @fd = File handle
353: * @buf = Write buffer
354: * @nbytes = Write bytes from buffer
355: * @offset = Write at position, if -1 write nbytes from current position
356: * @update = Update file handle position !0
1.24 misho 357: * return: -1 error or !=-1 written bytes
1.5 misho 358: */
1.30 misho 359: int io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset,
1.24 misho 360: int update);
1.5 misho 361:
362: /* Disk I/O helper macros */
363: #define io_read(f, b, n) io_rread(f, b, n, -1, 1)
364: #define io_write(f, b, n) io_rwrite(f, b, n, -1, 1)
365:
366:
1.7 misho 367: /* Crypto framework */
368:
369: /*
1.17 misho 370: * ioCipher() - Cipher wrapper for all supported crypto algorythms
1.16 misho 371: *
1.7 misho 372: * @pInput = input buffer
373: * @inLen = input buffer len
1.29 misho 374: * @ppOutput = output allocated buffe, must be e_free after use
1.7 misho 375: * @Cipher = cipher engine, like EVP_bf_cbc() or etc...
376: * @pKey = key
377: * @pIV = IV, salt (8 bytes)
378: * @nMode = Mode 0 - decrypting or 1 - encrypting
379: * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
380: */
381: int ioCipher(unsigned char *pInput, int inLen, unsigned char **ppOutput, const EVP_CIPHER *Cipher,
382: unsigned char *pKey, unsigned char *pIV, int nMode);
383:
384: /*
1.17 misho 385: * io_Blowfish() - Blowfish cipher algorythm, work with ASCII hex strings
1.16 misho 386: *
1.7 misho 387: * @pInput = input buffer
388: * @inLen = input buffer len
1.29 misho 389: * @ppOutput = output allocated buffe, must be e_free after use
1.7 misho 390: * @pKey = key
391: * @pIV = IV, salt (8 bytes)
392: * @nMode = Mode 0 - decrypting or 1 - encrypting
393: * return: 0 not present data or error!; >0 number of processed and returned bytes into ppOutput
394: */
1.8 misho 395: int io_Blowfish(unsigned char *pInput, int inLen, unsigned char **ppOutput,
396: unsigned char *pKey, unsigned char *pIV, int nMode);
1.12 misho 397: /*
1.17 misho 398: * io_ctr_AES() - Encrypt/Decrypt stream cipher CTR_AES
1.16 misho 399: *
1.12 misho 400: * @pInput = Input buffer with ASCII
401: * @inLen = Input buffer data length
1.29 misho 402: * @ppOutput = Output buffer with cipher data, must be e_free after use
1.12 misho 403: * @pKey = Key
404: * @IV = IVector/Nonce/Counter, Warning: IV must be variable, because we write there!!!
405: * return: -1 error or >-1 how many cipher blocks proceeded
406: */
407: int io_ctr_AES(unsigned char *pInput, int inLen, unsigned char **ppOutput,
408: unsigned char *pKey, unsigned char IV[AES_BLOCK_SIZE]);
409:
410:
411: /*
1.17 misho 412: * ioAllocPTY() - Allocate new PTY and TTY
1.16 misho 413: *
1.12 misho 414: * @ptyfd = master fd, pty
415: * @ttyfd = slave fd, tty
416: * @name = tty device name if not null
417: * @namesiz = name length, must be above 63 bytes.
418: * @term = termios for terminal
419: * @winz = winsize for terminal
420: * return: -1 error or 0 ok
421: */
1.30 misho 422: int ioAllocPTY(int *ptyfd, int *ttyfd, char * __restrict name, int namesiz,
1.12 misho 423: struct termios * __restrict term, struct winsize * __restrict winz);
424: /*
1.17 misho 425: * ioFreePTY() - Release PTY and TTY device
1.16 misho 426: *
1.12 misho 427: * @ptyfd = master fd, pty (==-1 skip closing pty)
428: * @ttyname = tty filename
429: * return: none
430: */
1.30 misho 431: void ioFreePTY(int ptyfd, const char *ttyname);
1.12 misho 432: /*
1.17 misho 433: * ioChgWinPTY() - Change window size of PTY
1.16 misho 434: *
1.12 misho 435: * @ptyfd = master fd, pty
436: * @row = row
437: * @col = col
438: * @xpxl = x pixels
439: * @ypxl = y pixels
440: * return: -1 error or 0 ok
441: */
1.30 misho 442: int ioChgWinPTY(int ptyfd, unsigned short row, unsigned short col,
1.12 misho 443: unsigned short xpxl, unsigned short ypxl);
444: /*
1.17 misho 445: * ioSetOwnerTTY() - Set owner to TTY
1.16 misho 446: *
1.12 misho 447: * @ttyname = tty filename
448: * @UID = uid
449: * @GID = gid
450: * return: -1 error or 0 ok
451: */
452: int ioSetOwnerTTY(const char *ttyname, uid_t UID, gid_t GID);
453: /*
1.17 misho 454: * ioSetSidTTY() - Makes the process's controlling TTY and sets it to sane modes.
1.16 misho 455: *
1.12 misho 456: * @ttyfd = slave fd, tty
457: * @ttyname = tty filename
458: * return: -1 error or 0 ok
459: */
460: int ioSetSidTTY(int *ttyfd, const char *ttyname);
461: /*
1.17 misho 462: * ioSetRAWMode() - Enter into RAW mode
1.16 misho 463: *
1.12 misho 464: * @fd = tty fd
465: * @otio = saved old termios for later restore if !=NULL
466: * return: -1 error or 0 ok
467: */
1.30 misho 468: int ioSetRAWMode(int fd, struct termios *otio);
1.12 misho 469: /*
1.17 misho 470: * ioRestoreMode() - Restore termios to tty fd
1.16 misho 471: *
1.12 misho 472: * @fd = tty fd
473: * @tio = termios structure for restore
474: * return: -1 error or 0 ok
475: */
1.30 misho 476: int ioRestoreMode(int fd, struct termios tio);
1.12 misho 477: /*
1.17 misho 478: * ioForkPTY() - Fork new process with session leader and new TTY
1.16 misho 479: *
1.12 misho 480: * @ptyfd = master fd, pty
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: * @otio = old termios structure for restore
486: * return: -1 error, 0 child process or >0 parent: pid of child
487: */
488: pid_t ioForkPTY(int *ptyfd, char * __restrict name, int namesiz, struct termios * __restrict term,
489: struct winsize * __restrict winz, struct termios * __restrict otio);
490:
491: /*
1.17 misho 492: * ioCreatePIDFile() - Create PID file
1.16 misho 493: *
1.12 misho 494: * @csName = PID filename
495: * @ifExists = !=0 if filename exists return error
496: * return: -1 error or 0 ok
497: */
1.30 misho 498: int ioCreatePIDFile(const char *csName, int ifExists);
1.7 misho 499:
1.13 misho 500: /*
1.17 misho 501: * ioSendFile() - AITNET sendfile() userland implementation, not dependant from OS
1.16 misho 502: *
1.13 misho 503: * @s = socket
504: * @csFile = file for send
505: * @sendLen = bytes to send, if 0 send all data
506: * @offset = start file offset
507: * @sndbuf = SO_SNDBUF value, if 0 use default
508: * return: 0 error, >0 ok, sended bytes
509: */
510: size_t ioSendFile(int s, const char *csFile, size_t sendLen, off_t offset, int sndbuf);
511: /*
1.17 misho 512: * ioRecvFile() - Receive file from socket, fastest (zero-copy) way
1.16 misho 513: *
1.13 misho 514: * @s = socket
515: * @csFile = file for receive
516: * @recvLen = receive bytes
517: * @over = overwrite file if exists with mode like 0644
518: * @rcvbuf = SO_RCVBUF value, if 0 use default
519: * return: 0 error, >0 ok, received bytes
520: */
521: size_t ioRecvFile(int s, const char *csFile, size_t recvLen, int over, int rcvbuf);
522:
1.31 misho 523: /*
524: * ioRealFileName() - Get real file name
525: *
526: * @fname = filename
527: * return: =NULL error or !=NULL real filename, should be free with e_free()
528: */
529: char *ioRealFileName(const char *fname);
1.7 misho 530:
1.14 misho 531: /* Buffered file access over memory block */
532:
533: /*
1.17 misho 534: * io_fmemopen() - File buffered stream operations over memory block
1.14 misho 535: *
536: * @base = Base address of memory block, if =NULL Infinit length(auto-grow)
537: * @basesize = Size of memory block
538: * return: NULL error or !=NULL Opened file resource
539: */
540: FILE *io_fmemopen(void ** __restrict base, off_t basesize);
541: /*
1.17 misho 542: * io_fmapopen() - File buffered stream operations over MMAP block
1.14 misho 543: *
544: * @csFile = Filename for MMAP, if =NULL private MMAP block
545: * @mode = File open mode
546: * @perm = If file not exists will be created with this access permissions
547: * @prot = MMAP protection
548: * @flags = MMAP mode flags
549: * @offset = Map from file offset, if csFile==NULL then this is size of MMAP private block
550: * return: NULL error or !=NULL Opened file resource
551: */
552: FILE *io_fmapopen(const char *csFile, int mode, int perm, int prot, int flags, off_t offset);
553: /*
1.17 misho 554: * io_fd2buf() - Convert open file handle to buffered file I/O
1.14 misho 555: *
556: * @fd = File handle
557: * @mode = Permissions for new buffered file I/O
558: * return: NULL error or open buffered file
559: */
1.30 misho 560: FILE *io_fd2buf(int fd, const char *mode);
1.14 misho 561: /*
1.17 misho 562: * io_dumbFile() - Create empry or dumb file with fixed size
1.14 misho 563: *
564: * @csFile = Filename for create
565: * @mode = File access permissions
566: * @size = File size
567: * return: -1 error or open file handle
568: */
569: int io_dumbFile(const char *csFile, int mode, off_t size);
570:
571:
1.32 misho 572: /*
573: * io_get1stiface() - Get first interface of host
574: *
575: * @szIface = interface string buffer
576: * @iflen = size of interface buffer
577: * return: -1 error or 0 ok
578: */
579: int io_get1stiface(char *szIface, int iflen);
580: /*
1.38.10.1 misho 581: * io_getmaciface() - Get MAC address from interface name
582: *
583: * @csIface = interface name
584: * @ea = ethernet address
585: * return: -1 error, 0 ok or 1 not found
586: */
587: int io_getmaciface(const char *csIface, ether_addr_t * __restrict ea);
588: /*
1.32 misho 589: * io_etherOpen() - Open BPF interface to device
590: *
591: * @csIface = interface name
592: * @flags = open flags
593: * @whdr = with complete headers
1.33 misho 594: * @wdlt = with data link type
1.32 misho 595: * @buflen = buffer length
596: * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
597: * return: -1 error or >-1 bpf handle
598: */
1.33 misho 599: int io_etherOpen(const char *csIface, int flags, int whdr, int wdlt,
1.32 misho 600: unsigned int *buflen, void **zcbuf);
601: /*
602: * io_etherClose() - Close BPF interface
603: *
604: * @eth = bpf handle
605: * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
606: * return: none
607: */
608: void io_etherClose(int eth, void **zcbuf);
609:
610: /*
1.36 misho 611: * io_etherFilter() - BPF filter routine
612: *
613: * @eth = bpf handle
614: * @io = filter direction
615: * (IO_ETHER_FILTER_PROMISC|IO_ETHER_FILTER_NOTREAD|IO_ETHER_FILTER_READ|IO_ETHER_FILTER_WRITE)
616: * @insn = BPF filter instruction array
617: * @insnlen = Length of BPF filter instruction array
618: * return: -1 error or 0 ok
619: */
620: int io_etherFilter(int eth, int io, struct bpf_insn * __restrict insn, size_t insnlen);
621:
622: /*
1.32 misho 623: * io_etherSend() - Send packet to bpf
624: *
625: * @eth = bpf handle
626: * @buf = buffer
627: * @buflen = buffer length
628: * return: -1 error or !=-1 written bytes
629: */
630: ssize_t io_etherSend(int eth, const void *buf, size_t buflen);
631: /*
632: * io_etherRecv() - Receive packet from bpf
633: *
634: * @eth = bpf handle
635: * @buf = buffer
636: * @buflen = buffer length
637: * @zcbuf = zero copy buffer, if BPF supports it and isn't NULL
638: * return: -1 error or !=-1 readed bytes
639: */
640: ssize_t io_etherRecv(int eth, void * __restrict buf,
641: size_t buflen, void * __restrict zcbuf);
642:
643:
1.1 misho 644: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>