Network library: Difference between revisions
Sweetbread (talk | contribs) m (Added link to network.inc) |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 4: | Line 4: | ||
Their function and API closely resembles these functions on other platforms. <br> | Their function and API closely resembles these functions on other platforms. <br> | ||
Because of this, more information about these functions can be found in other guides suchs as [http://beej.us/guide/bgnet/ Beej's guide to network programming].<br><br> | Because of this, more information about these functions can be found in other guides suchs as [http://beej.us/guide/bgnet/ Beej's guide to network programming].<br><br> | ||
All structures and error codes you need for these functions can be found in network.inc (in programs folder on SVN).<br> | All structures and error codes you need for these functions can be found in network.inc (in programs folder on [http://websvn.kolibrios.org/filedetails.php?repname=Kolibri+OS&path=%2Fprograms%2Fnetwork.inc SVN]).<br> | ||
==inet_addr== | ==inet_addr== | ||
Line 45: | Line 45: | ||
* ptr to addrinfo struct hints (optional)<br> | * ptr to addrinfo struct hints (optional)<br> | ||
* ptr to result addrinfo struct<br> | * ptr to result addrinfo struct<br> | ||
Output: eax = 0 on success / one of EAI codes on error | Output: eax = 0 on success / one of EAI codes on error.<br> | ||
On success, the function will write the pointer to the addrinfo structure at the given address.<br> | |||
Structure definitions and error codes can be found in network.inc | |||
<br> | <br> | ||
Example: | Example: | ||
Line 83: | Line 85: | ||
Input: ptr to addrinfo struct<br> | Input: ptr to addrinfo struct<br> | ||
Output: /<br> | Output: /<br> | ||
[[Category:Manuals]] | |||
[[Category:Network]] | |||
[[Category:Сеть]] | |||
[[Category:Руководства]] | |||
[[Category:Libraries]] | |||
[[Category:Библиотеки]] |
Latest revision as of 12:39, 19 January 2023
Network Library
The KolibriOS network library implements some network related functions similar to those found in Unix/Windows.
Their function and API closely resembles these functions on other platforms.
Because of this, more information about these functions can be found in other guides suchs as Beej's guide to network programming.
All structures and error codes you need for these functions can be found in network.inc (in programs folder on SVN).
inet_addr
Convert the string from standard IPv4 dotted notation to integer IP addr.
Input: ptr to ASCIIZ string containing standard dotted IPv4 address.
Output: eax = converted IP address / -1 on error
Example:
; Code section:
invoke inet_addr ip_address
; eax should now be 0x0100A8C0
; Data section:
ip_address db '192.168.0.1', 0
inet_ntoa
Convert the Internet host address to standard IPv4 dotted notation.
Input: in_addr struct (see network.inc for struct)
Output: eax = pointer to resulting string (in static buffer)
; Code section:
invoke ntoa sockaddr1
; eax will now point to following data: db "192.168.0.1", 0
; Data section:
sockaddr1:
dw ? ; address family
dw ? ; port
dd 0x0100A8C0 ; IP address
rb 8 ; zero
ends
getaddrinfo
Get a list of IP addresses and port numbers for given host and service
Input:
- ptr to hostname (optional)
- ptr to servname (optional)
- ptr to addrinfo struct hints (optional)
- ptr to result addrinfo struct
Output: eax = 0 on success / one of EAI codes on error.
On success, the function will write the pointer to the addrinfo structure at the given address.
Structure definitions and error codes can be found in network.inc
Example:
; Code section
; resolve name
invoke getaddrinfo, hostname, 0, 0, result
; test for error
test eax, eax
jnz fail
; convert IP address to decimal notation
mov edi, [result]
addrloop:
mov eax, [edi+addrinfo.ai_addr]
invoke inet_ntoa, [eax+sockaddr_in.sin_addr]
; write result
invoke con_write_asciiz, eax
; advance to next item
mov edi, [edi+addrinfo.ai_next]
test edi, edi
jnz addrloop
; free allocated memory
invoke freeaddrinfo, [result]
; Data section:
hostname db 'kolibrios.org', 0
; hostname db '192.168.0.1', 0
result dd ?
freeaddrinfo
Free one or more addrinfo structures returned by getaddrinfo.
Input: ptr to addrinfo struct
Output: /