1 2/* 3 * ng_parse.c 4 * 5 * Copyright (c) 1999 Whistle Communications, Inc. 6 * All rights reserved. 7 * 8 * Subject to the following obligations and disclaimer of warranty, use and --- 23 unchanged lines hidden (view full) --- 32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY 35 * OF SUCH DAMAGE. 36 * 37 * Author: Archie Cobbs <archie@freebsd.org> 38 * 39 * $Whistle: ng_parse.c,v 1.3 1999/11/29 01:43:48 archie Exp $ |
40 * $FreeBSD: head/sys/netgraph/ng_parse.c 123600 2003-12-17 12:40:34Z ru $ |
41 */ 42 43#include <sys/types.h> 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/kernel.h> 47#include <sys/errno.h> 48#include <sys/malloc.h> 49#include <sys/ctype.h> 50 |
51#include <net/ethernet.h> 52 |
53#include <netinet/in.h> 54 55#include <netgraph/ng_message.h> 56#include <netgraph/netgraph.h> 57#include <netgraph/ng_parse.h> 58 59#ifdef NG_SEPARATE_MALLOC 60MALLOC_DEFINE(M_NETGRAPH_PARSE, "netgraph_parse", "netgraph parse info"); --- 935 unchanged lines hidden (view full) --- 996 NULL, 997 ng_ipaddr_parse, 998 ng_ipaddr_unparse, 999 ng_ipaddr_getDefault, 1000 ng_int32_getAlign 1001}; 1002 1003/************************************************************************ |
1004 ETHERNET ADDRESS TYPE 1005 ************************************************************************/ 1006 1007static int 1008ng_enaddr_parse(const struct ng_parse_type *type, 1009 const char *s, int *const off, const u_char *const start, 1010 u_char *const buf, int *const buflen) 1011{ 1012 char *eptr; 1013 u_long val; 1014 int i; 1015 1016 if (*buflen < ETHER_ADDR_LEN) 1017 return (ERANGE); 1018 for (i = 0; i < ETHER_ADDR_LEN; i++) { 1019 val = strtoul(s + *off, &eptr, 16); 1020 if (val > 0xff || eptr == s + *off) 1021 return (EINVAL); 1022 buf[i] = (u_char)val; 1023 *off = (eptr - s); 1024 if (i < ETHER_ADDR_LEN - 1) { 1025 if (*eptr != ':') 1026 return (EINVAL); 1027 (*off)++; 1028 } 1029 } 1030 *buflen = ETHER_ADDR_LEN; 1031 return (0); 1032} 1033 1034static int 1035ng_enaddr_unparse(const struct ng_parse_type *type, 1036 const u_char *data, int *off, char *cbuf, int cbuflen) 1037{ 1038 int len; 1039 1040 len = snprintf(cbuf, cbuflen, "%02x:%02x:%02x:%02x:%02x:%02x", 1041 data[*off], data[*off + 1], data[*off + 2], 1042 data[*off + 3], data[*off + 4], data[*off + 5]); 1043 if (len >= cbuflen) 1044 return (ERANGE); 1045 *off += ETHER_ADDR_LEN; 1046 return (0); 1047} 1048 1049const struct ng_parse_type ng_parse_enaddr_type = { 1050 NULL, 1051 NULL, 1052 NULL, 1053 ng_enaddr_parse, 1054 ng_enaddr_unparse, 1055 NULL, 1056 0 1057}; 1058 1059/************************************************************************ |
1060 BYTE ARRAY TYPE 1061 ************************************************************************/ 1062 1063/* Get the length of a byte array */ 1064static int 1065ng_parse_bytearray_subtype_getLength(const struct ng_parse_type *type, 1066 const u_char *start, const u_char *buf) 1067{ --- 794 unchanged lines hidden --- |