xref: /haiku/src/add-ons/kernel/network/ppp/shared/libkernelppp/headers/KPPPConfigurePacket.h (revision 39241fe22890fb958b6ba32d6ab9526da98be187)
1 //-----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //
5 //  Copyright (c) 2003-2004 Waldemar Kornewald, Waldemar.Kornewald@web.de
6 //-----------------------------------------------------------------------
7 
8 #ifndef _K_PPP_CONFIGURE_PACKET__H
9 #define _K_PPP_CONFIGURE_PACKET__H
10 
11 #include <TemplateList.h>
12 
13 struct mbuf;
14 
15 //!	An abstract configure item.
16 typedef struct ppp_configure_item {
17 	uint8 type;
18 		//!< Item's type.
19 	uint8 length;
20 		//!< Item length (including appended data, if any).
21 	uint8 data[0];
22 		//!< Additional data may be appended to this structure.
23 } ppp_configure_item;
24 
25 
26 class KPPPConfigurePacket {
27 	private:
28 		// copies are not allowed!
29 		KPPPConfigurePacket(const KPPPConfigurePacket& copy);
30 		KPPPConfigurePacket& operator= (const KPPPConfigurePacket& copy);
31 
32 	public:
33 		KPPPConfigurePacket(uint8 code);
34 		KPPPConfigurePacket(struct mbuf *packet);
35 		~KPPPConfigurePacket();
36 
37 		bool SetCode(uint8 code);
38 		//!	Returns this packet's code value.
39 		uint8 Code() const
40 			{ return fCode; }
41 
42 		//!	Sets the packet's (unique) ID. Use KPPPLCP::NextID() to get a unique ID.
43 		void SetID(uint8 id)
44 			{ fID = id; }
45 		//!	Returns this packet's ID.
46 		uint8 ID() const
47 			{ return fID; }
48 
49 		bool AddItem(const ppp_configure_item *item, int32 index = -1);
50 		bool RemoveItem(ppp_configure_item *item);
51 		//!	Returns number of items in this packet.
52 		int32 CountItems() const
53 			{ return fItems.CountItems(); }
54 		ppp_configure_item *ItemAt(int32 index) const;
55 		ppp_configure_item *ItemWithType(uint8 type) const;
56 
57 		struct mbuf *ToMbuf(uint32 MRU, uint32 reserve = 0);
58 			// the user is responsible for freeing the mbuf
59 
60 	private:
61 		uint8 fCode, fID;
62 		TemplateList<ppp_configure_item*> fItems;
63 };
64 
65 
66 #endif
67