Skip to content

Commit

Permalink
Started fixing endianess issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfontanini committed Aug 15, 2012
1 parent 68ab7b0 commit 892bc0e
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 142 deletions.
10 changes: 5 additions & 5 deletions include/arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace Tins {
*
* \return Returns the sender's IP address in an uint32_t.
*/
IPv4Address sender_ip_addr() const { return Utils::net_to_host_l(_arp.ar_sip); }
IPv4Address sender_ip_addr() const { return Utils::be_to_host(_arp.ar_sip); }

/**
* \brief Getter for the target's hardware address.
Expand All @@ -100,21 +100,21 @@ namespace Tins {
*
* \return Returns the target's IP address in an uint32_t.
*/
IPv4Address target_ip_addr() const { return Utils::net_to_host_l(_arp.ar_tip); }
IPv4Address target_ip_addr() const { return Utils::be_to_host(_arp.ar_tip); }

/**
* \brief Getter for the hardware address format.
*
* \return Returns the hardware address' format in an uint16_t.
*/
uint16_t hw_addr_format() const { return Utils::net_to_host_s(_arp.ar_hrd); }
uint16_t hw_addr_format() const { return Utils::be_to_host(_arp.ar_hrd); }

/**
* \brief Getter for the protocol address format.
*
* \return Returns the protocol address' format in an uint16_t.
*/
uint16_t prot_addr_format() const { return Utils::net_to_host_s(_arp.ar_pro); }
uint16_t prot_addr_format() const { return Utils::be_to_host(_arp.ar_pro); }

/**
* \brief Getter for the hardware address length.
Expand All @@ -135,7 +135,7 @@ namespace Tins {
*
* \return Returns the ARP opcode in an uint16_t.
*/
uint16_t opcode() const { return Utils::net_to_host_s(_arp.ar_op); }
uint16_t opcode() const { return Utils::be_to_host(_arp.ar_op); }

/** \brief Getter for the header size.
* \return Returns the ARP header size.
Expand Down
15 changes: 7 additions & 8 deletions include/bootp.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,48 +116,47 @@ namespace Tins {
* \brief Getter for the xid field.
* \return The xid field for this BootP PDU.
*/
uint32_t xid() const { return Utils::net_to_host_l(_bootp.xid); }
uint32_t xid() const { return Utils::be_to_host(_bootp.xid); }

/**
* \brief Getter for the secs field.
* \return The secs field for this BootP PDU.
*/
uint16_t secs() const { return Utils::net_to_host_s(_bootp.secs); }
uint16_t secs() const { return Utils::be_to_host(_bootp.secs); }

/** \brief Getter for the padding field.
* \return The padding field for this BootP PDU.
*/
uint16_t padding() const { return Utils::net_to_host_s(_bootp.padding); }
uint16_t padding() const { return Utils::be_to_host(_bootp.padding); }

/**
* \brief Getter for the ciaddr field.
* \return The ciaddr field for this BootP PDU.
*/
IPv4Address ciaddr() const { return Utils::net_to_host_l(_bootp.ciaddr); }
IPv4Address ciaddr() const { return Utils::be_to_host(_bootp.ciaddr); }

/**
* \brief Getter for the yiaddr field.
* \return The yiaddr field for this BootP PDU.
*/
IPv4Address yiaddr() const { return Utils::net_to_host_l(_bootp.yiaddr); }
IPv4Address yiaddr() const { return Utils::be_to_host(_bootp.yiaddr); }

/**
* \brief Getter for the siaddr field.
* \return The siaddr field for this BootP PDU.
*/
IPv4Address siaddr() const { return Utils::net_to_host_l(_bootp.siaddr); }
IPv4Address siaddr() const { return Utils::be_to_host(_bootp.siaddr); }

/**
* \brief Getter for the giaddr field.
* \return The giaddr field for this BootP PDU.
*/
IPv4Address giaddr() const { return Utils::net_to_host_l(_bootp.giaddr); }
IPv4Address giaddr() const { return Utils::be_to_host(_bootp.giaddr); }

/**
* \brief Getter for the chaddr field.
* \return The chddr field for this BootP PDU.
*/
//const uint8_t *chaddr() const { return _bootp.chaddr; }
chaddr_type chaddr() const { return _bootp.chaddr; }

/**
Expand Down
19 changes: 11 additions & 8 deletions include/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ namespace Tins {
dname(nm), addr(ad), type(t), qclass(c), ttl(tt) {}
};

typedef std::list<Query> queries_type;
typedef std::list<Resource> resources_type;

/**
* \brief Default constructor.
*
Expand Down Expand Up @@ -172,7 +175,7 @@ namespace Tins {
*
* \return uint16_t containing the value of the id field.
*/
uint16_t id() const { return Utils::net_to_host_s(dns.id); }
uint16_t id() const { return Utils::be_to_host(dns.id); }

/**
* \brief Setter for the query response field.
Expand Down Expand Up @@ -255,28 +258,28 @@ namespace Tins {
*
* \return uint16_t containing the value of the questions field.
*/
uint16_t questions() const { return Utils::net_to_host_s(dns.questions); }
uint16_t questions() const { return Utils::be_to_host(dns.questions); }

/**
* \brief Setter for the answers field.
*
* \return uint16_t containing the value of the answers field.
*/
uint16_t answers() const { return Utils::net_to_host_s(dns.answers); }
uint16_t answers() const { return Utils::be_to_host(dns.answers); }

/**
* \brief Setter for the authority field.
*
* \return uint16_t containing the value of the authority field.
*/
uint16_t authority() const { return Utils::net_to_host_s(dns.authority); }
uint16_t authority() const { return Utils::be_to_host(dns.authority); }

/**
* \brief Setter for the additional field.
*
* \return uint16_t containing the value of the additional field.
*/
uint16_t additional() const { return Utils::net_to_host_s(dns.additional); }
uint16_t additional() const { return Utils::be_to_host(dns.additional); }

/**
* \brief Getter for the PDU's type.
Expand Down Expand Up @@ -401,7 +404,7 @@ namespace Tins {
* \param ip The ip address of the resolved name.
*/
void add_answer(const std::string &name, QueryType type, QueryClass qclass,
uint32_t ttl, uint32_t ip);
uint32_t ttl, IPv4Address ip);

/**
* \brief Add a query response.
Expand Down Expand Up @@ -459,14 +462,14 @@ namespace Tins {
* \return std::list<Query> containing the queries in this
* record.
*/
std::list<Query> dns_queries() const;
queries_type dns_queries() const;

/**
* \brief Getter for this PDU's DNS answers
* \return std::list<Resource> containing the answers in this
* record.
*/
std::list<Resource> dns_answers();
resources_type dns_answers();

/**
* \sa PDU::clone_pdu
Expand Down
10 changes: 5 additions & 5 deletions include/icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,28 +230,28 @@ namespace Tins {
*
* \return Returns the checksum as an unit16_t.
*/
uint16_t check() const { return Utils::net_to_host_s(this->_icmp.check); }
uint16_t check() const { return Utils::be_to_host(this->_icmp.check); }

/**
* \brief Getter for the echo id.
*
* \return Returns the echo id.
*/
uint16_t id() const { return Utils::net_to_host_s(_icmp.un.echo.id); }
uint16_t id() const { return Utils::be_to_host(_icmp.un.echo.id); }

/**
* \brief Getter for the echo sequence number.
*
* \return Returns the echo sequence number.
*/
uint16_t sequence() const { return Utils::net_to_host_s(_icmp.un.echo.sequence); }
uint16_t sequence() const { return Utils::be_to_host(_icmp.un.echo.sequence); }

/**
* \brief Getter for the gateway field.
*
* \return Returns the gateways in an unit32_t.
*/
uint32_t gateway() const { return Utils::net_to_host_l(this->_icmp.un.gateway); }
uint32_t gateway() const { return Utils::be_to_host(this->_icmp.un.gateway); }

/**
* \brief Getter for the pointer field.
Expand All @@ -265,7 +265,7 @@ namespace Tins {
*
* \return Returns the mtu value in an uint16_t.
*/
uint16_t mtu() const { return Utils::net_to_host_s(this->_icmp.un.frag.mtu); }
uint16_t mtu() const { return Utils::be_to_host(this->_icmp.un.frag.mtu); }

/**
* \brief Returns the header size.
Expand Down
12 changes: 6 additions & 6 deletions include/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,21 @@ namespace Tins {
*
* \return The total length of this IP PDU.
*/
uint16_t tot_len() const { return Utils::net_to_host_s(_ip.tot_len); }
uint16_t tot_len() const { return Utils::be_to_host(_ip.tot_len); }

/**
* \brief Getter for the id field.
*
* \return The id for this IP PDU.
*/
uint16_t id() const { return Utils::net_to_host_s(_ip.id); }
uint16_t id() const { return Utils::be_to_host(_ip.id); }

/**
* \brief Getter for the fragment offset field.
*
* \return The fragment offset for this IP PDU.
*/
uint16_t frag_off() const { return Utils::net_to_host_s(_ip.frag_off); }
uint16_t frag_off() const { return Utils::be_to_host(_ip.frag_off); }

/**
* \brief Getter for the time to live field.
Expand All @@ -205,20 +205,20 @@ namespace Tins {
*
* \return The checksum for this IP PDU.
*/
uint16_t check() const { return Utils::net_to_host_s(_ip.check); }
uint16_t check() const { return Utils::be_to_host(_ip.check); }

/**
* \brief Getter for the source address field.
*
* \return The source address for this IP PDU.
*/
IPv4Address src_addr() const { return Utils::net_to_host_l(_ip.saddr); }
IPv4Address src_addr() const { return Utils::be_to_host(_ip.saddr); }

/**
* \brief Getter for the destination address field.
* \return The destination address for this IP PDU.
*/
IPv4Address dst_addr() const { return Utils::net_to_host_l(_ip.daddr); }
IPv4Address dst_addr() const { return Utils::be_to_host(_ip.daddr); }

/**
* \brief Getter for the version field.
Expand Down
14 changes: 7 additions & 7 deletions include/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,49 +141,49 @@ namespace Tins {
*
* \return The destination port in an uint16_t.
*/
uint16_t dport() const { return Utils::net_to_host_s(_tcp.dport); }
uint16_t dport() const { return Utils::be_to_host(_tcp.dport); }

/**
* \brief Getter for the source port field.
*
* \return The source port in an uint16_t.
*/
uint16_t sport() const { return Utils::net_to_host_s(_tcp.sport); }
uint16_t sport() const { return Utils::be_to_host(_tcp.sport); }

/**
* \brief Getter for the sequence number field.
*
* \return The sequence number in an uint32_t.
*/
uint32_t seq() const { return Utils::net_to_host_l(_tcp.seq); }
uint32_t seq() const { return Utils::be_to_host(_tcp.seq); }

/**
* \brief Getter for the acknowledge number field.
*
* \return The acknowledge number in an uint32_t.
*/
uint32_t ack_seq() const { return Utils::net_to_host_l(_tcp.ack_seq); }
uint32_t ack_seq() const { return Utils::be_to_host(_tcp.ack_seq); }

/**
* \brief Getter for the window size field.
*
* \return The window size in an uint32_t.
*/
uint16_t window() const { return Utils::net_to_host_s(_tcp.window); }
uint16_t window() const { return Utils::be_to_host(_tcp.window); }

/**
* \brief Getter for the checksum field.
*
* \return The checksum field in an uint16_t.
*/
uint16_t check() const { return Utils::net_to_host_s(_tcp.check); }
uint16_t check() const { return Utils::be_to_host(_tcp.check); }

/**
* \brief Getter for the urgent pointer field.
*
* \return The urgent pointer in an uint16_t.
*/
uint16_t urg_ptr() const { return Utils::net_to_host_s(_tcp.urg_ptr); }
uint16_t urg_ptr() const { return Utils::be_to_host(_tcp.urg_ptr); }

/**
* \brief Getter for the data offset field.
Expand Down
6 changes: 3 additions & 3 deletions include/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ namespace Tins {
* \brief Getter for the destination port.
* \return The datagram's destination port.
*/
uint16_t dport() const { return Utils::net_to_host_s(_udp.dport); }
uint16_t dport() const { return Utils::be_to_host(_udp.dport); }

/**
* \brief Getter for the source port.
* \return The datagram's source port.
*/
uint16_t sport() const { return Utils::net_to_host_s(_udp.sport); }
uint16_t sport() const { return Utils::be_to_host(_udp.sport); }

/**
* \brief Getter for the length of the datagram.
* \return The length of the datagram.
*/
uint16_t length() const { return Utils::net_to_host_s(_udp.len); }
uint16_t length() const { return Utils::be_to_host(_udp.len); }

/**
* \brief Set the destination port.
Expand Down
Loading

0 comments on commit 892bc0e

Please sign in to comment.