2015-07-22 20:32:54 +02:00
|
|
|
#ifndef INCLUDE_SOCKET_H
|
|
|
|
#define INCLUDE_SOCKET_H
|
2015-08-04 17:48:36 +02:00
|
|
|
#print "[include <socket.h>]\n"
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#ifndef INCLUDE_KOLIBRI_H
|
|
|
|
#include "../lib/kolibri.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SOCK_STREAM 1
|
|
|
|
#define SOCK_DGRAM 2
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
#define AF_INET4 2
|
2015-07-22 20:32:54 +02:00
|
|
|
|
|
|
|
#define MSG_PEEK 0x02
|
|
|
|
#define MSG_DONTWAIT 0x40
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
struct SockAddr
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
2021-11-18 00:43:09 +01:00
|
|
|
word sin_family;
|
|
|
|
char data[14];
|
|
|
|
};
|
2015-07-22 20:32:54 +02:00
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = domain
|
|
|
|
// edx = type
|
|
|
|
// esi = protocol
|
|
|
|
inline fastcall dword socket_open(ECX, EDX, ESI)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 0
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
2021-11-18 00:43:09 +01:00
|
|
|
}
|
2015-07-22 20:32:54 +02:00
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
inline fastcall dword socket_close(ECX)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 1
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
// edx = pointer to sockaddr structure
|
|
|
|
// esi = length of sockaddr structure
|
|
|
|
inline fastcall dword socket_bind(ECX, EDX, ESI)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 2
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
// edx = backlog
|
|
|
|
inline fastcall dword socket_listen(ECX, EDX)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 3
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
// edx = pointer to sockaddr structure
|
|
|
|
// esi = length of sockaddr structure
|
|
|
|
inline fastcall dword socket_connect(ECX, EDX, ESI)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 4
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
// edx = pointer to sockaddr structure
|
|
|
|
// esi = length of sockaddr structure
|
|
|
|
inline fastcall dword socket_accept(ECX, EDX, ESI)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 5
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
// edx = pointer to buffer
|
|
|
|
// esi = length of buffer
|
|
|
|
// edi = flags
|
|
|
|
inline fastcall dword socket_send(ECX, EDX, ESI, EDI)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 6
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
2021-11-18 00:43:09 +01:00
|
|
|
// ecx = socket number
|
|
|
|
// edx = pointer to buffer
|
|
|
|
// esi = length of buffer
|
|
|
|
// edi = flags
|
|
|
|
inline fastcall dword socket_receive(ECX, EDX, ESI, EDI)
|
2015-07-22 20:32:54 +02:00
|
|
|
{
|
|
|
|
$mov eax, 75
|
2021-11-18 00:43:09 +01:00
|
|
|
$mov bl, 7
|
2015-07-22 20:32:54 +02:00
|
|
|
$int 0x40
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|