version 1.1, 2012/02/21 22:14:23
|
version 1.1.1.4, 2023/09/27 11:11:38
|
Line 31
|
Line 31
|
* |
* |
*/ |
*/ |
|
|
#if (HAVE_CONFIG_H) | #include "common.h" |
#include "../include/config.h" | |
#endif | |
#if (!(_WIN32) || (__CYGWIN__)) | |
#include "../include/libnet.h" | |
#else | |
#include "../include/win32/libnet.h" | |
#endif | |
|
|
/* private function prototypes */ |
/* private function prototypes */ |
static libnet_cq_t *libnet_cq_find_internal(libnet_t *); |
static libnet_cq_t *libnet_cq_find_internal(libnet_t *); |
Line 50 static libnet_cq_t *l_cq = NULL;
|
Line 43 static libnet_cq_t *l_cq = NULL;
|
static libnet_cqd_t l_cqd = {0, CQ_LOCK_UNLOCKED, NULL}; |
static libnet_cqd_t l_cqd = {0, CQ_LOCK_UNLOCKED, NULL}; |
|
|
|
|
static inline int set_cq_lock(u_int x) | static int |
| set_cq_lock(uint32_t x) |
{ |
{ |
if (check_cq_lock(x)) |
if (check_cq_lock(x)) |
{ |
{ |
Line 61 static inline int set_cq_lock(u_int x)
|
Line 55 static inline int set_cq_lock(u_int x)
|
return (1); |
return (1); |
} |
} |
|
|
static inline int clear_cq_lock(u_int x) | static int |
| clear_cq_lock(uint32_t x) |
{ |
{ |
if (!check_cq_lock(x)) |
if (!check_cq_lock(x)) |
{ |
{ |
Line 86 libnet_cq_add(libnet_t *l, char *label)
|
Line 81 libnet_cq_add(libnet_t *l, char *label)
|
if (cq_is_wlocked()) |
if (cq_is_wlocked()) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't add, context queue is write locked\n", __func__); | "%s(): can't add, context queue is write locked", __func__); |
return (-1); |
return (-1); |
} |
} |
|
|
/* ensure there is a label */ |
/* ensure there is a label */ |
if (label == NULL) |
if (label == NULL) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): empty label\n", | snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, "%s(): empty label", |
__func__); |
__func__); |
return (-1); |
return (-1); |
} |
} |
Line 105 libnet_cq_add(libnet_t *l, char *label)
|
Line 100 libnet_cq_add(libnet_t *l, char *label)
|
if (l_cq == NULL) |
if (l_cq == NULL) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't malloc initial context queue: %s\n", | "%s(): can't malloc initial context queue: %s", |
__func__, strerror(errno)); |
__func__, strerror(errno)); |
return (-1); |
return (-1); |
} |
} |
Line 114 libnet_cq_add(libnet_t *l, char *label)
|
Line 109 libnet_cq_add(libnet_t *l, char *label)
|
|
|
/* label the context with the user specified string */ |
/* label the context with the user specified string */ |
strncpy(l->label, label, LIBNET_LABEL_SIZE); |
strncpy(l->label, label, LIBNET_LABEL_SIZE); |
l->label[LIBNET_LABEL_SIZE] = '\0'; | l->label[LIBNET_LABEL_SIZE - 1] = '\0'; |
|
|
l_cq->next = NULL; |
l_cq->next = NULL; |
l_cq->prev = NULL; |
l_cq->prev = NULL; |
Line 136 libnet_cq_add(libnet_t *l, char *label)
|
Line 131 libnet_cq_add(libnet_t *l, char *label)
|
if (l_cq == NULL) |
if (l_cq == NULL) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't malloc new context queue: %s\n", | "%s(): can't malloc new context queue: %s", |
__func__, strerror(errno)); |
__func__, strerror(errno)); |
return (-1); |
return (-1); |
} |
} |
Line 145 libnet_cq_add(libnet_t *l, char *label)
|
Line 140 libnet_cq_add(libnet_t *l, char *label)
|
|
|
/* label the context with the user specified string */ |
/* label the context with the user specified string */ |
strncpy(l->label, label, LIBNET_LABEL_SIZE); |
strncpy(l->label, label, LIBNET_LABEL_SIZE); |
l->label[LIBNET_LABEL_SIZE] = '\0'; | l->label[LIBNET_LABEL_SIZE -1] = '\0'; |
|
|
new->next = l_cq; |
new->next = l_cq; |
new->prev = NULL; |
new->prev = NULL; |
Line 168 libnet_cq_remove(libnet_t *l)
|
Line 163 libnet_cq_remove(libnet_t *l)
|
if (l_cq == NULL) |
if (l_cq == NULL) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't remove from empty context queue\n", __func__); | "%s(): can't remove from empty context queue", __func__); |
return (NULL); |
return (NULL); |
} |
} |
|
|
if (l == NULL) |
if (l == NULL) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
|
"%s(): can't remove empty libnet context\n", __func__); |
|
return(NULL); |
return(NULL); |
} |
} |
|
|
Line 183 libnet_cq_remove(libnet_t *l)
|
Line 176 libnet_cq_remove(libnet_t *l)
|
if (cq_is_wlocked()) |
if (cq_is_wlocked()) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): can't remove, context queue is write locked\n", | "%s(): can't remove, context queue is write locked", |
__func__); |
__func__); |
return (NULL); |
return (NULL); |
} |
} |
Line 191 libnet_cq_remove(libnet_t *l)
|
Line 184 libnet_cq_remove(libnet_t *l)
|
if ((p = libnet_cq_find_internal(l)) == NULL) |
if ((p = libnet_cq_find_internal(l)) == NULL) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): context not present in context queue\n", __func__); | "%s(): context not present in context queue", __func__); |
return (NULL); |
return (NULL); |
} |
} |
|
|
Line 282 libnet_cq_dup_check(libnet_t *l, char *label)
|
Line 275 libnet_cq_dup_check(libnet_t *l, char *label)
|
if (p->context == l) |
if (p->context == l) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): context already in context queue\n", __func__); | "%s(): context already in context queue", __func__); |
return (1); |
return (1); |
} |
} |
if (strncmp(p->context->label, label, LIBNET_LABEL_SIZE) == 0) |
if (strncmp(p->context->label, label, LIBNET_LABEL_SIZE) == 0) |
{ |
{ |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): duplicate label %s\n", __func__, label); | "%s(): duplicate label %s", __func__, label); |
return (1); |
return (1); |
} |
} |
} |
} |
Line 325 libnet_cq_find_by_label(char *label)
|
Line 318 libnet_cq_find_by_label(char *label)
|
return (p ? p->context : NULL); |
return (p ? p->context : NULL); |
} |
} |
|
|
int8_t * | const char * |
libnet_cq_getlabel(libnet_t *l) |
libnet_cq_getlabel(libnet_t *l) |
{ |
{ |
return (l->label); |
return (l->label); |
Line 344 libnet_cq_destroy()
|
Line 337 libnet_cq_destroy()
|
libnet_destroy(tmp->context); |
libnet_destroy(tmp->context); |
free(tmp); |
free(tmp); |
} |
} |
|
l_cq = NULL; |
|
memset(&l_cqd, 0, sizeof(l_cqd)); |
} |
} |
|
|
libnet_t * |
libnet_t * |
Line 388 libnet_cq_next()
|
Line 383 libnet_cq_next()
|
return (l_cqd.current ? l_cqd.current->context : NULL); |
return (l_cqd.current ? l_cqd.current->context : NULL); |
} |
} |
|
|
u_int32_t | uint32_t |
libnet_cq_size() |
libnet_cq_size() |
{ |
{ |
return (l_cqd.node); |
return (l_cqd.node); |
} |
} |
|
|
|
uint32_t |
|
libnet_cq_end_loop() |
|
{ |
|
if (! clear_cq_lock(CQ_LOCK_WRITE)) |
|
{ |
|
return (0); |
|
} |
|
l_cqd.current = l_cq; |
|
return (1); |
|
} |
|
|
|
/** |
|
* Local Variables: |
|
* indent-tabs-mode: nil |
|
* c-file-style: "stroustrup" |
|
* End: |
|
*/ |