Hacked together things you really shouldn't push
This commit is contained in:
parent
0ca02a4bcf
commit
2bd723b597
12
toolchain/patches/newlib/toaru/sys/select.h
Normal file
12
toolchain/patches/newlib/toaru/sys/select.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _TOARU_SYS_SELECT_H
|
||||
#define _TOARU_SYS_SELECT_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
#undef /* _TOARU_SYS_SELECT_H */
|
106
userspace/lib/network.c
Normal file
106
userspace/lib/network.c
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* libnetwork
|
||||
*
|
||||
* Install me to /usr/lib/libnetwork.a
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "network.h"
|
||||
|
||||
static struct hostent _out_host;
|
||||
|
||||
#define UNIMPLEMENTED fprintf(stderr, "[libnetwork] Unimplemented: %s\n", __FUNCTION__)
|
||||
|
||||
struct hostent * gethostbyname(const char * name) {
|
||||
UNIMPLEMENTED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* All of these should just be reads. */
|
||||
ssize_t recv(int sockfd, void *buf, size_t len, int flags) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t send(int sockfd, const void *buf, size_t len, int flags) {
|
||||
UNIMPLEMENTED;
|
||||
return len;
|
||||
}
|
||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) {
|
||||
UNIMPLEMENTED;
|
||||
return len;
|
||||
}
|
||||
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int socket(int domain, int type, int protocol) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t htonl(uint32_t hostlong) {
|
||||
return ( (((hostlong) & 0xFF) << 24) | (((hostlong) & 0xFF00) << 8) | (((hostlong) & 0xFF0000) >> 8) | (((hostlong) & 0xFF000000) >> 24));
|
||||
}
|
||||
|
||||
uint16_t htons(uint16_t hostshort) {
|
||||
return ( (((hostshort) & 0xFF) << 8) | (((hostshort) & 0xFF00) >> 8) );
|
||||
}
|
||||
|
||||
uint32_t ntohl(uint32_t netlong) {
|
||||
return htonl(netlong);
|
||||
}
|
||||
|
||||
uint16_t ntohs(uint16_t netshort) {
|
||||
return htons(netshort);
|
||||
}
|
||||
|
||||
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int accept(int sockfd, struct sockaddr * addr, socklen_t * addrlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int listen(int sockfd, int backlog) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen) {
|
||||
UNIMPLEMENTED;
|
||||
return -1;
|
||||
}
|
||||
|
100
userspace/lib/network.h
Normal file
100
userspace/lib/network.h
Normal file
@ -0,0 +1,100 @@
|
||||
#ifndef _TOARU_SYS_SOCKET_H
|
||||
#define _TOARU_SYS_SOCKET_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define AF_INET 1
|
||||
#define AF_UNSPEC 0
|
||||
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
#define SOL_SOCKET 0
|
||||
|
||||
#define SO_KEEPALIVE 1
|
||||
|
||||
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 */
|
||||
};
|
||||
|
||||
struct hostent * gethostbyname(const char * name);
|
||||
|
||||
typedef size_t socklen_t;
|
||||
|
||||
struct sockaddr {
|
||||
unsigned short sa_family; // address family, AF_xxx
|
||||
char sa_data[14]; // 14 bytes of protocol address
|
||||
};
|
||||
|
||||
struct in_addr {
|
||||
unsigned long s_addr; // load with inet_pton()
|
||||
};
|
||||
|
||||
struct sockaddr_in {
|
||||
short sin_family; // e.g. AF_INET, AF_INET6
|
||||
unsigned short sin_port; // e.g. htons(3490)
|
||||
struct in_addr sin_addr; // see struct in_addr, below
|
||||
char sin_zero[8]; // zero this if you want to
|
||||
};
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags;
|
||||
int ai_family;
|
||||
int ai_socktype;
|
||||
int ai_protocol;
|
||||
socklen_t ai_addrlen;
|
||||
struct sockaddr *ai_addr;
|
||||
char *ai_canonname;
|
||||
struct addrinfo *ai_next;
|
||||
};
|
||||
|
||||
struct iovec { /* Scatter/gather array items */
|
||||
void *iov_base; /* Starting address */
|
||||
size_t iov_len; /* Number of bytes to transfer */
|
||||
};
|
||||
|
||||
struct msghdr {
|
||||
void *msg_name; /* optional address */
|
||||
socklen_t msg_namelen; /* size of address */
|
||||
struct iovec *msg_iov; /* scatter/gather array */
|
||||
size_t msg_iovlen; /* # elements in msg_iov */
|
||||
void *msg_control; /* ancillary data, see below */
|
||||
size_t msg_controllen; /* ancillary data buffer len */
|
||||
int msg_flags; /* flags on received message */
|
||||
};
|
||||
|
||||
|
||||
typedef uint32_t in_addr_t;
|
||||
typedef uint16_t in_port_t;
|
||||
|
||||
ssize_t recv(int sockfd, void *buf, size_t len, int flags);
|
||||
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
|
||||
ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
|
||||
|
||||
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
|
||||
ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen);
|
||||
ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
|
||||
|
||||
int socket(int domain, int type, int protocol);
|
||||
|
||||
uint32_t htonl(uint32_t hostlong);
|
||||
uint16_t htons(uint16_t hostshort);
|
||||
uint32_t ntohl(uint32_t netlong);
|
||||
uint16_t ntohs(uint16_t netshort);
|
||||
|
||||
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
|
||||
int accept(int sockfd, struct sockaddr * addr, socklen_t * addrlen);
|
||||
int listen(int sockfd, int backlog);
|
||||
int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int getpeername(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
|
||||
int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
|
||||
int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
#endif /* _TOARU_SYS_SOCKET_H */
|
Loading…
Reference in New Issue
Block a user