1*b6a54c62Smartin /* $NetBSD: prog_ops.h,v 1.5 2020/04/03 16:20:52 martin Exp $ */ 216456bb8Spooka 316456bb8Spooka /* 416456bb8Spooka * Copyright (c) 2010 The NetBSD Foundation, Inc. 516456bb8Spooka * All rights reserved. 616456bb8Spooka * 716456bb8Spooka * Redistribution and use in source and binary forms, with or without 816456bb8Spooka * modification, are permitted provided that the following conditions 916456bb8Spooka * are met: 1016456bb8Spooka * 1. Redistributions of source code must retain the above copyright 1116456bb8Spooka * notice, this list of conditions and the following disclaimer. 1216456bb8Spooka * 2. Redistributions in binary form must reproduce the above copyright 1316456bb8Spooka * notice, this list of conditions and the following disclaimer in the 1416456bb8Spooka * documentation and/or other materials provided with the distribution. 1516456bb8Spooka * 1616456bb8Spooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1716456bb8Spooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1816456bb8Spooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1916456bb8Spooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2016456bb8Spooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2116456bb8Spooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2216456bb8Spooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2316456bb8Spooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2416456bb8Spooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2516456bb8Spooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2616456bb8Spooka * POSSIBILITY OF SUCH DAMAGE. 2716456bb8Spooka */ 2816456bb8Spooka 2916456bb8Spooka #ifndef _PROG_OPS_H_ 3016456bb8Spooka #define _PROG_OPS_H_ 3116456bb8Spooka 3216456bb8Spooka #include <sys/types.h> 33*b6a54c62Smartin #include <sys/sysctl.h> 3416456bb8Spooka 35a1a6b89aSpooka #ifndef CRUNCHOPS 36*b6a54c62Smartin /* 37*b6a54c62Smartin * This is shared between netstat and route (as they share some code) 38*b6a54c62Smartin */ 39*b6a54c62Smartin struct sysctlnode; 4016456bb8Spooka struct prog_ops { 4116456bb8Spooka int (*op_init)(void); 4216456bb8Spooka 4316456bb8Spooka int (*op_socket)(int, int, int); 446a4ffbc8Schristos int (*op_setsockopt)(int, int, int, const void *, socklen_t); 456a4ffbc8Schristos 466a4ffbc8Schristos 4716456bb8Spooka int (*op_open)(const char *, int, ...); 4816456bb8Spooka pid_t (*op_getpid)(void); 4916456bb8Spooka 5016456bb8Spooka ssize_t (*op_read)(int, void *, size_t); 5116456bb8Spooka ssize_t (*op_write)(int, const void *, size_t); 5216456bb8Spooka 53*b6a54c62Smartin int (*op_shutdown)(int, int); 54*b6a54c62Smartin 556a4ffbc8Schristos int (*op_sysctl)(const int *, u_int, void *, size_t *, 566a4ffbc8Schristos const void *, size_t); 5716456bb8Spooka 58*b6a54c62Smartin int (*op_sysctlbyname)(const char *, void *, size_t *, 59*b6a54c62Smartin const void *, size_t); 60*b6a54c62Smartin 61*b6a54c62Smartin int (*op_sysctlgetmibinfo)(const char *, int *, u_int *, 62*b6a54c62Smartin char *, size_t *, struct sysctlnode **, int); 63*b6a54c62Smartin 64*b6a54c62Smartin int (*op_sysctlnametomib)(const char *, int *, size_t *); 6516456bb8Spooka }; 6616456bb8Spooka extern const struct prog_ops prog_ops; 6716456bb8Spooka 6816456bb8Spooka #define prog_init prog_ops.op_init 696a4ffbc8Schristos 7016456bb8Spooka #define prog_socket prog_ops.op_socket 716a4ffbc8Schristos #define prog_setsockopt prog_ops.op_setsockopt 726a4ffbc8Schristos 7316456bb8Spooka #define prog_open prog_ops.op_open 7416456bb8Spooka #define prog_getpid prog_ops.op_getpid 756a4ffbc8Schristos 7616456bb8Spooka #define prog_read prog_ops.op_read 7716456bb8Spooka #define prog_write prog_ops.op_write 786a4ffbc8Schristos 79*b6a54c62Smartin #define prog_shutdown prog_ops.op_shutdown 80*b6a54c62Smartin 8116456bb8Spooka #define prog_sysctl prog_ops.op_sysctl 826a4ffbc8Schristos 83*b6a54c62Smartin #define prog_sysctlbyname prog_ops.op_sysctlbyname 84*b6a54c62Smartin #define prog_sysctlgetmibinfo prog_ops.op_sysctlgetmibinfo 85*b6a54c62Smartin #define prog_sysctlnametomib prog_ops.op_sysctlnametomib 866a4ffbc8Schristos 87a1a6b89aSpooka #else 88a1a6b89aSpooka #define prog_init ((int (*)(void))NULL) 896a4ffbc8Schristos 90a1a6b89aSpooka #define prog_socket socket 916a4ffbc8Schristos #define prog_setsockopt setsockopt 926a4ffbc8Schristos 93a1a6b89aSpooka #define prog_open open 94a1a6b89aSpooka #define prog_getpid getpid 956a4ffbc8Schristos 96a1a6b89aSpooka #define prog_read read 97a1a6b89aSpooka #define prog_write write 986a4ffbc8Schristos 99a1a6b89aSpooka #define prog_shutdown shutdown 100*b6a54c62Smartin 101*b6a54c62Smartin #define prog_sysctl sysctl 102*b6a54c62Smartin #define prog_sysctlbyname sysctlbyname 103*b6a54c62Smartin #define prog_sysctlgetmibinfo sysctlgetmibinfo 104*b6a54c62Smartin #define prog_sysctlnametomib sysctlnametomib 105*b6a54c62Smartin 106a1a6b89aSpooka #endif 10716456bb8Spooka 10816456bb8Spooka #endif /* _PROG_OPS_H_ */ 109