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