Subversion Repositories Kolibri OS

Rev

Rev 3139 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3139 Rev 3835
Line 1... Line 1...
1
Cosaè implementato
1
eax = 74 - Work directly with network interface
2
==================
2
ebx = -1 (Get number of active network devices)
Line -... Line 3...
-
 
3
 
3
 
4
    out:
Line 4... Line -...
4
Le seguenti feature sono presenti nel codice stack TCP/IP:
-
 
5
 
-
 
6
  IP layer.
-
 
7
  ICMP.
-
 
8
  TCP layer.
-
 
9
  UDP layer.
-
 
10
  local loopback.
5
        eax = number of active network devices 
11
  Realtek 8029 PCI ethernet interface.
-
 
12
  Realtek 8139 PCI ethernet interface.
-
 
13
  Intel i8255x PCI ethernet interface.
-
 
Line 14... Line 6...
14
  Dynamic ARP table.
6
 
Line 15... Line -...
15
  PPP dialer
-
 
16
 
7
bh = device number, for all following functions !
17
E sono implementate le seguenti applicazioni:
-
 
18
 
8
 
19
  Server HTTP
-
 
20
  Telnet
-
 
21
  Client POP
-
 
Line 22... Line -...
22
  DNS Name resolver
-
 
23
  Server MP3
-
 
24
  Client TFTP
9
bl = 0 (Get device type)
Line -... Line 10...
-
 
10
 
-
 
11
    out:
-
 
12
        eax = device type number 
-
 
13
 
-
 
14
bl = 1 (Get device name)
Line 25... Line 15...
25
  Client IRC
15
 
26
 
-
 
Line -... Line 16...
-
 
16
    in:
27
Vi sono inoltre applicazioni sperimentali, per los terming di musica e
17
        ecx = pointer to 64 byte buffer 
28
per la comunicazione via socket, in fase di sviluppo vi è anche un
18
    out:
29
browser web.
19
        name is copied into the buffer
Line -... Line 20...
-
 
20
        eax = -1 on error 
Line -... Line 21...
-
 
21
 
30
 
22
bl = 2 (Reset the device)
-
 
23
 
31
 
24
    in
Line 32... Line 25...
32
Cosa non è implementato
25
        none 
Line -... Line 26...
-
 
26
    out
Line 33... Line 27...
33
=======================
27
        eax = -1 on error 
34
 
28
 
Line 35... Line -...
35
Il layer IP non processa le opzioni dello header.
-
 
36
Il layer IP non supporta il routing.
-
 
37
Non è supportata la 'Packet fragmentation'.
29
bl = 3 (Stop device)
38
 
-
 
Line -... Line 30...
-
 
30
 
-
 
31
    in
39
 
32
        none 
40
Come configurare Kolibri per il PPP
33
    out
-
 
34
        eax = -1 on error 
-
 
35
 
Line 41... Line 36...
41
===================================
36
TO BE FIGURED OUT
42
 
-
 
Line 43... Line -...
43
Vedi ppp.txt
-
 
44
 
-
 
45
 
-
 
46
Come configurare Kolibri per l'Ethernet
-
 
47
=======================================
-
 
48
 
-
 
49
Inanzitutto è necessario possedere una scheda ethernet supportata e
-
 
50
installata, o presente sulla scheda madre. Se non si è certi del tipo di
-
 
51
hardware, si può provare a configurare lo stack. Se l'hardware è
-
 
52
supportato allora verrà notificato e configurato correttamente.
-
 
53
 
-
 
54
Setting Up the ARP Table
-
 
55
------------------------
-
 
56
 
-
 
57
Kolibri's ARP table is dynamically created and maintained; You can see what
-
 
58
hosts Kolibri has communicated with by running the ARPSTAT application.
-
 
59
 
-
 
60
Enabling Ethernet
-
 
61
-----------------
-
 
62
 
-
 
63
Boot Kolibri, then select STACKCFG from the NET menu.
-
 
64
Press the 'Read' Button, then select 'Packet Driver'.
-
 
65
Press 'Change' next to the IP address, and enter the IP address you want
-
 
66
to use. Make sure it is on the same sub-net as the LAN to which you are
-
 
67
connected.
-
 
68
Press 'Apply' to action the changes.
-
 
69
Close the program.
-
 
70
 
-
 
71
 
-
 
72
The stack is now running, which you can test by pinging Kolibri from a
-
 
73
remote host.
-
 
74
 
-
 
75
 
-
 
76
The simplest way to connect two PC's together is using a 'Null Modem'
-
 
77
Ethernet cable. These simply cross certain wires over. They can be
-
 
78
purchased from PC stores, but are simple to make. Details can be found
-
 
79
on the web. Look on google for 'ethernet cross over cable' or similar.
-
 
80
 
-
 
81
 
-
 
82
How to use TCP/IP locally, with no Network
-
 
83
==========================================
-
 
84
 
-
 
85
Kolibri supports a form of local loopback that means applications on the
-
 
86
same PC can communicate with each other via sockets as though they
-
 
87
were on separate hosts. To connect to an application on the same machine,
-
 
88
specify the local IP address as the destination address. You do not even
-
 
89
need to configure the stack for ethernet; local loopback will work without
-
 
90
any network hardware. It's great for development and testing.
-
 
91
 
-
 
92
 
-
 
93
Application Programming Interface
-
 
94
=================================
-
 
95
 
-
 
96
The developer can access the stack through interrupt 0x40, function 53.
-
 
97
The file TFTPC.ASM gives a good example of how to use the programming
-
 
98
interface ( at least, for UDP), but as network communication is complex
-
 
99
I'll give an overview.
-
 
100
 
-
 
101
 
-
 
102
Sockets
-
 
103
=======
-
 
104
 
-
 
105
Applications connect to each other and pass information between themselves
-
 
106
through a mechanism called a 'socket'. Sockets are end-points for
-
 
107
communication; You need one at each application to communicate.
-
 
108
 
-
 
109
Using sockets is a little like using files on an OS; You open them, read
-
 
110
and write to them, then close them. The only thing that makes life slightly
-
 
111
more complicated is that unlike with a file, you have something intelligent
-
 
112
at the other end ( which for example may not want to close when you do! )
-
 
113
 
-
 
114
Lets deal with the terminology before we go any further.
-
 
115
 
-
 
116
socket      A unique identifier used by the application for communication.
-
 
117
local port  A number that identifies this application on the local host.
-
 
118
            Ports are a way to allow multiple applications to communicate
-
 
119
            with other hosts without the data becoming mixed up. ( The
-
 
120
            technical term is 'multiplex' ). Port numbers are 16 bit.
-
 
121
remote port A number that identifies the application on the remote host
-
 
122
            to which we are communicating with. To the remote host, this is
-
 
123
            it's 'local port'. Port numbers are 16 bit.
-
 
124
IP Address  A 32 bit number that identifies the remote host PC that we are
-
 
125
            communicating with.
-
 
126
Passive     Refers to the mode by which a socket is opened; When opening in
-
 
127
            passive mode, the local PC is awaiting an incoming connection.
-
 
128
Active      Refers to the mode by which a socket is opened; When opening in
-
 
129
            active mode, the local PC will attempt to connect to a remote
-
 
130
            PC.
-
 
131
 
-
 
132
When you connect to a socket on a remote PC, you need to specify more than
-
 
133
just the IP address, otherwise the remote stack will not know to which
-
 
134
application it should send your data. You must fully qualify the address,
-
 
135
which means you specify the IP address and the port number. This would be
-
 
136
written like this
-
 
137
 
-
 
138
192.168.1.10:80   ; Connect to port 80 on the machine 192.168.1.10
-
 
139
 
-
 
140
Port numbers are important. Some are 'well known' and provide access to
-
 
141
common applications. For example port 80 is used by HTTP servers; That
-
 
142
way I can connect to a webserver on a host without having to find out
-
 
143
what port number the application is listening on.
-
 
144
 
-
 
145
This brings me to the way in which you open a socket; As I said earlier,
-
 
146
there are two modes, Passive and Active. A webserver would open a passive
-
 
147
socket, as it is waiting for incoming connection requests. A web browser
-
 
148
would open an active socket because it is attempting to connect to a
-
 
149
specified remote host.
-
 
150
 
-
 
151
 
-
 
152
Access to programming interface
-
 
153
===============================
-
 
154
The developer accesses the stack functions through interrupt 0x40,
-
 
155
function 53. Some functions may be accessed through function 52, but these
-
 
156
are mainly for stack configuration.
-
 
157
Here is a summary of the functions that you may use and the parameter
-
 
158
definitions.
-
 
159
 
-
 
160
 
-
 
161
Get Local IP Address
-
 
162
--------------------
-
 
163
eax = 52
-
 
164
ebx = 1
-
 
165
 
-
 
166
IP address returned in eax ( in internet byte order )
-
 
167
 
-
 
168
 
-
 
169
Write to stack input queue
-
 
170
--------------------------
-
 
171
eax = 52
-
 
172
ebx = 6
-
 
173
edx = number of bytes to write
-
 
174
esi = pointer to data ( in application space )
-
 
175
 
-
 
176
On return, eax holds 0 for OK, or 0xFFFFFFFF for error.
-
 
177
This interface is for slow network drivers only ( PPP, SLIP )
-
 
178
 
-
 
179
 
-
 
180
Read data from network output queue
-
 
181
-----------------------------------
-
 
182
eax = 52
-
 
183
ebx = 8
-
 
184
esi = pointer to data ( in application space )
-
 
185
 
-
 
186
On return, eax holds number of bytes transferred.
-
 
187
This interface is for slow network drivers only ( PPP, SLIP )
-
 
188
 
-
 
189
 
-
 
190
Open a UDP socket
-
 
191
-----------------
-
 
192
eax = 53
-
 
193
ebx = 0
-
 
194
ecx = local port
-
 
195
edx = remote port
-
 
196
esi = remote ip address ( in internet byte order )
-
 
197
 
-
 
198
The socket number allocated is returned in eax.
-
 
199
A return value of 0xFFFFFFFF means no socket could be opened.
-
 
200
 
-
 
201
 
37
 
202
Open a TCP socket
38
eax = 75 - Work with Sockets
-
 
39
 
-
 
40
These functions work like the ones found in UNIX (and windows)
Line 203... Line 41...
203
-----------------
41
for more info, please read http://beej.us/guide/bgnet/
Line 204... Line -...
204
eax = 53
-
 
205
ebx = 5
-
 
206
ecx = local port
-
 
207
edx = remote port
-
 
208
esi = remote ip address ( in internet byte order )
42
 
209
edi = mode : SOCKET_PASSIVE or SOCKET_ACTIVE  ( defined in stack.inc )
43
bl = 0 (Open Socket)
-
 
44
 
-
 
45
    in:
-
 
46
        ecx = domain
-
 
47
        edx = type
Line 210... Line 48...
210
 
48
        esi = protocol 
211
The socket number allocated is returned in eax.
-
 
Line 212... Line -...
212
A return value of 0xFFFFFFFF means no socket could be opened.
-
 
213
 
-
 
214
 
-
 
215
Close a socket (UDP Only )
49
    out:
216
--------------------------
50
        eax = socket number, -1 on error 
-
 
51
 
-
 
52
bl = 1 (Close Socket)
-
 
53
 
Line 217... Line 54...
217
eax = 53
54
    in:
Line 218... Line -...
218
ebx = 1
-
 
219
ecx = socket number
-
 
220
 
-
 
221
On return, eax holds 0 for OK, or 0xFFFFFFFF for error.
-
 
222
 
55
        ecx = socket number 
223
 
56
    out:
-
 
57
        eax = -1 on error 
-
 
58
 
-
 
59
bl = 2 (Bind)
-
 
60
 
Line 224... Line 61...
224
Close a socket (TCP Only )
61
    in:
225
--------------------------
-
 
Line 226... Line -...
226
eax = 53
-
 
227
ebx = 8
-
 
228
ecx = socket number
-
 
229
 
62
        ecx = socket number
230
On return, eax holds 0 for OK, or 0xFFFFFFFF for error.
63
        edx = pointer to sockaddr structure
231
 
64
        esi = length of sockaddr structure 
-
 
65
    out:
-
 
66
        eax = -1 on error 
232
 
67
 
Line 233... Line 68...
233
Poll socket
68
bl = 3 (Listen)
Line 234... Line -...
234
-----------
-
 
235
eax = 53
-
 
236
ebx = 2
-
 
237
ecx = socket number
-
 
238
 
69
 
239
On return, eax holds the number of bytes in the receive buffer.
70
    in:
-
 
71
        ecx = socket number
-
 
72
        edx = backlog 
-
 
73
    out:
-
 
74
        eax = -1 on error 
-
 
75
 
Line 240... Line -...
240
 
-
 
241
 
-
 
242
Read socket data
-
 
243
----------------
-
 
244
eax = 53
76
bl = 4 (connect)
245
ebx = 3
-
 
Line 246... Line -...
246
ecx = socket number
-
 
247
 
-
 
248
On return, eax holds the number of bytes remaining, bl holds a data byte.
-
 
249
 
77
 
250
 
78
    in:
251
Write to socket ( UDP only )
79
        ecx = socket number
252
----------------------------
80
        edx = pointer to sockaddr structure
-
 
81
        esi = length of sockaddr structure 
253
eax = 53
82
    out:
254
ebx = 4
83
        eax = -1 on error 
Line -... Line 84...
-
 
84
 
Line 255... Line -...
255
ecx = socket number
-
 
256
edx = number of bytes to write
-
 
257
esi = pointer to data ( in application space )
-
 
258
 
85
bl = 5 (accept)
259
On return, eax holds 0 for OK, or 0xFFFFFFFF for error.
86
 
260
 
-
 
261
 
-
 
262
Return socket status ( TCP only )
87
    in:
263
---------------------------------
88
        ecx = socket number
264
eax = 53
-
 
265
ebx = 6
-
 
266
ecx = socket number
-
 
267
 
-
 
268
On return, eax holds the sockets TCP status.
89
        edx = pointer to sockaddr structure
269
This function can be used to determine when a socket has actually connected
-
 
Line 270... Line 90...
270
to another socket - data cannot be written to a socket until the connection
90
        esi = length of sockaddr structure 
Line 271... Line -...
271
is established (TCB_ESTABLISHED). The states a socket can be in are defined
-
 
272
in stack.inc as TCB_
-
 
273
 
-
 
274
 
-
 
275
Write to socket ( TCP only )
-
 
276
----------------------------
91
    out:
277
eax = 53
92
        eax = socket number, -1 on error 
Line 278... Line -...
278
ebx = 7
-
 
279
ecx = socket number
-
 
280
edx = number of bytes to write
-
 
281
esi = pointer to data ( in application space )
93
 
Line 282... Line -...
282
 
-
 
283
On return, eax holds 0 for OK, or 0xFFFFFFFF for error.
-
 
284
 
94
bl = 6 (send)
285
 
95
 
286
Check port number
96
    in:
287
-----------------
97
        ecx = socket number
288
eax = 53
98
        edx = pointer to buffer
Line -... Line 99...
-
 
99
        esi = length of buffer
Line 289... Line 100...
289
ebx = 9
100
        edi = flags 
290
ecx = port number
101
    out:
Line 291... Line -...
291
 
-
 
292
This function is used to determine if a port number
-
 
293
is in use by any sockets as a local port number. Local
-
 
294
port numbers are normally unique.
-
 
295
 
102
        eax = -1 on error 
Line 296... Line 103...
296
On return, eax is 1 for port number not in use, 0 otherwise.
103
 
Line 297... Line -...
297
 
-
 
298
 
-
 
299
Opening a TCP socket in Kolibri
-
 
300
===============================
-
 
301
 
-
 
302
There are two ways to open a socket - Passive or Active.
-
 
303
 
-
 
304
In a Passive connection your application 'listens' for incoming
-
 
305
requests from remote applications. Typically this will be done when
-
 
Line 306... Line 104...
306
you are implementing a server application that allows any other
104
bl = 7 (receive)
Line -... Line 105...
-
 
105
 
-
 
106
    in:
Line -... Line 107...
-
 
107
        ecx = socket number
Line 307... Line 108...
307
application to connect to it. You would specify a 'known' local
108
        edx = pointer to buffer
308
port number, such as 80 for a web server. You would leave the
-
 
Line 309... Line -...
309
remote IP and remote port number as 0, which indicates any
-
 
310
remote application may connect.
-
 
311
 
-
 
312
Once the socket has been opened you would wait for an incoming
-
 
313
connection before doing anything. This can be by either checking
-
 
314
the socket status for TCB_ESTABLISHED, or waiting for data in the
-
 
Line 315... Line -...
315
receive buffer.
-
 
316
 
-
 
317
In an Active connection, you are making a connection to a specified
-
 
318
remote port. The remote IP and remote port parameters must be filled
-
 
319
in with non-zero values ( otherwise, what are you connecting to? ).
-
 
320
You also specify a unique local port number so the remote application
109
        esi = length of buffer
Line -... Line 110...
-
 
110
        edi = flags 
-
 
111
    out:
-
 
112
        eax = number of bytes copied, -1 on error 
Line 321... Line 113...
321
can uniquely identify you - after all, there may be several applications
113
 
322
on your machine connected to the same remote host. See below for finding
-
 
Line -... Line 114...
-
 
114
bl = 8 (set socket options)
323
a unique port number.
115
 
-
 
116
    in:
324
 
117
        ecx = socket number
-
 
118
        edx = level
-
 
119
        esi = optionname
-
 
120
        edi = ptr to buffer
325
 
121
 
-
 
122
The buffer's first dword is the length of the buffer, minus the first dword offcourse
Line -... Line 123...
-
 
123
 
-
 
124
    out:
-
 
125
        eax = -1 on error 
-
 
126
 
-
 
127
bl = 9 (get socket options
-
 
128
 
-
 
129
    in:
-
 
130
        ecx = socket number
-
 
131
        edx = level
-
 
132
        esi = optionname
-
 
133
        edi = ptr to buffer
Line -... Line 134...
-
 
134
 
-
 
135
The buffer's first dword is the length of the buffer, minus the first dword offcourse
326
How to find an unused local port number
136
 
-
 
137
    out:
-
 
138
        eax = -1 on error, socket option otherwise 
-
 
139
 
327
=======================================
140
TIP
Line 328... Line 141...
328
 
141
 
329
Typically when you are creating an active connection to a remote
142
when you import 'network.inc' and 'macros.inc' into your source code, you can use the following syntax to work with sockets:
330
socket you will want to choose a unique local port number. Local
143
 
331
port numbers normally start from 1000; The following code may
144
 
Line -... Line 145...
-
 
145
for example, to open a socket
-
 
146
 
-
 
147
mcall socket, AF_INET, SOCK_DGRAM,0
Line 332... Line 148...
332
be used to obtain an unused port number prior to making the
148
mov [socketnum], eax
333
open socket call.
149
 
334
 
150
then to connect to a server