mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 15:03:34 +00:00
The implementations of the getproto* functions follow from the getserv* functions: same static name allocation, same type of internal function that opens a file to search, aliases are not written to the struct, same type of error handling/returns. This changes also fixes a getaddrinfo AI_PASSIVE memory error. When getaddrinfo is passed name = NULL and AI_PASSIVE in hints->ai_flags, it was setting the s_addr value to INADDR_ANY but *not* returning the addrinfo pointer via *res = ai. This caused a free(NULL) memory error when the caller tried to free res, because the caller expects res to be a valid pointer to a struct addrinfo. Our non-standard API parseport() has been updated to use strtoimax. strtoimax has an extra parameter endptr to store where the parsing was terminated. endptr is used in parseport to check if the provided string was valid.
65 lines
1.8 KiB
C
65 lines
1.8 KiB
C
#ifndef COSMOPOLITAN_LIBC_DNS_ENT_H_
|
|
#define COSMOPOLITAN_LIBC_DNS_ENT_H_
|
|
#include "libc/dns/dns.h"
|
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
extern int h_errno;
|
|
|
|
struct netent {
|
|
char *n_name; /* official network name */
|
|
char **n_aliases; /* alias list */
|
|
int n_addrtype; /* net address type */
|
|
uint32_t n_net; /* network number */
|
|
};
|
|
|
|
struct protoent {
|
|
char *p_name; /* official protocol name */
|
|
char **p_aliases; /* alias list */
|
|
int p_proto; /* protocol number */
|
|
};
|
|
|
|
struct hostent {
|
|
char *h_name; /* official name of host */
|
|
char **h_aliases; /* alias list */
|
|
int h_addrtype; /* host address type */
|
|
int h_length; /* length of address */
|
|
char **h_addr_list; /* list of addresses */
|
|
};
|
|
#define h_addr h_addr_list[0]
|
|
|
|
struct servent {
|
|
char *s_name; /* official service name */
|
|
char **s_aliases; /* alias list */
|
|
int s_port; /* port number (in network byte order) */
|
|
char *s_proto; /* protocol to use */
|
|
};
|
|
|
|
struct netent *getnetent(void);
|
|
struct netent *getnetbyname(const char *);
|
|
struct netent *getnetbyaddr(uint32_t, int);
|
|
void setnetent(int);
|
|
void endnetent(void);
|
|
|
|
struct protoent *getprotoent(void);
|
|
struct protoent *getprotobyname(const char *);
|
|
struct protoent *getprotobynumber(int);
|
|
void setprotoent(int);
|
|
void endprotoent(void);
|
|
|
|
struct hostent *gethostent(void);
|
|
struct hostent *gethostbyname(const char *);
|
|
struct hostent *gethostbyaddr(const void *, socklen_t, int);
|
|
void sethostent(int);
|
|
void endhostent(void);
|
|
|
|
struct servent *getservent(void);
|
|
struct servent *getservbyname(const char *, const char *);
|
|
struct servent *getservbyport(int, const char *);
|
|
void setservent(int);
|
|
void endservent(void);
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_DNS_ENT_H_ */
|