xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.lib/pppoe/common.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * PPPoE common utilities and data.
24  *
25  * Copyright (c) 2000-2001 by Sun Microsystems, Inc.
26  * All rights reserved.
27  */
28 
29 #ifndef PPPOE_COMMON_H
30 #define	PPPOE_COMMON_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/socket.h>
38 #include <net/if.h>
39 #include <net/sppptun.h>
40 #include <net/pppoe.h>
41 #include <netinet/if_ether.h>
42 
43 #define	PKT_INPUT_LEN	PPPOE_MSGMAX
44 #define	PKT_OCTL_LEN	(sizeof (struct ppptun_control) + 1)
45 #define	PKT_OUTPUT_LEN	PPPOE_MSGMAX
46 
47 /* Common buffers */
48 extern uint32_t pkt_input[];
49 extern uint32_t pkt_octl[];
50 extern uint32_t pkt_output[];
51 
52 /* Name of PPPoE tunnel driver */
53 extern const char tunnam[];
54 
55 /* Name of application (from argv[0]) */
56 extern char *myname;
57 
58 /* Ethernet broadcast address */
59 extern const ether_addr_t ether_bcast;
60 
61 /* General purpose utility functions. */
62 struct strbuf;
63 extern int strioctl(int fd, int cmd, void *ptr, int ilen, int olen);
64 extern const char *ehost(const ppptun_atype *pap);
65 extern const char *ehost2(const struct ether_addr *ea);
66 extern const char *ihost(uint32_t haddr);
67 extern int hexdecode(char chr);
68 extern const char *mystrerror(int err);
69 extern void myperror(const char *emsg);
70 extern int mygetmsg(int fd, struct strbuf *ctrl, struct strbuf *data,
71     int *flags);
72 
73 /* PPPoE-specific functions. */
74 extern poep_t *poe_mkheader(void *dptr, uint8_t codeval, int sessionid);
75 extern boolean_t poe_tagcheck(const poep_t *poep, int length,
76     const uint8_t *tptr);
77 extern int poe_add_str(poep_t *poep, uint16_t ttype, const char *str);
78 extern int poe_add_long(poep_t *poep, uint16_t ttype, uint32_t val);
79 extern int poe_two_longs(poep_t *poep, uint16_t ttype, uint32_t val1,
80     uint32_t val2);
81 extern int poe_tag_copy(poep_t *poep, const uint8_t *tagp);
82 extern const char *poe_tagname(uint16_t tagtype);
83 extern const char *poe_codename(uint8_t codetype);
84 
85 /* These are here in case access wrappers are desired. */
86 #define	poe_version_type(p)	((p)->poep_version_type)
87 #define	poe_code(p)		((p)->poep_code)
88 #define	poe_session_id(p)	ntohs((p)->poep_session_id)
89 #define	poe_length(p)		ntohs((p)->poep_length)
90 
91 #ifdef	__cplusplus
92 }
93 #endif
94 
95 #endif /* PPPOE_COMMON_H */
96