xref: /netbsd-src/usr.sbin/arp/prog_ops.h (revision 222abc89f82a4cc92d71a59d51738578dee7fa92)
1*222abc89Sroy /*      $NetBSD: prog_ops.h,v 1.3 2020/09/11 15:28:29 roy Exp $	*/
2fe289628Sozaki-r 
3fe289628Sozaki-r /*
4fe289628Sozaki-r  * Copyright (c) 2015 The NetBSD Foundation, Inc.
5fe289628Sozaki-r  * All rights reserved.
6fe289628Sozaki-r  *
7fe289628Sozaki-r  * Redistribution and use in source and binary forms, with or without
8fe289628Sozaki-r  * modification, are permitted provided that the following conditions
9fe289628Sozaki-r  * are met:
10fe289628Sozaki-r  * 1. Redistributions of source code must retain the above copyright
11fe289628Sozaki-r  *    notice, this list of conditions and the following disclaimer.
12fe289628Sozaki-r  * 2. Redistributions in binary form must reproduce the above copyright
13fe289628Sozaki-r  *    notice, this list of conditions and the following disclaimer in the
14fe289628Sozaki-r  *    documentation and/or other materials provided with the distribution.
15fe289628Sozaki-r  *
16fe289628Sozaki-r  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17fe289628Sozaki-r  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18fe289628Sozaki-r  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19fe289628Sozaki-r  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20fe289628Sozaki-r  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21fe289628Sozaki-r  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22fe289628Sozaki-r  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23fe289628Sozaki-r  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24fe289628Sozaki-r  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25fe289628Sozaki-r  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26fe289628Sozaki-r  * POSSIBILITY OF SUCH DAMAGE.
27fe289628Sozaki-r  */
28fe289628Sozaki-r 
29fe289628Sozaki-r #ifndef _PROG_OPS_H_
30fe289628Sozaki-r #define _PROG_OPS_H_
31fe289628Sozaki-r 
32fe289628Sozaki-r #include <sys/types.h>
33fe289628Sozaki-r 
34fe289628Sozaki-r #ifndef CRUNCHOPS
35fe289628Sozaki-r /* XXX: Keep same order with netstat! */
36fe289628Sozaki-r struct prog_ops {
37fe289628Sozaki-r 	int (*op_init)(void);
38fe289628Sozaki-r 
39fe289628Sozaki-r 	int (*op_sysctl)(const int *, u_int, void *, size_t *,
40fe289628Sozaki-r 			 const void *, size_t);
41fe289628Sozaki-r 
42fe289628Sozaki-r 	int (*op_socket)(int, int, int);
43fe289628Sozaki-r 	int (*op_open)(const char *, int, ...);
44fe289628Sozaki-r 	pid_t (*op_getpid)(void);
45fe289628Sozaki-r 
46*222abc89Sroy 	int (*op_ioctl)(int, unsigned long, ...);
47fe289628Sozaki-r 	ssize_t (*op_read)(int, void *, size_t);
48fe289628Sozaki-r 	ssize_t (*op_write)(int, const void *, size_t);
492cc9171bSdholland 
502cc9171bSdholland 	int (*op_close)(int);
51fe289628Sozaki-r };
52fe289628Sozaki-r extern const struct prog_ops prog_ops;
53fe289628Sozaki-r 
54fe289628Sozaki-r #define prog_init prog_ops.op_init
55fe289628Sozaki-r #define prog_socket prog_ops.op_socket
56fe289628Sozaki-r #define prog_open prog_ops.op_open
57fe289628Sozaki-r #define prog_getpid prog_ops.op_getpid
58*222abc89Sroy #define prog_ioctl prog_ops.op_ioctl
59fe289628Sozaki-r #define prog_read prog_ops.op_read
60fe289628Sozaki-r #define prog_write prog_ops.op_write
612cc9171bSdholland #define prog_close prog_ops.op_close
62fe289628Sozaki-r #define prog_sysctl prog_ops.op_sysctl
63fe289628Sozaki-r #else
64fe289628Sozaki-r #define prog_init ((int (*)(void))NULL)
65fe289628Sozaki-r #define prog_socket socket
66fe289628Sozaki-r #define prog_open open
67fe289628Sozaki-r #define prog_getpid getpid
68*222abc89Sroy #define prog_ioctl ioctl
69fe289628Sozaki-r #define prog_read read
70fe289628Sozaki-r #define prog_write write
712cc9171bSdholland #define prog_close close
72fe289628Sozaki-r #define prog_sysctl sysctl
73fe289628Sozaki-r #endif
74fe289628Sozaki-r 
75fe289628Sozaki-r #endif /* _PROG_OPS_H_ */
76