From d549585de5399f3acd41ea66dc5351c5107c0771 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Tue, 16 Aug 2011 13:53:08 -0300 Subject: [PATCH] Added BootP PDU header file. Still needs filling and implementation --- include/bootp.h | 74 ++++++++++++++++++++++++++++++++++++++++++++ src/packetsender.cpp | 4 +-- 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 include/bootp.h diff --git a/include/bootp.h b/include/bootp.h new file mode 100644 index 0000000..1dc4e12 --- /dev/null +++ b/include/bootp.h @@ -0,0 +1,74 @@ +/* + * libtins is a net packet wrapper library for crafting and + * interpreting sniffed packets. + * + * Copyright (C) 2011 Nasel + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __BOOTP_H +#define __BOOTP_H + +#include + +#include + +#include "pdu.h" + +namespace Tins { + + /** + * \brief Class representing a BootP packet. + */ + class BootP : public PDU { + + public: + /** + * \brief Enum which contains the different opcodes BootP messages. + */ + enum OpCodes { + BOOTREQUEST = 1, + BOOTREPLY = 2 + } + + private: + /** + * Struct that represents the Bootp datagram. + */ + struct bootp { + uint8_t opcode; + uint8_t htype; + uint8_t hlen; + uint8_t hops; + uint32_t xid; + uint16_t secs; + uint16_t padding; + uint32_t ciaddr; + uint32_t yiaddr; + uint32_t siaddr; + uint32_t giaddr; + uint8_t chaddr[16]; + uint8_t sname[64]; + uint8_t file[128]; + uint8_t vend[64]; + } __attribute__((__packed__)); + + + } + +} + +#endif diff --git a/src/packetsender.cpp b/src/packetsender.cpp index 6dd13dd..5ba0ee9 100644 --- a/src/packetsender.cpp +++ b/src/packetsender.cpp @@ -106,7 +106,7 @@ bool Tins::PacketSender::send_l2(PDU *pdu, struct sockaddr* link_addr, uint32_t uint8_t *buffer = pdu->serialize(sz); bool ret_val = (sendto(sock, buffer, sz, 0, link_addr, len_addr) != -1); delete[] buffer; - + return ret_val; } @@ -150,7 +150,7 @@ Tins::PDU *Tins::PacketSender::recv_match_loop(int sock, PDU *pdu, struct sockad if((read = select(sock + 1, &readfds, 0, 0, &timeout)) == -1) return 0; if(FD_ISSET(sock, &readfds)) { - ssize_t size = recvfrom(sock, buffer, 2048, 0, link_addr, &addrlen); + ssize_t size = recvfrom(sock, buffer, 2048, 0, link_addr, &addrlen); if(pdu->matches_response(buffer, size)) return pdu->clone_packet(buffer, size); }