Usermode/libnet - Starting work on DNS resolver
[tpg/acess2.git] / Usermode / Libraries / libnet.so_src / include_exp / net.h
1 /*
2  * Acess2 Common Networking Library
3  * By John Hodge (thePowersGang)
4  */
5
6 #ifndef __LIBNET_H_
7 #define __LIBNET_H_
8
9 enum {
10         NET_ADDRTYPE_NULL = 0,
11         NET_ADDRTYPE_IPV4 = 4,
12         NET_ADDRTYPE_IPV6 = 6
13 };
14
15 /**
16  * \brief Parse a string as an IP Address
17  * \param String        Input string
18  * \param Addr  Output binary format of the address
19  * \return Address family (0: Invalid, 4: IPv4, 6: IPv6)
20  */
21 extern int      Net_ParseAddress(const char *String, void *Addr);
22
23 /**
24  * \brief Convert a network address into a string
25  * \param AddressType   Address family as returned by Net_ParseAddress
26  * \param Address       Address data
27  */
28 extern const char *Net_PrintAddress(int AddressType, const void *Address);
29
30 /**
31  * \brief Get the size in bytes of an address type
32  * \param AddressType   Address type returned by Net_ParseAddress
33  * \return Size of an address in bytes
34  */
35 extern int Net_GetAddressSize(int AddressType);
36
37 /**
38  * \brief Get the interface required to reach \a Addr
39  * \param AddrType      Addresss Family (4: IPv4, 6: IPv6)
40  * \param Addr  Address in binary format
41  * \return Interface number
42  */
43 extern char     *Net_GetInterface(int AddrType, void *Addr);
44
45 /**
46  * \brief Open a network socket file
47  * \param AddrType      Address family
48  * \param Addr  Binary address
49  * \param SocketName    Socket type to open (e.g. tcpc for TCP client)
50  *                      If NULL, the node directory is opened
51  * \return Socket file descriptor (as returned by \a open), or -1 on error
52  * 
53  * Opens a file using /Devices/ip/routes/@<AddrType>:<Addr>/<SocketName>
54  * 
55  */
56 extern int      Net_OpenSocket(int AddrType, const void *Addr, const char *SocketName);
57
58 extern int      Net_OpenSocket_TCPC(int AddrType, const void *Addr, int Port);
59
60 extern int      Net_OpenSocket_UDP(int AddrType, const void *Addr, int RAddr, int LAddr);
61
62
63 /**
64  * \name Hostnames
65  * \brief Handling of hostname resolution
66  * \{
67  */
68
69 /**
70  * \brief Returns an address for the specified hostname
71  * \note Picks randomly if multiple addresses are present
72  */
73 extern int      Net_Lookup_AnyAddr(const char *Name, int AddrType, void *Addr);
74
75 /**
76  */
77 extern int      Net_Lookup_Name(int AddrType, const void *Addr, char *Dest[256]);
78
79 /**
80  * \}
81  */
82
83 #endif

UCC git Repository :: git.ucc.asn.au