mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Initial import
This commit is contained in:
commit
c91b3c5006
14915 changed files with 590219 additions and 0 deletions
32
libc/dns/dnsquestion.h
Normal file
32
libc/dns/dnsquestion.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_DNS_DNSQUESTION_H_
|
||||
#define COSMOPOLITAN_LIBC_DNS_DNSQUESTION_H_
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct DnsQuestion {
|
||||
const char *qname;
|
||||
uint16_t qtype;
|
||||
uint16_t qclass;
|
||||
};
|
||||
|
||||
/**
|
||||
* Serializes DNS question record to wire.
|
||||
*
|
||||
* @return number of bytes written
|
||||
* @see pascalifydnsname()
|
||||
*/
|
||||
forceinline int serializednsquestion(uint8_t *buf, size_t size,
|
||||
struct DnsQuestion dq) {
|
||||
int wrote;
|
||||
if ((wrote = pascalifydnsname(buf, size, dq.qname)) == -1) return -1;
|
||||
if (wrote + 1 + 4 > size) return enospc();
|
||||
buf[wrote + 1] = dq.qtype >> 010, buf[wrote + 2] = dq.qtype >> 000;
|
||||
buf[wrote + 3] = dq.qclass >> 010, buf[wrote + 4] = dq.qclass >> 000;
|
||||
return wrote + 5;
|
||||
}
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_DNS_DNSQUESTION_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue