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