mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
Add protoent and netent (#209)
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.
This commit is contained in:
parent
c002e4ba76
commit
e99a4dcc8c
16 changed files with 713 additions and 124 deletions
|
@ -7,6 +7,19 @@ 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 */
|
||||
|
@ -23,6 +36,18 @@ struct servent {
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue