4 * Routines for manipulation with fwp message buffer (msgb)
12 /*unsigned char* fwp_msgb_dealloc(size_t buf_size) */
13 /*unsigned char* fwp_msgb_pool_init(size_t buf_size) */
18 * \param buf_size Size of msgb
19 * \return Allocated msgb
22 struct fwp_msgb* fwp_msgb_alloc(size_t buf_size)
24 struct fwp_msgb* msgb;
26 /*fwp_msgb_pool_dequeue; other choice*/
27 msgb = (struct fwp_msgb*) malloc(sizeof(struct fwp_msgb) + buf_size);
31 msgb->buffer_size = buf_size;
33 msgb->data = (unsigned char*) msgb + sizeof(struct fwp_msgb);
34 msgb->tail = msgb->data;
43 * \param msgb Pointer to msgb
46 void fwp_msgb_free(struct fwp_msgb *msgb)
53 * Routine is usually called after putting data of length len to msgb
54 * to adjust internal tail pointer and len fields of msgb
56 * \param msgb Pointer to msgb
57 * \param len The lenght data put to msgb
58 * \return Previous tail pointer
61 inline unsigned char* fwp_msgb_put(struct fwp_msgb *msgb, unsigned int len)
63 unsigned char *tmp= msgb->tail;
71 * Routine is usually called after reading data of lenght len from msgb to
72 * adjust internal data pointer and len of msgb
74 * \param msgb Pointer to msgb
75 * \param len The lenght data
76 * \return Previous tail pointer on NULL in case of lack of space in the buffer.
79 inline unsigned char* fwp_msgb_pull(struct fwp_msgb *msgb, unsigned int len)
85 return msgb->data += len;
89 * Routine is usually called after fwp_msgb_reserve after reserved area is filled
92 * \param msgb Pointer to msgb
93 * \param len The lenght data
94 * \return Current data pointer
97 inline unsigned char* fwp_msgb_push(struct fwp_msgb* msgb, unsigned int len)
104 inline unsigned char* fwp_msgb_shift(struct fwp_msgb *msgb, unsigned int len)
106 if (msgb->data + len > msgb->tail)
109 return msgb->data += len;
113 * Sets data pointer to the start of buffer
115 * \param msgb Pointer to msgb
118 inline void fwp_msgb_reset_data_pointer(struct fwp_msgb *msgb)
120 msgb->data = (unsigned char*) msgb + sizeof(struct fwp_msgb);
124 * Sets data pointer to the start of buffer and the length of used data to zero
126 * \param msgb Pointer to msgb
128 inline void fwp_msgb_reset_data(struct fwp_msgb* msgb)
131 msgb->data = (unsigned char*) msgb + sizeof(struct fwp_msgb);
132 msgb->tail = msgb->data;
136 * Reserve place of length len in msgb
138 * \param msgb Pointer to msgb
139 * \param len The lenght data
141 inline void fwp_msgb_reserve(fwp_msgb_t *msgb, unsigned int len)
147 /*struct fwp_socket* fwp_socket_create(struct sockaddr *_addr, socklen_t _addrlen)
149 struct fwp_socket* fwpsock;
152 fwpsock = (struct fwp_socket*) malloc(sizeof(struct fwp_socket) +
157 addr = (unsigned char*) fwpsock + sizeof(struct fwp_socket);
158 memcpy(addr, (void*) _addr, _addrlen);
160 fwpsock->addr = (struct sockaddr*) addr;
161 fwpsock->addrlen = _addrlen;
166 inline void fwp_socket_set(struct fwp_socket *fwpsock, struct sockaddr *_addr,
169 fwpsock->addr = _addr;
170 fwpsock->addrlen = _addrlen;
173 void fwp_socket_free(struct fwp_socket *fwpsock)
175 free((void*)fwpsock);