version 1.1, 2012/02/21 22:14:23
|
version 1.1.1.3, 2023/09/27 11:11:38
|
Line 30
|
Line 30
|
* |
* |
*/ |
*/ |
|
|
#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 | |
|
|
libnet_t * |
libnet_t * |
libnet_init(int injection_type, char *device, char *err_buf) | libnet_init(int injection_type, const char *device, char *err_buf) |
{ |
{ |
libnet_t *l = NULL; |
libnet_t *l = NULL; |
|
|
#if !defined(__WIN32__) | #if defined(__WIN32__) |
if (getuid() && geteuid()) | |
{ | |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, | |
"%s(): UID or EUID of 0 required\n", __func__); | |
goto bad; | |
} | |
#else | |
WSADATA wsaData; |
WSADATA wsaData; |
|
|
if ((WSAStartup(0x0202, &wsaData)) != 0) |
if ((WSAStartup(0x0202, &wsaData)) != 0) |
{ |
{ |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): unable to initialize winsock 2\n", __func__); | "%s(): unable to initialize winsock 2", __func__); |
goto bad; |
goto bad; |
} |
} |
#endif |
#endif |
Line 65 libnet_init(int injection_type, char *device, char *er
|
Line 51 libnet_init(int injection_type, char *device, char *er
|
l = (libnet_t *)malloc(sizeof (libnet_t)); |
l = (libnet_t *)malloc(sizeof (libnet_t)); |
if (l == NULL) |
if (l == NULL) |
{ |
{ |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n", __func__, | snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s", __func__, |
strerror(errno)); |
strerror(errno)); |
goto bad; |
goto bad; |
} |
} |
Line 75 libnet_init(int injection_type, char *device, char *er
|
Line 61 libnet_init(int injection_type, char *device, char *er
|
l->injection_type = injection_type; |
l->injection_type = injection_type; |
l->ptag_state = LIBNET_PTAG_INITIALIZER; |
l->ptag_state = LIBNET_PTAG_INITIALIZER; |
l->device = (device ? strdup(device) : NULL); |
l->device = (device ? strdup(device) : NULL); |
|
l->fd = -1; |
|
|
strncpy(l->label, LIBNET_LABEL_DEFAULT, LIBNET_LABEL_SIZE); |
strncpy(l->label, LIBNET_LABEL_DEFAULT, LIBNET_LABEL_SIZE); |
l->label[sizeof(l->label)] = '\0'; | l->label[LIBNET_LABEL_SIZE - 1] = '\0'; |
|
|
switch (l->injection_type) |
switch (l->injection_type) |
{ |
{ |
|
case LIBNET_NONE: |
|
break; |
case LIBNET_LINK: |
case LIBNET_LINK: |
case LIBNET_LINK_ADV: |
case LIBNET_LINK_ADV: |
if (libnet_select_device(l) == -1) |
if (libnet_select_device(l) == -1) |
{ |
{ |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf); | snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); |
goto bad; |
goto bad; |
} |
} |
if (libnet_open_link(l) == -1) |
if (libnet_open_link(l) == -1) |
{ |
{ |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf); | snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); |
goto bad; |
goto bad; |
} |
} |
break; |
break; |
Line 98 libnet_init(int injection_type, char *device, char *er
|
Line 87 libnet_init(int injection_type, char *device, char *er
|
case LIBNET_RAW4_ADV: |
case LIBNET_RAW4_ADV: |
if (libnet_open_raw4(l) == -1) |
if (libnet_open_raw4(l) == -1) |
{ |
{ |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf); | snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); |
goto bad; |
goto bad; |
} |
} |
break; |
break; |
Line 106 libnet_init(int injection_type, char *device, char *er
|
Line 95 libnet_init(int injection_type, char *device, char *er
|
case LIBNET_RAW6_ADV: |
case LIBNET_RAW6_ADV: |
if (libnet_open_raw6(l) == -1) |
if (libnet_open_raw6(l) == -1) |
{ |
{ |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, l->err_buf); | snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); |
goto bad; |
goto bad; |
} |
} |
break; |
break; |
default: |
default: |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, |
snprintf(err_buf, LIBNET_ERRBUF_SIZE, |
"%s(): unsupported injection type\n", __func__); | "%s(): unsupported injection type", __func__); |
goto bad; |
goto bad; |
break; |
break; |
} |
} |
Line 132 libnet_destroy(libnet_t *l)
|
Line 121 libnet_destroy(libnet_t *l)
|
{ |
{ |
if (l) |
if (l) |
{ |
{ |
close(l->fd); | if (l->fd != -1) |
if (l->device) | close(l->fd); |
{ | free(l->device); |
free(l->device); | |
} | |
libnet_clear_packet(l); |
libnet_clear_packet(l); |
free(l); |
free(l); |
} |
} |
Line 146 void
|
Line 133 void
|
libnet_clear_packet(libnet_t *l) |
libnet_clear_packet(libnet_t *l) |
{ |
{ |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
libnet_pblock_t *next; |
|
|
|
if (l) | if (!l) |
{ |
{ |
p = l->protocol_blocks; | return; |
if (p) | |
{ | |
for (; p; p = next) | |
{ | |
next = p->next; | |
if (p->buf) | |
{ | |
free(p->buf); | |
} | |
free(p); | |
} | |
} | |
l->protocol_blocks = NULL; | |
l->total_size = 0; | |
} |
} |
|
|
|
while((p = l->protocol_blocks)) |
|
{ |
|
libnet_pblock_delete(l, p); |
|
} |
|
|
|
/* All pblocks are deleted, so start the tag count over from 1. */ |
|
l->ptag_state = 0; |
} |
} |
|
|
void |
void |
Line 189 libnet_getfd(libnet_t *l)
|
Line 169 libnet_getfd(libnet_t *l)
|
return (-1); |
return (-1); |
} |
} |
|
|
return (l->fd); | return (int)(l->fd); |
} |
} |
|
|
int8_t * | const char * |
libnet_getdevice(libnet_t *l) |
libnet_getdevice(libnet_t *l) |
{ |
{ |
if (l == NULL) |
if (l == NULL) |
Line 203 libnet_getdevice(libnet_t *l)
|
Line 183 libnet_getdevice(libnet_t *l)
|
return (l->device); |
return (l->device); |
} |
} |
|
|
u_int8_t * | uint8_t * |
libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag) |
libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag) |
{ |
{ |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
Line 225 libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag)
|
Line 205 libnet_getpbuf(libnet_t *l, libnet_ptag_t ptag)
|
} |
} |
} |
} |
|
|
u_int32_t | uint32_t |
libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag) |
libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag) |
{ |
{ |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
Line 247 libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag)
|
Line 227 libnet_getpbuf_size(libnet_t *l, libnet_ptag_t ptag)
|
} |
} |
} |
} |
|
|
u_int32_t | uint32_t |
libnet_getpacket_size(libnet_t *l) |
libnet_getpacket_size(libnet_t *l) |
{ |
{ |
|
/* Why doesn't this return l->total_size? */ |
libnet_pblock_t *p; |
libnet_pblock_t *p; |
u_int32_t n; | uint32_t n; |
|
|
if (l == NULL) |
if (l == NULL) |
{ |
{ |
Line 270 libnet_getpacket_size(libnet_t *l)
|
Line 251 libnet_getpacket_size(libnet_t *l)
|
return (n); |
return (n); |
} |
} |
|
|
/* EOF */ | /** |
| * Local Variables: |
| * indent-tabs-mode: nil |
| * c-file-style: "stroustrup" |
| * End: |
| */ |