int libnet_open_raw6(libnet_t *l) { return (libnet_open_link(l)); }
libnet_t * libnet_init(int injection_type, const char *device, char *err_buf) { libnet_t *l = NULL; #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; if ((WSAStartup(0x0202, &wsaData)) != 0) { snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): unable to initialize winsock 2\n", __func__); goto bad; } #endif l = (libnet_t *)malloc(sizeof (libnet_t)); if (l == NULL) { snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): malloc(): %s\n", __func__, strerror(errno)); goto bad; } memset(l, 0, sizeof (*l)); l->injection_type = injection_type; l->ptag_state = LIBNET_PTAG_INITIALIZER; l->device = (device ? strdup(device) : NULL); strncpy(l->label, LIBNET_LABEL_DEFAULT, LIBNET_LABEL_SIZE); l->label[sizeof(l->label)] = '\0'; switch (l->injection_type) { case LIBNET_LINK: case LIBNET_LINK_ADV: if (libnet_select_device(l) == -1) { snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); goto bad; } if (libnet_open_link(l) == -1) { snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); goto bad; } break; case LIBNET_RAW4: case LIBNET_RAW4_ADV: if (libnet_open_raw4(l) == -1) { snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); goto bad; } break; case LIBNET_RAW6: case LIBNET_RAW6_ADV: if (libnet_open_raw6(l) == -1) { snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s", l->err_buf); goto bad; } break; default: snprintf(err_buf, LIBNET_ERRBUF_SIZE, "%s(): unsupported injection type\n", __func__); goto bad; break; } return (l); bad: if (l) { libnet_destroy(l); } return (NULL); }