mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
AK: Rename the common integer typedefs to make it obvious what they are.
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
This commit is contained in:
parent
c4c4bbc5ba
commit
27f699ef0c
208 changed files with 1603 additions and 1621 deletions
|
@ -20,8 +20,8 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
word id() const { return m_id; }
|
||||
void set_id(word w) { m_id = w; }
|
||||
u16 id() const { return m_id; }
|
||||
void set_id(u16 w) { m_id = w; }
|
||||
|
||||
bool recursion_desired() const { return m_recursion_desired; }
|
||||
void set_recursion_desired(bool b) { m_recursion_desired = b; }
|
||||
|
@ -32,16 +32,16 @@ public:
|
|||
bool is_authoritative_answer() const { return m_authoritative_answer; }
|
||||
void set_authoritative_answer(bool b) { m_authoritative_answer = b; }
|
||||
|
||||
byte opcode() const { return m_opcode; }
|
||||
void set_opcode(byte b) { m_opcode = b; }
|
||||
u8 opcode() const { return m_opcode; }
|
||||
void set_opcode(u8 b) { m_opcode = b; }
|
||||
|
||||
bool is_query() const { return !m_query_or_response; }
|
||||
bool is_response() const { return m_query_or_response; }
|
||||
void set_is_query() { m_query_or_response = false; }
|
||||
void set_is_response() { m_query_or_response = true; }
|
||||
|
||||
byte response_code() const { return m_response_code; }
|
||||
void set_response_code(byte b) { m_response_code = b; }
|
||||
u8 response_code() const { return m_response_code; }
|
||||
void set_response_code(u8 b) { m_response_code = b; }
|
||||
|
||||
bool checking_disabled() const { return m_checking_disabled; }
|
||||
void set_checking_disabled(bool b) { m_checking_disabled = b; }
|
||||
|
@ -52,39 +52,39 @@ public:
|
|||
bool is_recursion_available() const { return m_recursion_available; }
|
||||
void set_recursion_available(bool b) { m_recursion_available = b; }
|
||||
|
||||
word question_count() const { return m_question_count; }
|
||||
void set_question_count(word w) { m_question_count = w; }
|
||||
u16 question_count() const { return m_question_count; }
|
||||
void set_question_count(u16 w) { m_question_count = w; }
|
||||
|
||||
word answer_count() const { return m_answer_count; }
|
||||
void set_answer_count(word w) { m_answer_count = w; }
|
||||
u16 answer_count() const { return m_answer_count; }
|
||||
void set_answer_count(u16 w) { m_answer_count = w; }
|
||||
|
||||
word authority_count() const { return m_authority_count; }
|
||||
void set_authority_count(word w) { m_authority_count = w; }
|
||||
u16 authority_count() const { return m_authority_count; }
|
||||
void set_authority_count(u16 w) { m_authority_count = w; }
|
||||
|
||||
word additional_count() const { return m_additional_count; }
|
||||
void set_additional_count(word w) { m_additional_count = w; }
|
||||
u16 additional_count() const { return m_additional_count; }
|
||||
void set_additional_count(u16 w) { m_additional_count = w; }
|
||||
|
||||
void* payload() { return this + 1; }
|
||||
const void* payload() const { return this + 1; }
|
||||
|
||||
private:
|
||||
NetworkOrdered<word> m_id;
|
||||
NetworkOrdered<u16> m_id;
|
||||
|
||||
bool m_recursion_desired : 1;
|
||||
bool m_truncated : 1;
|
||||
bool m_authoritative_answer : 1;
|
||||
byte m_opcode : 4;
|
||||
u8 m_opcode : 4;
|
||||
bool m_query_or_response : 1;
|
||||
byte m_response_code : 4;
|
||||
u8 m_response_code : 4;
|
||||
bool m_checking_disabled : 1;
|
||||
bool m_authenticated_data : 1;
|
||||
bool m_zero : 1;
|
||||
bool m_recursion_available : 1;
|
||||
|
||||
NetworkOrdered<word> m_question_count;
|
||||
NetworkOrdered<word> m_answer_count;
|
||||
NetworkOrdered<word> m_authority_count;
|
||||
NetworkOrdered<word> m_additional_count;
|
||||
NetworkOrdered<u16> m_question_count;
|
||||
NetworkOrdered<u16> m_answer_count;
|
||||
NetworkOrdered<u16> m_authority_count;
|
||||
NetworkOrdered<u16> m_additional_count;
|
||||
};
|
||||
|
||||
static_assert(sizeof(DNSPacket) == 12);
|
||||
|
|
|
@ -8,21 +8,21 @@ class [[gnu::packed]] DNSRecord
|
|||
public:
|
||||
DNSRecord() {}
|
||||
|
||||
word name() const { return m_name; }
|
||||
word type() const { return m_type; }
|
||||
word record_class() const { return m_class; }
|
||||
dword ttl() const { return m_ttl; }
|
||||
word data_length() const { return m_data_length; }
|
||||
u16 name() const { return m_name; }
|
||||
u16 type() const { return m_type; }
|
||||
u16 record_class() const { return m_class; }
|
||||
u32 ttl() const { return m_ttl; }
|
||||
u16 data_length() const { return m_data_length; }
|
||||
|
||||
void* data() { return this + 1; }
|
||||
const void* data() const { return this + 1; }
|
||||
|
||||
private:
|
||||
NetworkOrdered<word> m_name;
|
||||
NetworkOrdered<word> m_type;
|
||||
NetworkOrdered<word> m_class;
|
||||
NetworkOrdered<dword> m_ttl;
|
||||
NetworkOrdered<word> m_data_length;
|
||||
NetworkOrdered<u16> m_name;
|
||||
NetworkOrdered<u16> m_type;
|
||||
NetworkOrdered<u16> m_class;
|
||||
NetworkOrdered<u32> m_ttl;
|
||||
NetworkOrdered<u16> m_data_length;
|
||||
};
|
||||
|
||||
static_assert(sizeof(DNSRecord) == 12);
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
static HashMap<String, String> dns_custom_hostnames;
|
||||
|
||||
static Vector<String> lookup(const String& hostname, bool& did_timeout, const String& DNS_IP, unsigned short record_type);
|
||||
static String parse_dns_name(const byte*, int& offset, int max_offset);
|
||||
static String parse_dns_name(const u8*, int& offset, int max_offset);
|
||||
|
||||
static void load_etc_hosts()
|
||||
{
|
||||
|
@ -46,20 +46,20 @@ static void load_etc_hosts()
|
|||
|
||||
auto sections = fields[0].split('.');
|
||||
IPv4Address addr {
|
||||
(byte)atoi(sections[0].characters()),
|
||||
(byte)atoi(sections[1].characters()),
|
||||
(byte)atoi(sections[2].characters()),
|
||||
(byte)atoi(sections[3].characters()),
|
||||
(u8)atoi(sections[0].characters()),
|
||||
(u8)atoi(sections[1].characters()),
|
||||
(u8)atoi(sections[2].characters()),
|
||||
(u8)atoi(sections[3].characters()),
|
||||
};
|
||||
|
||||
auto name = fields[1];
|
||||
dns_custom_hostnames.set(name, addr.to_string());
|
||||
|
||||
IPv4Address reverse_addr {
|
||||
(byte)atoi(sections[3].characters()),
|
||||
(byte)atoi(sections[2].characters()),
|
||||
(byte)atoi(sections[1].characters()),
|
||||
(byte)atoi(sections[0].characters()),
|
||||
(u8)atoi(sections[3].characters()),
|
||||
(u8)atoi(sections[2].characters()),
|
||||
(u8)atoi(sections[1].characters()),
|
||||
(u8)atoi(sections[0].characters()),
|
||||
};
|
||||
StringBuilder builder;
|
||||
builder.append(reverse_addr.to_string());
|
||||
|
@ -198,9 +198,9 @@ int main(int argc, char** argv)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static word get_next_id()
|
||||
static u16 get_next_id()
|
||||
{
|
||||
static word s_next_id = 0;
|
||||
static u16 s_next_id = 0;
|
||||
return ++s_next_id;
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
|||
stream << ByteBuffer::wrap(&request_header, sizeof(request_header));
|
||||
auto parts = hostname.split('.');
|
||||
for (auto& part : parts) {
|
||||
stream << (byte)part.length();
|
||||
stream << (u8)part.length();
|
||||
stream << part;
|
||||
}
|
||||
stream << '\0';
|
||||
|
@ -262,7 +262,7 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
|||
|
||||
struct sockaddr_in src_addr;
|
||||
socklen_t src_addr_len = sizeof(src_addr);
|
||||
byte response_buffer[4096];
|
||||
u8 response_buffer[4096];
|
||||
ssize_t nrecv = recvfrom(fd, response_buffer, sizeof(response_buffer) - 1, 0, (struct sockaddr*)&src_addr, &src_addr_len);
|
||||
if (nrecv < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
|
@ -303,13 +303,13 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
|||
}
|
||||
|
||||
int offset = 0;
|
||||
auto question = parse_dns_name((const byte*)response_header.payload(), offset, nrecv);
|
||||
auto question = parse_dns_name((const u8*)response_header.payload(), offset, nrecv);
|
||||
offset += 4;
|
||||
|
||||
Vector<String> addresses;
|
||||
|
||||
for (word i = 0; i < response_header.answer_count(); ++i) {
|
||||
auto& record = *(const DNSRecord*)(&((const byte*)response_header.payload())[offset]);
|
||||
for (u16 i = 0; i < response_header.answer_count(); ++i) {
|
||||
auto& record = *(const DNSRecord*)(&((const u8*)response_header.payload())[offset]);
|
||||
dbgprintf("LookupServer: Answer #%u: (question: %s), type=%u, ttl=%u, length=%u, data=",
|
||||
i,
|
||||
question.characters(),
|
||||
|
@ -320,11 +320,11 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
|||
offset += sizeof(DNSRecord) + record.data_length();
|
||||
if (record.type() == T_PTR) {
|
||||
int dummy = 0;
|
||||
auto name = parse_dns_name((const byte*)record.data(), dummy, record.data_length());
|
||||
auto name = parse_dns_name((const u8*)record.data(), dummy, record.data_length());
|
||||
dbgprintf("%s\n", name.characters());
|
||||
addresses.append(name);
|
||||
} else if (record.type() == T_A) {
|
||||
auto ipv4_address = IPv4Address((const byte*)record.data());
|
||||
auto ipv4_address = IPv4Address((const u8*)record.data());
|
||||
dbgprintf("%s\n", ipv4_address.to_string().characters());
|
||||
addresses.append(ipv4_address.to_string());
|
||||
} else {
|
||||
|
@ -337,11 +337,11 @@ Vector<String> lookup(const String& hostname, bool& did_timeout, const String& D
|
|||
return addresses;
|
||||
}
|
||||
|
||||
static String parse_dns_name(const byte* data, int& offset, int max_offset)
|
||||
static String parse_dns_name(const u8* data, int& offset, int max_offset)
|
||||
{
|
||||
Vector<char, 128> buf;
|
||||
while (offset < max_offset) {
|
||||
byte ch = data[offset];
|
||||
u8 ch = data[offset];
|
||||
if (ch == '\0') {
|
||||
++offset;
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue