1*37241896SHiroki Sato /*- 2*37241896SHiroki Sato * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org> 3*37241896SHiroki Sato * All rights reserved. 4*37241896SHiroki Sato * 5*37241896SHiroki Sato * Redistribution and use in source and binary forms, with or without 6*37241896SHiroki Sato * modification, are permitted provided that the following conditions 7*37241896SHiroki Sato * are met: 8*37241896SHiroki Sato * 1. Redistributions of source code must retain the above copyright 9*37241896SHiroki Sato * notice, this list of conditions and the following disclaimer. 10*37241896SHiroki Sato * 2. Redistributions in binary form must reproduce the above copyright 11*37241896SHiroki Sato * notice, this list of conditions and the following disclaimer in the 12*37241896SHiroki Sato * documentation and/or other materials provided with the distribution. 13*37241896SHiroki Sato * 14*37241896SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 15*37241896SHiroki Sato * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*37241896SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*37241896SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 18*37241896SHiroki Sato * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*37241896SHiroki Sato * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*37241896SHiroki Sato * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*37241896SHiroki Sato * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*37241896SHiroki Sato * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*37241896SHiroki Sato * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*37241896SHiroki Sato * SUCH DAMAGE. 25*37241896SHiroki Sato * 26*37241896SHiroki Sato * $FreeBSD$ 27*37241896SHiroki Sato * 28*37241896SHiroki Sato */ 29*37241896SHiroki Sato 30*37241896SHiroki Sato #define SOCK_BACKLOG 5 31*37241896SHiroki Sato 32*37241896SHiroki Sato #define CM_MSG_MAXLEN 8192 33*37241896SHiroki Sato #define CM_VERSION 1 34*37241896SHiroki Sato #define CM_VERSION_STR "1.0" 35*37241896SHiroki Sato 36*37241896SHiroki Sato #define CM_TYPE_EOM 0 37*37241896SHiroki Sato #define CM_TYPE_ACK 1 38*37241896SHiroki Sato #define CM_TYPE_ERR 2 39*37241896SHiroki Sato #define CM_TYPE_NUL 3 40*37241896SHiroki Sato #define CM_TYPE_REQ_SET_PROP 4 41*37241896SHiroki Sato #define CM_TYPE_REQ_GET_PROP 5 42*37241896SHiroki Sato #define CM_TYPE_MAX 6 43*37241896SHiroki Sato 44*37241896SHiroki Sato #define CM_STATE_EOM 0 45*37241896SHiroki Sato #define CM_STATE_INIT 1 46*37241896SHiroki Sato #define CM_STATE_MSG_DISPATCH 2 47*37241896SHiroki Sato #define CM_STATE_MSG_RECV 3 48*37241896SHiroki Sato #define CM_STATE_ACK_WAIT 4 49*37241896SHiroki Sato 50*37241896SHiroki Sato struct ctrl_msg_hdr { 51*37241896SHiroki Sato int cm_version; 52*37241896SHiroki Sato size_t cm_len; 53*37241896SHiroki Sato int cm_type; 54*37241896SHiroki Sato }; 55*37241896SHiroki Sato 56*37241896SHiroki Sato struct ctrl_msg_pl { 57*37241896SHiroki Sato char *cp_ifname; 58*37241896SHiroki Sato char *cp_key; 59*37241896SHiroki Sato 60*37241896SHiroki Sato size_t cp_val_len; 61*37241896SHiroki Sato char *cp_val; 62*37241896SHiroki Sato }; 63*37241896SHiroki Sato 64*37241896SHiroki Sato int csock_open(struct sockinfo *, mode_t); 65*37241896SHiroki Sato int csock_close(struct sockinfo *); 66*37241896SHiroki Sato int csock_listen(struct sockinfo *); 67*37241896SHiroki Sato int csock_accept(struct sockinfo *); 68*37241896SHiroki Sato int cmsg_send(int, char *); 69*37241896SHiroki Sato int cmsg_recv(int, char *); 70*37241896SHiroki Sato 71*37241896SHiroki Sato size_t cmsg_pl2bin(char *, struct ctrl_msg_pl *); 72*37241896SHiroki Sato struct ctrl_msg_pl *cmsg_bin2pl(char *, struct ctrl_msg_pl *); 73*37241896SHiroki Sato size_t cmsg_str2bin(char *, void *, size_t); 74*37241896SHiroki Sato void *cmsg_bin2str(char *, void *, size_t); 75