forked from KolibriOS/kolibrios
Adding support for new stack to Menuet Lib
git-svn-id: svn://kolibrios.org@4248 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
6eee0d0789
commit
66a80ab62a
@ -7,6 +7,144 @@ extern "C" {
|
||||
|
||||
#include<menuet/os.h>
|
||||
|
||||
|
||||
// System functions
|
||||
#define _SOCKETF 75
|
||||
|
||||
// Socket subfunctions
|
||||
#define _OPENSF 0
|
||||
#define _CLOSESF 1
|
||||
#define _BINDSF 2
|
||||
#define _LISTENSF 3
|
||||
#define _CONNECTSF 4
|
||||
#define _ACCEPTSF 5
|
||||
#define _SENDSF 6
|
||||
#define _RECEIVESF 7
|
||||
|
||||
// Socket types
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
#define SOCK_RAW 3
|
||||
|
||||
// Socket options
|
||||
#define SO_NONBLOCK ((long)(1))
|
||||
|
||||
// IP protocols
|
||||
#define IPPROTO_IP 0
|
||||
#define IPPROTO_ICMP 1
|
||||
#define IPPROTO_TCP 6
|
||||
#define IPPROTO_UDP 17
|
||||
|
||||
// Address families
|
||||
#define AF_UNSPEC 0
|
||||
#define AF_LOCAL 1
|
||||
#define AF_INET 2 // IPv4
|
||||
#define AF_INET6 28 // IPv6 (not supported yet)
|
||||
|
||||
#define PF_UNSPEC AF_UNSPEC
|
||||
#define PF_LOCAL AF_LOCAL
|
||||
#define PF_INET4 AF_INET4
|
||||
#define PF_INET6 AF_INET6
|
||||
|
||||
// Flags for addrinfo
|
||||
#define AI_PASSIVE 1
|
||||
#define AI_CANONNAME 2
|
||||
#define AI_NUMERICHOST 4
|
||||
#define AI_NUMERICSERV 8
|
||||
#define AI_ADDRCONFIG 0x400
|
||||
|
||||
// Internal definition
|
||||
#define AI_SUPPORTED 0x40F
|
||||
|
||||
// For system function 76
|
||||
#define API_ETH ((int)(0))
|
||||
#define API_IPv4 ((int)(1))
|
||||
#define API_ICMP ((int)(2))
|
||||
#define API_UDP ((int)(3))
|
||||
#define API_TCP ((int)(4))
|
||||
#define API_ARP ((int)(5))
|
||||
#define API_PPPOE ((int)(6))
|
||||
|
||||
// Socket flags for user calls
|
||||
#define MSG_PEEK 0x02
|
||||
#define MSG_DONTWAIT 0x40
|
||||
|
||||
|
||||
struct in_addr {
|
||||
unsigned long s_addr;
|
||||
};
|
||||
|
||||
struct sockaddr {
|
||||
unsigned short sa_family; // address family, AF_xxx
|
||||
char sa_data[14]; // 14 bytes of protocol address
|
||||
};
|
||||
|
||||
struct sockaddr_in {
|
||||
short sin_family; // sa_family_t
|
||||
unsigned short sin_port; // in_port_t
|
||||
struct in_addr sin_addr;
|
||||
char sin_zero[8];
|
||||
};
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags; // bitmask of AI_*
|
||||
int longai_family; // PF_*
|
||||
int ai_socktype; //SOCK_*
|
||||
int ai_protocol; // 0 or IPPROTO_*
|
||||
int ai_addrlen; // length of ai_addr
|
||||
char *ai_canonname;
|
||||
struct sockaddr *ai_addr; // struct sockaddr*
|
||||
struct addrinfo *ai_next; // struct addrinfo*
|
||||
};
|
||||
|
||||
#define EAI_ADDRFAMILY 1
|
||||
#define EAI_AGAIN 2
|
||||
#define EAI_BADFLAGS 3
|
||||
#define EAI_FAIL 4
|
||||
#define EAI_FAMILY 5
|
||||
#define EAI_MEMORY 6
|
||||
#define EAI_NONAME 8
|
||||
#define EAI_SERVICE 9
|
||||
#define EAI_SOCKTYPE 10
|
||||
#define EAI_BADHINTS 12
|
||||
#define EAI_PROTOCOL 13
|
||||
#define EAI_OVERFLOW 14
|
||||
|
||||
// Socket error codes
|
||||
// Error Codes
|
||||
#define ENOBUFS 1
|
||||
#define EINPROGRESS 2
|
||||
#define EOPNOTSUPP 4
|
||||
#define EWOULDBLOCK 6
|
||||
#define ENOTCONN 9
|
||||
#define EALREADY 10
|
||||
#define EINVAL 11
|
||||
#define EMSGSIZE 12
|
||||
#define ENOMEM 18
|
||||
#define EADDRINUSE 20
|
||||
#define ECONNREFUSED 61
|
||||
#define ECONNRESET 52
|
||||
#define EISCONN 56
|
||||
#define ETIMEDOUT 60
|
||||
#define ECONNABORTED 53
|
||||
|
||||
|
||||
unsigned long inet_addr(char *cp);
|
||||
int socket(int domain, int type, int protocol);
|
||||
int close_socket(int s);
|
||||
int bind(int sockfd, struct sockaddr *my_addr, int addrlen);
|
||||
int listen(int s, int backlog);
|
||||
int connect(int sockfd, const struct sockaddr *serv_addr, int addrlen);
|
||||
int accept(int s, struct sockaddr *addr, int *addrlen);
|
||||
int send(int s, const void *buf, int len, int flags);
|
||||
int recv(int sockfd, void *buf, int len, int flags);
|
||||
// Review int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen);
|
||||
// Review int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen);
|
||||
// Add socketpair()
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
|
||||
#define __NET_stack_rd_cfg_word 0
|
||||
#define __NET_stack_get_ip 1
|
||||
#define __NET_stack_wr_cfg_word 2
|
||||
|
@ -36,7 +36,7 @@ typedef struct
|
||||
unsigned char c_char;
|
||||
unsigned char c_back;
|
||||
unsigned char c_color;
|
||||
} char_info_t __attribute__((packed));
|
||||
} char_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -1,5 +1,56 @@
|
||||
#include <menuet/net.h>
|
||||
|
||||
|
||||
unsigned long inet_addr(char *cp)
|
||||
{
|
||||
// Adapted from here http://stackoverflow.com/a/1684635
|
||||
unsigned long __ret;
|
||||
unsigned int c1,c2,c3,c4;
|
||||
sscanf(cp, "%d.%d.%d.%d", &c1,&c2,&c3,&c4);
|
||||
__ret = (unsigned long)c4+c3*256+c2*256*256+c1*256*256*256;
|
||||
return htonl(__ret);
|
||||
}
|
||||
|
||||
int socket(int domain, int type, int protocol)
|
||||
{
|
||||
int __ret;
|
||||
__asm__("int $0x40":"=a"(__ret):"a"(_SOCKETF),"b"(_OPENSF),"c"(domain),"d"(type),"S"(protocol));
|
||||
return __ret;
|
||||
}
|
||||
|
||||
int close_socket(int s)
|
||||
{
|
||||
int __ret;
|
||||
__asm__("int $0x40":"=a"(__ret):"a"(_SOCKETF),"b"(_CLOSESF),"c"(s));
|
||||
return __ret;
|
||||
}
|
||||
|
||||
|
||||
int connect(int sockfd, const struct sockaddr *serv_addr, int addrlen)
|
||||
{
|
||||
int __ret;
|
||||
__asm__("int $0x40":"=a"(__ret):"a"(_SOCKETF),"b"(_CONNECTSF),"c"(sockfd),"d"(serv_addr),"S"(addrlen));
|
||||
return __ret;
|
||||
}
|
||||
|
||||
int send(int s, const void *buf, int len, int flags)
|
||||
{
|
||||
int __ret;
|
||||
__asm__("int $0x40":"=a"(__ret):"a"(_SOCKETF),"b"(_SENDSF),"c"(s),"d"(buf),"S"(len),"D"(flags));
|
||||
return __ret;
|
||||
}
|
||||
|
||||
int recv(int sockfd, void *buf, int len, int flags)
|
||||
{
|
||||
int __ret;
|
||||
__asm__("int $0x40":"=a"(__ret):"a"(_SOCKETF),"b"(_RECEIVESF),"c"(sockfd),"d"(buf),"S"(len),"D"(flags));
|
||||
return __ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
__u32 __menuet__open_UDP_socket(__u32 local_port,__u32 remote_port,__u32 remote_ip)
|
||||
{
|
||||
__u32 __ret;
|
||||
|
Loading…
Reference in New Issue
Block a user