KolibriLib
Loading...
Searching...
No Matches
network.hpp
1#ifndef __NETWORK_H__
2#define __NETWORK_H__
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <sys/ksys.h>
7
8#include "childWindow.hpp"
9
12namespace KolibriLib
13{
14
16 namespace Network
17 {
18
20 namespace Devices
21 {
25 {
26 int amount;
27 asm_inline(
28 "int $0x40"
29 :"=a"(amount)
30 :"a"(74), "b"(-1)
31 );
32 return amount;
33 }
34
38 int GetDeviceType(int device)
39 {
40 int type;
41 asm_inline(
42 "int $0x40"
43 :"=a"(type)
44 :"a"(74), "b"(0)
45 );
46 return type;
47 }
48
52 std::string GetDeviceName(int Device)
53 {
54 int abc;
55 void *buff = malloc(64);
56 asm_inline(
57 "int $0x40"
58 :"=a"(abc)
59 :"a"(74), "b"((1 << 16) + Device), "c"(buff)
60 );
61 return std::string((char*)buff);
62 }
63
64 bool ResetDevice(unsigned short Device)
65 {
66 int error;
67 void *ptr = malloc(64);
68 asm_inline(
69 "int $0x40"
70 :"=a"(error)
71 :"a"(74), "b"((2 << 16) + Device), "c"(ptr)
72 );
73 return error;
74 }
75 } // namespace Devices
76
77
79 namespace Socket
80 {
81 #include <sys/socket.h>
82
84 enum Domain
85 {
86 IPv4 = 2,
87 IPv6 = 10
88 };
91 {
92 Stream = 1,
93 DGram = 2,
94 RAW = 3
95 };
96
99 {
100 PROTOCOL_IP = 0,
101 PROTOCOL_CMP = 1,
102 PROTOCOL_TCP = 6,
103 PROTOCOL_UDP = 17,
104 PROTOCOL_RAW = 255
105 };
106
112 inline int OpenSocket(int domain = IPv4, int SocetType = Stream, int protocol = PROTOCOL_IP)
113 {
114 int Socket = socket(domain, SocetType, protocol);
115
116 if(err_code == -1)
117 {
118 childWindow::ErrorWindow("He yдaлocь открыть сокет");
119 }
120
121 return Socket;
122 }
123
127 bool CloseSocket(int Socket)
128 {
129 int a = close(Socket);
130 if(a == -1)
131 {
132 return false;
133 }
134 return true;
135 }
136
137 bool Bind(int Socket)
138 {
139 //bind(Socket, );
140 }
141
142 } // namespace Socket
143
144 } // namespace network
145
146} // namespace KolibriLib
147
148
149#endif // __NETWORK_H__
int GetDeviceType(int device)
Получить тип устройства
Definition network.hpp:38
int GetDevicesAmount()
Получить кол-во сетевых устройств
Definition network.hpp:24
std::string GetDeviceName(int Device)
Получить имя устройства
Definition network.hpp:52
bool CloseSocket(int Socket)
Закрыть сокет
Definition network.hpp:127
int OpenSocket(int domain=IPv4, int SocetType=Stream, int protocol=PROTOCOL_IP)
Окрыть сокет
Definition network.hpp:112
SocetTypes
Список типов сокета
Definition network.hpp:91
Protocols
Список протоколов
Definition network.hpp:99
void ErrorWindow(std::string ErrorMessage)
окошко с ошибкой
Definition childWindow.hpp:92
Основное пространство имён
Definition base.hpp:17