wpabuf.h

Go to the documentation of this file.
00001 
00016 #ifndef WPABUF_H
00017 #define WPABUF_H
00018 
00019 /*
00020  * Internal data structure for wpabuf. Please do not touch this directly from
00021  * elsewhere. This is only defined in header file to allow inline functions
00022  * from this file to access data.
00023  */
00024 struct wpabuf {
00025         size_t size; /* total size of the allocated buffer */
00026         size_t used; /* length of data in the buffer */
00027         u8 *ext_data; /* pointer to external data; NULL if data follows
00028                        * struct wpabuf */
00029         /* optionally followed by the allocated buffer */
00030 };
00031 
00032 
00033 int wpabuf_resize(struct wpabuf **buf, size_t add_len);
00034 struct wpabuf * wpabuf_alloc(size_t len);
00035 struct wpabuf * wpabuf_alloc_ext_data(u8 *data, size_t len);
00036 struct wpabuf * wpabuf_alloc_copy(const void *data, size_t len);
00037 struct wpabuf * wpabuf_dup(const struct wpabuf *src);
00038 void wpabuf_free(struct wpabuf *buf);
00039 void * wpabuf_put(struct wpabuf *buf, size_t len);
00040 struct wpabuf * wpabuf_concat(struct wpabuf *a, struct wpabuf *b);
00041 struct wpabuf * wpabuf_zeropad(struct wpabuf *buf, size_t len);
00042 void wpabuf_printf(struct wpabuf *buf, char *fmt, ...) PRINTF_FORMAT(2, 3);
00043 
00044 
00051 static inline size_t wpabuf_size(const struct wpabuf *buf)
00052 {
00053         return buf->size;
00054 }
00055 
00062 static inline size_t wpabuf_len(const struct wpabuf *buf)
00063 {
00064         return buf->used;
00065 }
00066 
00073 static inline size_t wpabuf_tailroom(const struct wpabuf *buf)
00074 {
00075         return buf->size - buf->used;
00076 }
00077 
00084 static inline const void * wpabuf_head(const struct wpabuf *buf)
00085 {
00086         if (buf->ext_data)
00087                 return buf->ext_data;
00088         return buf + 1;
00089 }
00090 
00091 static inline const u8 * wpabuf_head_u8(const struct wpabuf *buf)
00092 {
00093         return wpabuf_head(buf);
00094 }
00095 
00102 static inline void * wpabuf_mhead(struct wpabuf *buf)
00103 {
00104         if (buf->ext_data)
00105                 return buf->ext_data;
00106         return buf + 1;
00107 }
00108 
00109 static inline u8 * wpabuf_mhead_u8(struct wpabuf *buf)
00110 {
00111         return wpabuf_mhead(buf);
00112 }
00113 
00114 static inline void wpabuf_put_u8(struct wpabuf *buf, u8 data)
00115 {
00116         u8 *pos = wpabuf_put(buf, 1);
00117         *pos = data;
00118 }
00119 
00120 static inline void wpabuf_put_le16(struct wpabuf *buf, u16 data)
00121 {
00122         u8 *pos = wpabuf_put(buf, 2);
00123         WPA_PUT_LE16(pos, data);
00124 }
00125 
00126 static inline void wpabuf_put_be16(struct wpabuf *buf, u16 data)
00127 {
00128         u8 *pos = wpabuf_put(buf, 2);
00129         WPA_PUT_BE16(pos, data);
00130 }
00131 
00132 static inline void wpabuf_put_be24(struct wpabuf *buf, u32 data)
00133 {
00134         u8 *pos = wpabuf_put(buf, 3);
00135         WPA_PUT_BE24(pos, data);
00136 }
00137 
00138 static inline void wpabuf_put_be32(struct wpabuf *buf, u32 data)
00139 {
00140         u8 *pos = wpabuf_put(buf, 4);
00141         WPA_PUT_BE32(pos, data);
00142 }
00143 
00144 static inline void wpabuf_put_data(struct wpabuf *buf, const void *data,
00145                                    size_t len)
00146 {
00147         if (data)
00148                 os_memcpy(wpabuf_put(buf, len), data, len);
00149 }
00150 
00151 static inline void wpabuf_put_buf(struct wpabuf *dst,
00152                                   const struct wpabuf *src)
00153 {
00154         wpabuf_put_data(dst, wpabuf_head(src), wpabuf_len(src));
00155 }
00156 
00157 static inline void wpabuf_set(struct wpabuf *buf, const void *data, size_t len)
00158 {
00159         buf->ext_data = (u8 *) data;
00160         buf->size = buf->used = len;
00161 }
00162 
00163 static inline void wpabuf_put_str(struct wpabuf *dst, const char *str)
00164 {
00165         wpabuf_put_data(dst, str, os_strlen(str));
00166 }
00167 
00168 #endif /* WPABUF_H */
00169 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:54 2009 for hostapd by  doxygen 1.6.1