mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Make whitespace changes
Status lines for Emacs and Vim have been added to Python sources so they'll be easier to edit using Python's preferred coding style. Some DNS helper functions have been broken up into multiple files. It's nice to have one function per file whenever possible, since that way we don't need -ffunction-sections. Another reason it's good to have small source files, is because the build will be enforcing resource limits on compilation and testing soon.
This commit is contained in:
parent
71273bc5c9
commit
9b29358511
293 changed files with 1975 additions and 609 deletions
|
@ -20,6 +20,9 @@
|
|||
#include "libc/sysv/consts/termios.h"
|
||||
|
||||
uint32_t cfgetispeed(const struct termios *t) {
|
||||
/* return t->c_cflag & CBAUD; */ /* ??? */
|
||||
return t->c_ispeed;
|
||||
if (CBAUD) {
|
||||
return t->c_cflag & CBAUD;
|
||||
} else {
|
||||
return t->c_ispeed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
#include "libc/sysv/consts/termios.h"
|
||||
|
||||
uint32_t cfgetospeed(const struct termios *t) {
|
||||
/* return t->c_cflag & CBAUD; */ /* ??? */
|
||||
return t->c_ospeed;
|
||||
if (CBAUD) {
|
||||
return t->c_cflag & CBAUD;
|
||||
} else {
|
||||
return t->c_ospeed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,11 +22,15 @@
|
|||
|
||||
int cfsetospeed(struct termios *t, int speed) {
|
||||
if (CBAUD) {
|
||||
if (speed & ~CBAUD) return einval();
|
||||
t->c_cflag &= ~CBAUD;
|
||||
t->c_cflag |= speed;
|
||||
if (!(speed & ~CBAUD)) {
|
||||
t->c_cflag &= ~CBAUD;
|
||||
t->c_cflag |= speed;
|
||||
return 0;
|
||||
} else {
|
||||
return einval();
|
||||
}
|
||||
} else {
|
||||
t->c_ospeed = speed;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -64,8 +64,8 @@ int CompareDnsNames(const char *, const char *) paramsnonnull();
|
|||
int PascalifyDnsName(uint8_t *, size_t, const char *) paramsnonnull();
|
||||
int ResolveDns(const struct ResolvConf *, int, const char *, struct sockaddr *,
|
||||
uint32_t) paramsnonnull();
|
||||
int ResolveDnsReverse(const struct ResolvConf *resolvconf, int, const char *,
|
||||
char *, size_t) paramsnonnull();
|
||||
int ResolveDnsReverse(const struct ResolvConf *, int, const char *, char *,
|
||||
size_t) paramsnonnull();
|
||||
struct addrinfo *newaddrinfo(uint16_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_DNS_ENT_H_
|
||||
#define COSMOPOLITAN_LIBC_DNS_ENT_H_
|
||||
#include "libc/dns/dns.h"
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ int getaddrinfo(const char *name, const char *service,
|
|||
struct addrinfo *ai;
|
||||
char proto[32];
|
||||
port = 0;
|
||||
|
||||
if (!name && !service) return EAI_NONAME;
|
||||
if (!name && (hints->ai_flags & AI_CANONNAME)) return EAI_BADFLAGS;
|
||||
if (service && (port = parseport(service)) == -1) {
|
||||
|
@ -60,10 +59,10 @@ int getaddrinfo(const char *name, const char *service,
|
|||
strcpy(proto, "udp");
|
||||
else /* ai_socktype == 0 */
|
||||
strcpy(proto, "");
|
||||
|
||||
if ((port = LookupServicesByName(service, proto, sizeof(proto), NULL, 0,
|
||||
NULL)) == -1)
|
||||
NULL)) == -1) {
|
||||
return EAI_NONAME;
|
||||
}
|
||||
}
|
||||
if (!(ai = newaddrinfo(port))) return EAI_MEMORY;
|
||||
if (service) ai->ai_addr4->sin_port = htons(port);
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
@ -35,35 +34,25 @@ struct hostent *gethostbyaddr(const void *s_addr, socklen_t len, int type) {
|
|||
static char *h_aliases[1];
|
||||
static char *h_addr_list[2];
|
||||
static char h_addr_list0[4];
|
||||
|
||||
struct sockaddr_in addr;
|
||||
|
||||
if (!ptr1) {
|
||||
he1.h_name = h_name;
|
||||
|
||||
he1.h_aliases = h_aliases;
|
||||
he1.h_aliases[0] = NULL;
|
||||
|
||||
he1.h_addrtype = AF_INET;
|
||||
he1.h_length = 4;
|
||||
he1.h_addr_list = h_addr_list;
|
||||
|
||||
he1.h_addr_list[0] = h_addr_list0;
|
||||
he1.h_addr_list[1] = NULL;
|
||||
|
||||
ptr1 = &he1;
|
||||
}
|
||||
|
||||
if (type != AF_INET || len != sizeof(uint32_t)) return NULL;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = 0;
|
||||
addr.sin_addr.s_addr = *(uint32_t *)(s_addr);
|
||||
|
||||
if (getnameinfo((struct sockaddr *)&addr, sizeof(addr), ptr1->h_name,
|
||||
DNS_NAME_MAX, NULL, 0, 0))
|
||||
return NULL;
|
||||
|
||||
*((uint32_t *)ptr1->h_addr_list[0]) = (addr.sin_addr.s_addr);
|
||||
|
||||
return ptr1;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/mem/mem.h"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
|
|
41
libc/dns/getntprotocolstxtpath.c
Normal file
41
libc/dns/getntprotocolstxtpath.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ This is free and unencumbered software released into the public domain. │
|
||||
│ │
|
||||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │
|
||||
│ distribute this software, either in source code form or as a compiled │
|
||||
│ binary, for any purpose, commercial or non-commercial, and by any │
|
||||
│ means. │
|
||||
│ │
|
||||
│ In jurisdictions that recognize copyright laws, the author or authors │
|
||||
│ of this software dedicate any and all copyright interest in the │
|
||||
│ software to the public domain. We make this dedication for the benefit │
|
||||
│ of the public at large and to the detriment of our heirs and │
|
||||
│ successors. We intend this dedication to be an overt act of │
|
||||
│ relinquishment in perpetuity of all present and future rights to this │
|
||||
│ software under copyright law. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │
|
||||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/prototxt.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
|
||||
textwindows char *GetNtProtocolsTxtPath(char *pathbuf, uint32_t size) {
|
||||
/* protocol, not plural */
|
||||
const char *const kWinHostsPath = "\\drivers\\etc\\protocol";
|
||||
uint32_t len = GetSystemDirectoryA(&pathbuf[0], size);
|
||||
if (len && len + strlen(kWinHostsPath) + 1 < size) {
|
||||
if (pathbuf[len] == '\\') pathbuf[len--] = '\0';
|
||||
memcpy(&pathbuf[len], kWinHostsPath, strlen(kWinHostsPath) + 1);
|
||||
return &pathbuf[0];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
40
libc/dns/getntservicestxtpath.c
Normal file
40
libc/dns/getntservicestxtpath.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ This is free and unencumbered software released into the public domain. │
|
||||
│ │
|
||||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │
|
||||
│ distribute this software, either in source code form or as a compiled │
|
||||
│ binary, for any purpose, commercial or non-commercial, and by any │
|
||||
│ means. │
|
||||
│ │
|
||||
│ In jurisdictions that recognize copyright laws, the author or authors │
|
||||
│ of this software dedicate any and all copyright interest in the │
|
||||
│ software to the public domain. We make this dedication for the benefit │
|
||||
│ of the public at large and to the detriment of our heirs and │
|
||||
│ successors. We intend this dedication to be an overt act of │
|
||||
│ relinquishment in perpetuity of all present and future rights to this │
|
||||
│ software under copyright law. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │
|
||||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/servicestxt.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
|
||||
textwindows char *GetNtServicesTxtPath(char *pathbuf, uint32_t size) {
|
||||
const char *const kWinHostsPath = "\\drivers\\etc\\services";
|
||||
uint32_t len = GetSystemDirectoryA(&pathbuf[0], size);
|
||||
if (len && len + strlen(kWinHostsPath) + 1 < size) {
|
||||
if (pathbuf[len] == '\\') pathbuf[len--] = '\0';
|
||||
memcpy(&pathbuf[len], kWinHostsPath, strlen(kWinHostsPath) + 1);
|
||||
return &pathbuf[0];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/dns/prototxt.h"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/dns/prototxt.h"
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/dns/servicestxt.h"
|
||||
|
@ -35,7 +34,6 @@ struct servent *getservbyname(const char *name, const char *proto) {
|
|||
static char s_name[DNS_NAME_MAX + 1];
|
||||
static char localproto[DNS_NAME_MAX + 1];
|
||||
int p;
|
||||
|
||||
if (!ptr0) {
|
||||
se0.s_name = s_name;
|
||||
if (!(se0.s_aliases = calloc(1, sizeof(char *)))) return NULL;
|
||||
|
@ -43,17 +41,13 @@ struct servent *getservbyname(const char *name, const char *proto) {
|
|||
se0.s_proto = localproto;
|
||||
ptr0 = &se0;
|
||||
}
|
||||
|
||||
if (proto) {
|
||||
if (!memccpy(localproto, proto, '\0', DNS_NAME_MAX)) return NULL;
|
||||
} else
|
||||
strcpy(localproto, "");
|
||||
|
||||
p = LookupServicesByName(name, ptr0->s_proto, DNS_NAME_MAX, ptr0->s_name,
|
||||
DNS_NAME_MAX, NULL);
|
||||
if (p == -1) return NULL;
|
||||
|
||||
ptr0->s_port = htons(p);
|
||||
|
||||
return ptr0;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/dns/servicestxt.h"
|
||||
|
@ -34,7 +33,6 @@ struct servent *getservbyport(int port, const char *proto) {
|
|||
static struct servent *ptr1, se1;
|
||||
static char s_name[DNS_NAME_MAX + 1];
|
||||
static char localproto[DNS_NAME_MAX + 1];
|
||||
|
||||
if (!ptr1) {
|
||||
se1.s_name = s_name;
|
||||
if (!(se1.s_aliases = calloc(1, sizeof(char *)))) return NULL;
|
||||
|
@ -42,16 +40,14 @@ struct servent *getservbyport(int port, const char *proto) {
|
|||
se1.s_proto = localproto;
|
||||
ptr1 = &se1;
|
||||
}
|
||||
|
||||
if (proto) {
|
||||
if (!memccpy(localproto, proto, '\0', DNS_NAME_MAX)) return NULL;
|
||||
} else
|
||||
strcpy(localproto, "");
|
||||
|
||||
if (LookupServicesByPort(ntohs(port), ptr1->s_proto, DNS_NAME_MAX,
|
||||
ptr1->s_name, DNS_NAME_MAX, NULL) == -1)
|
||||
ptr1->s_name, DNS_NAME_MAX, NULL) == -1) {
|
||||
return NULL;
|
||||
|
||||
}
|
||||
ptr1->s_port = port;
|
||||
return ptr1;
|
||||
}
|
||||
|
|
|
@ -23,11 +23,10 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
|
||||
int h_errno = 0;
|
||||
int h_errno;
|
||||
|
||||
void herror(const char *s) {
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
|
||||
|
|
|
@ -23,103 +23,12 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/prototxt.h"
|
||||
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/prototxt.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static textwindows noinline char *GetNtProtocolsTxtPath(char *pathbuf,
|
||||
uint32_t size) {
|
||||
/* protocol, not plural */
|
||||
const char *const kWinHostsPath = "\\drivers\\etc\\protocol";
|
||||
uint32_t len = GetSystemDirectoryA(&pathbuf[0], size);
|
||||
if (len && len + strlen(kWinHostsPath) + 1 < size) {
|
||||
if (pathbuf[len] == '\\') pathbuf[len--] = '\0';
|
||||
memcpy(&pathbuf[len], kWinHostsPath, strlen(kWinHostsPath) + 1);
|
||||
return &pathbuf[0];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens and searches /etc/protocols to find name for a given number.
|
||||
*
|
||||
* format of /etc/protocols is like this:
|
||||
*
|
||||
* # comment
|
||||
* # NAME PROTOCOL ALIASES
|
||||
* ip 0 IP
|
||||
* icmp 1 ICMP
|
||||
*
|
||||
* @param protonum is the protocol number
|
||||
* @param buf is a buffer to store the official name of the protocol
|
||||
* @param bufsize is the size of buf
|
||||
* @param filepath is the location of the protocols file
|
||||
* (if NULL, uses /etc/protocols)
|
||||
* @return 0 on success, -1 on error
|
||||
*
|
||||
* @note aliases are not read from the file.
|
||||
*/
|
||||
int LookupProtoByNumber(const int protonum, char *buf, size_t bufsize,
|
||||
const char *filepath) {
|
||||
FILE *f;
|
||||
char *line;
|
||||
char pathbuf[PATH_MAX];
|
||||
const char *path;
|
||||
size_t linesize;
|
||||
int found;
|
||||
char *name, *number, *comment, *tok;
|
||||
|
||||
if (!(path = filepath)) {
|
||||
path = "/etc/protocols";
|
||||
if (IsWindows()) {
|
||||
path =
|
||||
firstnonnull(GetNtProtocolsTxtPath(pathbuf, ARRAYLEN(pathbuf)), path);
|
||||
}
|
||||
}
|
||||
|
||||
if (bufsize == 0 || !(f = fopen(path, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
line = NULL;
|
||||
linesize = 0;
|
||||
found = 0;
|
||||
|
||||
while (found == 0 && (getline(&line, &linesize, f)) != -1) {
|
||||
if ((comment = strchr(line, '#'))) *comment = '\0';
|
||||
name = strtok_r(line, " \t\r\n\v", &tok);
|
||||
number = strtok_r(NULL, " \t\r\n\v", &tok);
|
||||
if (name && number && protonum == atoi(number)) {
|
||||
if (!memccpy(buf, name, '\0', bufsize)) {
|
||||
strcpy(buf, "");
|
||||
break;
|
||||
}
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
|
||||
if (ferror(f)) {
|
||||
errno = ferror(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (!found) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens and searches /etc/protocols to find number for a given name.
|
||||
|
@ -144,7 +53,6 @@ int LookupProtoByName(const char *protoname, char *buf, size_t bufsize,
|
|||
size_t linesize;
|
||||
int found, result;
|
||||
char *name, *number, *alias, *comment, *tok;
|
||||
|
||||
if (!(path = filepath)) {
|
||||
path = "/etc/protocols";
|
||||
if (IsWindows()) {
|
||||
|
@ -152,7 +60,6 @@ int LookupProtoByName(const char *protoname, char *buf, size_t bufsize,
|
|||
firstnonnull(GetNtProtocolsTxtPath(pathbuf, ARRAYLEN(pathbuf)), path);
|
||||
}
|
||||
}
|
||||
|
||||
if (bufsize == 0 || !(f = fopen(path, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -160,7 +67,6 @@ int LookupProtoByName(const char *protoname, char *buf, size_t bufsize,
|
|||
linesize = 0;
|
||||
found = 0;
|
||||
result = -1;
|
||||
|
||||
while (found == 0 && (getline(&line, &linesize, f)) != -1) {
|
||||
if ((comment = strchr(line, '#'))) *comment = '\0';
|
||||
name = strtok_r(line, " \t\r\n\v", &tok);
|
||||
|
@ -169,7 +75,6 @@ int LookupProtoByName(const char *protoname, char *buf, size_t bufsize,
|
|||
alias = name;
|
||||
while (alias && strcasecmp(alias, protoname) != 0)
|
||||
alias = strtok_r(NULL, " \t\r\n\v", &tok);
|
||||
|
||||
if (alias) /* alias matched with protoname */
|
||||
{
|
||||
if (!memccpy(buf, name, '\0', bufsize)) {
|
||||
|
@ -182,14 +87,11 @@ int LookupProtoByName(const char *protoname, char *buf, size_t bufsize,
|
|||
}
|
||||
}
|
||||
free(line);
|
||||
|
||||
if (ferror(f)) {
|
||||
errno = ferror(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (!found) return -1;
|
||||
|
||||
return result;
|
||||
}
|
93
libc/dns/lookupprotobynumber.c
Normal file
93
libc/dns/lookupprotobynumber.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ This is free and unencumbered software released into the public domain. │
|
||||
│ │
|
||||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │
|
||||
│ distribute this software, either in source code form or as a compiled │
|
||||
│ binary, for any purpose, commercial or non-commercial, and by any │
|
||||
│ means. │
|
||||
│ │
|
||||
│ In jurisdictions that recognize copyright laws, the author or authors │
|
||||
│ of this software dedicate any and all copyright interest in the │
|
||||
│ software to the public domain. We make this dedication for the benefit │
|
||||
│ of the public at large and to the detriment of our heirs and │
|
||||
│ successors. We intend this dedication to be an overt act of │
|
||||
│ relinquishment in perpetuity of all present and future rights to this │
|
||||
│ software under copyright law. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │
|
||||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/dns/prototxt.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
/**
|
||||
* Opens and searches /etc/protocols to find name for a given number.
|
||||
*
|
||||
* The format of /etc/protocols is like this:
|
||||
*
|
||||
* # comment
|
||||
* # NAME PROTOCOL ALIASES
|
||||
* ip 0 IP
|
||||
* icmp 1 ICMP
|
||||
*
|
||||
* @param protonum is the protocol number
|
||||
* @param buf is a buffer to store the official name of the protocol
|
||||
* @param bufsize is the size of buf
|
||||
* @param filepath is the location of the protocols file
|
||||
* (if NULL, uses /etc/protocols)
|
||||
* @return 0 on success, -1 on error
|
||||
* @note aliases are not read from the file.
|
||||
*/
|
||||
int LookupProtoByNumber(const int protonum, char *buf, size_t bufsize,
|
||||
const char *filepath) {
|
||||
FILE *f;
|
||||
char *line;
|
||||
char pathbuf[PATH_MAX];
|
||||
const char *path;
|
||||
size_t linesize;
|
||||
int found;
|
||||
char *name, *number, *comment, *tok;
|
||||
if (!(path = filepath)) {
|
||||
path = "/etc/protocols";
|
||||
if (IsWindows()) {
|
||||
path =
|
||||
firstnonnull(GetNtProtocolsTxtPath(pathbuf, ARRAYLEN(pathbuf)), path);
|
||||
}
|
||||
}
|
||||
if (bufsize == 0 || !(f = fopen(path, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
line = NULL;
|
||||
linesize = 0;
|
||||
found = 0;
|
||||
while (found == 0 && (getline(&line, &linesize, f)) != -1) {
|
||||
if ((comment = strchr(line, '#'))) *comment = '\0';
|
||||
name = strtok_r(line, " \t\r\n\v", &tok);
|
||||
number = strtok_r(NULL, " \t\r\n\v", &tok);
|
||||
if (name && number && protonum == atoi(number)) {
|
||||
if (!memccpy(buf, name, '\0', bufsize)) {
|
||||
strcpy(buf, "");
|
||||
break;
|
||||
}
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
if (ferror(f)) {
|
||||
errno = ferror(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
if (!found) return -1;
|
||||
return 0;
|
||||
}
|
|
@ -23,117 +23,12 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/servicestxt.h"
|
||||
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/servicestxt.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static textwindows noinline char *GetNtServicesTxtPath(char *pathbuf,
|
||||
uint32_t size) {
|
||||
const char *const kWinHostsPath = "\\drivers\\etc\\services";
|
||||
uint32_t len = GetSystemDirectoryA(&pathbuf[0], size);
|
||||
if (len && len + strlen(kWinHostsPath) + 1 < size) {
|
||||
if (pathbuf[len] == '\\') pathbuf[len--] = '\0';
|
||||
memcpy(&pathbuf[len], kWinHostsPath, strlen(kWinHostsPath) + 1);
|
||||
return &pathbuf[0];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens and searches /etc/services to find name for a given port.
|
||||
*
|
||||
* format of /etc/services is like this:
|
||||
*
|
||||
* # comment
|
||||
* # NAME PORT/PROTOCOL ALIASES
|
||||
* ftp 21/tcp
|
||||
* fsp 21/udp fspd
|
||||
* ssh 22/tcp
|
||||
*
|
||||
* @param servport is the port number
|
||||
* @param servproto is a NULL-terminated string (eg "tcp", "udp")
|
||||
* (if servproto is an empty string,
|
||||
* if is filled with the first matching
|
||||
* protocol)
|
||||
* @param servprotolen the size of servproto
|
||||
* @param buf is a buffer to store the official name of the service
|
||||
* @param bufsize is the size of buf
|
||||
* @param filepath is the location of the services file
|
||||
* (if NULL, uses /etc/services)
|
||||
* @return 0 on success, -1 on error
|
||||
*
|
||||
* @note aliases are not read from the file.
|
||||
*/
|
||||
int LookupServicesByPort(const int servport, char *servproto,
|
||||
size_t servprotolen, char *buf, size_t bufsize,
|
||||
const char *filepath) {
|
||||
FILE *f;
|
||||
char *line;
|
||||
char pathbuf[PATH_MAX];
|
||||
const char *path;
|
||||
size_t linesize;
|
||||
int found;
|
||||
char *name, *port, *proto, *comment, *tok;
|
||||
|
||||
if (!(path = filepath)) {
|
||||
path = "/etc/services";
|
||||
if (IsWindows()) {
|
||||
path =
|
||||
firstnonnull(GetNtServicesTxtPath(pathbuf, ARRAYLEN(pathbuf)), path);
|
||||
}
|
||||
}
|
||||
|
||||
if (servprotolen == 0 || bufsize == 0 || !(f = fopen(path, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
line = NULL;
|
||||
linesize = 0;
|
||||
found = 0;
|
||||
strcpy(buf, "");
|
||||
|
||||
while (found == 0 && (getline(&line, &linesize, f)) != -1) {
|
||||
if ((comment = strchr(line, '#'))) *comment = '\0';
|
||||
name = strtok_r(line, " \t\r\n\v", &tok);
|
||||
port = strtok_r(NULL, "/ \t\r\n\v", &tok);
|
||||
proto = strtok_r(NULL, " \t\r\n\v", &tok);
|
||||
if (name && port && proto && servport == atoi(port)) {
|
||||
if (!servproto[0] || strncasecmp(proto, servproto, servprotolen) == 0) {
|
||||
if (!servproto[0] && !memccpy(servproto, proto, '\0', servprotolen)) {
|
||||
strcpy(servproto, "");
|
||||
break;
|
||||
}
|
||||
if (!memccpy(buf, name, '\0', bufsize)) {
|
||||
strcpy(buf, "");
|
||||
break;
|
||||
}
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
|
||||
if (ferror(f)) {
|
||||
errno = ferror(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (!found) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens and searches /etc/services to find port for a given name.
|
||||
|
@ -149,9 +44,7 @@ int LookupServicesByPort(const int servport, char *servproto,
|
|||
* @param bufsize is the size of buf
|
||||
* @param filepath is the location of services file
|
||||
* (if NULL, uses /etc/services)
|
||||
* @return -1 on error, or
|
||||
* positive port number
|
||||
*
|
||||
* @return -1 on error, or positive port number
|
||||
* @note aliases are read from file for comparison, but not returned.
|
||||
* @see LookupServicesByPort
|
||||
*/
|
||||
|
@ -165,7 +58,6 @@ int LookupServicesByName(const char *servname, char *servproto,
|
|||
size_t linesize;
|
||||
int found, result;
|
||||
char *name, *port, *proto, *alias, *comment, *tok;
|
||||
|
||||
if (!(path = filepath)) {
|
||||
path = "/etc/services";
|
||||
if (IsWindows()) {
|
||||
|
@ -173,7 +65,6 @@ int LookupServicesByName(const char *servname, char *servproto,
|
|||
firstnonnull(GetNtServicesTxtPath(pathbuf, ARRAYLEN(pathbuf)), path);
|
||||
}
|
||||
}
|
||||
|
||||
if (servprotolen == 0 || !(f = fopen(path, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -182,7 +73,6 @@ int LookupServicesByName(const char *servname, char *servproto,
|
|||
found = 0;
|
||||
result = -1;
|
||||
if (buf && bufsize != 0) strcpy(buf, "");
|
||||
|
||||
while (found == 0 && (getline(&line, &linesize, f)) != -1) {
|
||||
if ((comment = strchr(line, '#'))) *comment = '\0';
|
||||
name = strtok_r(line, " \t\r\n\v", &tok);
|
||||
|
@ -192,7 +82,6 @@ int LookupServicesByName(const char *servname, char *servproto,
|
|||
alias = name;
|
||||
while (alias && strcasecmp(alias, servname) != 0)
|
||||
alias = strtok_r(NULL, " \t\r\n\v", &tok);
|
||||
|
||||
if (alias) /* alias matched with servname */
|
||||
{
|
||||
if (!servproto[0] || strncasecmp(proto, servproto, servprotolen) == 0) {
|
||||
|
@ -211,14 +100,11 @@ int LookupServicesByName(const char *servname, char *servproto,
|
|||
}
|
||||
}
|
||||
free(line);
|
||||
|
||||
if (ferror(f)) {
|
||||
errno = ferror(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if (!found) return -1;
|
||||
|
||||
return result;
|
||||
}
|
108
libc/dns/lookupservicesbyport.c
Normal file
108
libc/dns/lookupservicesbyport.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ This is free and unencumbered software released into the public domain. │
|
||||
│ │
|
||||
│ Anyone is free to copy, modify, publish, use, compile, sell, or │
|
||||
│ distribute this software, either in source code form or as a compiled │
|
||||
│ binary, for any purpose, commercial or non-commercial, and by any │
|
||||
│ means. │
|
||||
│ │
|
||||
│ In jurisdictions that recognize copyright laws, the author or authors │
|
||||
│ of this software dedicate any and all copyright interest in the │
|
||||
│ software to the public domain. We make this dedication for the benefit │
|
||||
│ of the public at large and to the detriment of our heirs and │
|
||||
│ successors. We intend this dedication to be an overt act of │
|
||||
│ relinquishment in perpetuity of all present and future rights to this │
|
||||
│ software under copyright law. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR │
|
||||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/dns/servicestxt.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
/**
|
||||
* Opens and searches /etc/services to find name for a given port.
|
||||
*
|
||||
* The format of /etc/services is like this:
|
||||
*
|
||||
* # comment
|
||||
* # NAME PORT/PROTOCOL ALIASES
|
||||
* ftp 21/tcp
|
||||
* fsp 21/udp fspd
|
||||
* ssh 22/tcp
|
||||
*
|
||||
* @param servport is the port number
|
||||
* @param servproto is a NULL-terminated string (eg "tcp", "udp")
|
||||
* (if servproto is an empty string,
|
||||
* if is filled with the first matching
|
||||
* protocol)
|
||||
* @param servprotolen the size of servproto
|
||||
* @param buf is a buffer to store the official name of the service
|
||||
* @param bufsize is the size of buf
|
||||
* @param filepath is the location of the services file
|
||||
* (if NULL, uses /etc/services)
|
||||
* @return 0 on success, -1 on error
|
||||
* @note aliases are not read from the file.
|
||||
*/
|
||||
int LookupServicesByPort(const int servport, char *servproto,
|
||||
size_t servprotolen, char *buf, size_t bufsize,
|
||||
const char *filepath) {
|
||||
FILE *f;
|
||||
char *line;
|
||||
char pathbuf[PATH_MAX];
|
||||
const char *path;
|
||||
size_t linesize;
|
||||
int found;
|
||||
char *name, *port, *proto, *comment, *tok;
|
||||
if (!(path = filepath)) {
|
||||
path = "/etc/services";
|
||||
if (IsWindows()) {
|
||||
path =
|
||||
firstnonnull(GetNtServicesTxtPath(pathbuf, ARRAYLEN(pathbuf)), path);
|
||||
}
|
||||
}
|
||||
if (servprotolen == 0 || bufsize == 0 || !(f = fopen(path, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
line = NULL;
|
||||
linesize = 0;
|
||||
found = 0;
|
||||
strcpy(buf, "");
|
||||
while (found == 0 && (getline(&line, &linesize, f)) != -1) {
|
||||
if ((comment = strchr(line, '#'))) *comment = '\0';
|
||||
name = strtok_r(line, " \t\r\n\v", &tok);
|
||||
port = strtok_r(NULL, "/ \t\r\n\v", &tok);
|
||||
proto = strtok_r(NULL, " \t\r\n\v", &tok);
|
||||
if (name && port && proto && servport == atoi(port)) {
|
||||
if (!servproto[0] || strncasecmp(proto, servproto, servprotolen) == 0) {
|
||||
if (!servproto[0] && !memccpy(servproto, proto, '\0', servprotolen)) {
|
||||
strcpy(servproto, "");
|
||||
break;
|
||||
}
|
||||
if (!memccpy(buf, name, '\0', bufsize)) {
|
||||
strcpy(buf, "");
|
||||
break;
|
||||
}
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
if (ferror(f)) {
|
||||
errno = ferror(f);
|
||||
return -1;
|
||||
}
|
||||
fclose(f);
|
||||
if (!found) return -1;
|
||||
return 0;
|
||||
}
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define COSMOPOLITAN_LIBC_DNS_PROTOTXT_H_
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
@ -10,6 +9,7 @@ int LookupProtoByNumber(const int, char *, size_t, const char *)
|
|||
paramsnonnull((2));
|
||||
int LookupProtoByName(const char *, char *, size_t, const char *)
|
||||
paramsnonnull((1, 2));
|
||||
char *GetNtProtocolsTxtPath(char *, uint32_t);
|
||||
|
||||
/* TODO: implement like struct HostsTxt? */
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/calls/calls.h"
|
||||
|
@ -52,7 +51,6 @@
|
|||
* @param name is a reversed IP address string ending with .in-addr.arpa
|
||||
* @param buf to store the obtained hostname if any
|
||||
* @param bufsize is size of buf
|
||||
*
|
||||
* @return 0 on success, or -1 w/ errno
|
||||
* @error EAFNOSUPPORT, ENETDOWN, ENAMETOOLONG, EBADMSG
|
||||
*/
|
||||
|
@ -63,7 +61,6 @@ int ResolveDnsReverse(const struct ResolvConf *resolvconf, int af,
|
|||
struct DnsHeader h, h2;
|
||||
uint8_t *p, *pe, msg[512];
|
||||
uint16_t rtype, rclass, rdlength;
|
||||
|
||||
if (af != AF_INET && af != AF_UNSPEC) return eafnosupport();
|
||||
if (!resolvconf->nameservers.i) return 0;
|
||||
memset(&h, 0, sizeof(h));
|
||||
|
@ -76,7 +73,6 @@ int ResolveDnsReverse(const struct ResolvConf *resolvconf, int af,
|
|||
q.qclass = DNS_CLASS_IN;
|
||||
memset(msg, 0, sizeof(msg));
|
||||
SerializeDnsHeader(msg, &h);
|
||||
|
||||
if ((n = SerializeDnsQuestion(msg + 12, 500, &q)) == -1) return -1;
|
||||
if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) return -1;
|
||||
if (sendto(fd, msg, 12 + n, 0, resolvconf->nameservers.p,
|
||||
|
@ -103,7 +99,6 @@ int ResolveDnsReverse(const struct ResolvConf *resolvconf, int af,
|
|||
rclass = READ16BE(p), p += 2;
|
||||
/* ttl */ p += 4;
|
||||
rdlength = READ16BE(p), p += 2;
|
||||
|
||||
if (p + rdlength <= pe && rtype == DNS_TYPE_PTR &&
|
||||
rclass == DNS_CLASS_IN) {
|
||||
if (strnlen((char *)p, pe - p) + 1 > bufsize)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
│ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
|
||||
│ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR │
|
||||
│ OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define COSMOPOLITAN_LIBC_DNS_SERVICESTXT_H_
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
|
@ -10,6 +9,7 @@ int LookupServicesByPort(const int, char *, size_t, char *, size_t,
|
|||
const char *) paramsnonnull((2, 4));
|
||||
int LookupServicesByName(const char *, char *, size_t, char *, size_t,
|
||||
const char *) paramsnonnull((1, 2));
|
||||
char *GetNtServicesTxtPath(char *, uint32_t);
|
||||
|
||||
/* TODO: implement like struct HostsTxt? */
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
/**
|
||||
* Prints stack frames with symbols.
|
||||
*
|
||||
* PrintBacktraceUsingSymbols(STDOUT_FILENO, NULL, GetSymbolTable());
|
||||
* PrintBacktraceUsingSymbols(STDOUT_FILENO, NULL, GetSymbolTable());
|
||||
*
|
||||
* @param f is output stream
|
||||
* @param bp is rbp which can be NULL to detect automatically
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "libc/log/internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
|
||||
/**
|
||||
* Prints initial part of fatal message.
|
||||
|
@ -31,18 +30,21 @@
|
|||
* @see __start_fatal_ndebug()
|
||||
*/
|
||||
relegated void __start_fatal(const char *file, int line) {
|
||||
char s[16 + 16 + 16 + 16 + PATH_MAX + 16 + NAME_MAX + 16], *p;
|
||||
p = stpcpy(s, CLS);
|
||||
p = stpcpy(p, RED);
|
||||
bool colorful;
|
||||
char s[16 + 16 + 16 + 16 + PATH_MAX + 16 + NAME_MAX + 16], *p = s;
|
||||
colorful = cancolor();
|
||||
*p++ = '\r';
|
||||
if (colorful) p = stpcpy(p, "\e[J\e[30;101m");
|
||||
p = stpcpy(p, "error");
|
||||
p = stpcpy(p, BLUE1);
|
||||
p = stpcpy(p, ":");
|
||||
if (colorful) p = stpcpy(p, "\e[94;49m");
|
||||
*p++ = ':';
|
||||
p = stpcpy(p, file);
|
||||
p = stpcpy(p, ":");
|
||||
*p++ = ':';
|
||||
p += int64toarray_radix10(line, p);
|
||||
p = stpcpy(p, ":");
|
||||
*p++ = ':';
|
||||
p = stpcpy(p, program_invocation_short_name);
|
||||
p = stpcpy(p, RESET);
|
||||
p = stpcpy(p, ": ");
|
||||
if (colorful) p = stpcpy(p, "\e[0m");
|
||||
*p++ = ':';
|
||||
*p++ = ' ';
|
||||
write(2, s, p - s);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,9 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
||||
/**
|
||||
|
@ -27,8 +28,11 @@
|
|||
* @see __start_fatal()
|
||||
*/
|
||||
relegated void __start_fatal_ndebug(void) {
|
||||
if (cancolor()) __print_string("\r\e[J");
|
||||
__print_string("error:");
|
||||
__print_string(program_invocation_name);
|
||||
__print_string(": ");
|
||||
char s[16 + 16 + 16 + 16 + PATH_MAX + 16], *p = s;
|
||||
*p++ = '\r';
|
||||
if (cancolor()) p = stpcpy(p, "\e[J");
|
||||
p = stpcpy(p, "error:");
|
||||
p = stpcpy(p, program_invocation_name);
|
||||
p = stpcpy(p, ": ");
|
||||
write(2, s, p - s);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue