Networking - DNS resolution semi-working
[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 #include <stddef.h>
10
11 enum {
12         NET_ADDRTYPE_NULL = 0,
13         NET_ADDRTYPE_IPV4 = 4,
14         NET_ADDRTYPE_IPV6 = 6
15 };
16
17 /**
18  * \brief Parse a string as an IP Address
19  * \param String        Input string
20  * \param Addr  Output binary format of the address
21  * \return Address family (0: Invalid, 4: IPv4, 6: IPv6)
22  */
23 extern int      Net_ParseAddress(const char *String, void *Addr);
24
25 /**
26  * \brief Convert a network address into a string
27  * \param AddressType   Address family as returned by Net_ParseAddress
28  * \param Address       Address data
29  */
30 extern const char *Net_PrintAddress(int AddressType, const void *Address);
31
32 /**
33  * \brief Get the size in bytes of an address type
34  * \param AddressType   Address type returned by Net_ParseAddress
35  * \return Size of an address in bytes
36  */
37 extern int Net_GetAddressSize(int AddressType);
38
39 /**
40  * \brief Get the interface required to reach \a Addr
41  * \param AddrType      Addresss Family (4: IPv4, 6: IPv6)
42  * \param Addr  Address in binary format
43  * \return Interface number
44  */
45 extern char     *Net_GetInterface(int AddrType, void *Addr);
46
47 /**
48  * \brief Open a network socket file
49  * \param AddrType      Address family
50  * \param Addr  Binary address
51  * \param SocketName    Socket type to open (e.g. tcpc for TCP client)
52  *                      If NULL, the node directory is opened
53  * \return Socket file descriptor (as returned by \a open), or -1 on error
54  * 
55  * Opens a file using /Devices/ip/routes/@<AddrType>:<Addr>/<SocketName>
56  * 
57  */
58 extern int      Net_OpenSocket(int AddrType, const void *Addr, const char *SocketName);
59
60 extern int      Net_OpenSocket_TCPC(int AddrType, const void *Addr, int Port);
61
62 extern int      Net_OpenSocket_UDP(int AddrType, const void *Addr, int RAddr, int LAddr);
63 extern int Net_UDP_SendTo  (int FD, int Port, int AddrType, const void *Addr, size_t Length, const void *Data);
64 extern int Net_UDP_RecvFrom(int FD, int* Port, int* AddrType, void *Addr, size_t Length, void *Data);
65
66
67 /**
68  * \name Hostnames
69  * \brief Handling of hostname resolution
70  * \{
71  */
72
73 /**
74  * \brief Returns an address for the specified hostname
75  * \note Picks randomly if multiple addresses are present
76  */
77 extern int      Net_Lookup_AnyAddr(const char *Name, int AddrType, void *Addr);
78
79 /**
80  * \brief Callback for Net_Lookup_Addrs, returns non-zero when lookup should terminate
81  */
82 typedef int tNet_LookupAddrs_Callback(void *info, int AddrType, const void *Addr);
83
84 /**
85  * \brief Enumerate addresses for a host, calling the provided function for each
86  */
87 extern int      Net_Lookup_Addrs(const char *Name, void *info, tNet_LookupAddrs_Callback* callback);
88
89 /**
90  */
91 extern int      Net_Lookup_Name(int AddrType, const void *Addr, char *Dest[256]);
92
93 /**
94  * \}
95  */
96
97 #endif

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