libc: more net stubs

This commit is contained in:
K. Lange 2021-03-25 15:52:19 +09:00
parent 487d0f3a6e
commit 020c3cdb3c
6 changed files with 75 additions and 1 deletions

View File

@ -0,0 +1,11 @@
#pragma once
#include <_cheader.h>
#include <stdint.h>
#include <sys/types.h>
_Begin_C_Header
#define INADDR_ANY (unsigned long int)0x0
_End_C_Header

23
base/usr/include/netdb.h Normal file
View File

@ -0,0 +1,23 @@
#pragma once
#include <_cheader.h>
#include <sys/socket.h>
_Begin_C_Header
extern int getnameinfo(const struct sockaddr *addr, socklen_t addrlen,
char *host, socklen_t hostlen,
char *serv, socklen_t servlen, int flags);
extern int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints,
struct addrinfo **res);
extern void freeaddrinfo(struct addrinfo *res);
#define NI_NUMERICHOST 1
#define NI_MAXHOST 255
_End_C_Header

View File

@ -18,6 +18,7 @@ _Begin_C_Header
#define SOL_SOCKET 0
#define SO_KEEPALIVE 1
#define SO_REUSEADDR 2
struct hostent {
char *h_name; /* official name of host */
@ -73,6 +74,10 @@ struct msghdr {
int msg_flags; /* flags on received message */
};
struct sockaddr_storage {
unsigned short ss_family;
char _ss_pad[128];
};
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
@ -100,6 +105,9 @@ extern int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
extern int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
extern int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
extern int connect(int sockfd, const struct sockaddr * addr, socklen_t addrlen);
extern int shutdown(int sockfd, int how);
_End_C_Header

View File

@ -37,4 +37,16 @@ typedef int clock_t;
extern clock_t clock(void);
#define CLOCKS_PER_SEC 1
struct timespec {
time_t tv_sec;
long tv_nsec;
};
typedef int clockid_t;
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
extern int clock_gettime(clockid_t clk_id, struct timespec *tp);
_End_C_Header

View File

@ -123,4 +123,7 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t
return -1;
}
int shutdown(int sockfd, int how) {
UNIMPLEMENTED;
return -1;
}

17
libc/time/clock_gettime.c Normal file
View File

@ -0,0 +1,17 @@
#include <time.h>
#include <errno.h>
#include <sys/time.h>
int clock_gettime(clockid_t clk_id, struct timespec *tp) {
if (clk_id < 0 || clk_id > 1) {
errno = EINVAL;
return -1;
}
struct timeval t;
gettimeofday(&t, NULL);
tp->tv_sec = t.tv_sec;
tp->tv_nsec = t.tv_usec * 1000;
return 0;
}