2 * Acess2 Common Networking Library
3 * By John Hodge (thePowersGang)
12 NET_ADDRTYPE_NULL = 0,
13 NET_ADDRTYPE_IPV4 = 4,
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)
23 extern int Net_ParseAddress(const char *String, void *Addr);
26 * \brief Convert a network address into a string
27 * \param AddressType Address family as returned by Net_ParseAddress
28 * \param Address Address data
30 extern const char *Net_PrintAddress(int AddressType, const void *Address);
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
37 extern int Net_GetAddressSize(int AddressType);
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
45 extern char *Net_GetInterface(int AddrType, void *Addr);
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
55 * Opens a file using /Devices/ip/routes/@<AddrType>:<Addr>/<SocketName>
58 extern int Net_OpenSocket(int AddrType, const void *Addr, const char *SocketName);
60 extern int Net_OpenSocket_TCPC(int AddrType, const void *Addr, int Port);
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);
69 * \brief Handling of hostname resolution
74 * \brief Returns an address for the specified hostname
75 * \note Picks randomly if multiple addresses are present
77 extern int Net_Lookup_AnyAddr(const char *Name, int AddrType, void *Addr);
80 * \brief Callback for Net_Lookup_Addrs, returns non-zero when lookup should terminate
82 typedef int tNet_LookupAddrs_Callback(void *info, int AddrType, const void *Addr);
85 * \brief Enumerate addresses for a host, calling the provided function for each
87 extern int Net_Lookup_Addrs(const char *Name, void *info, tNet_LookupAddrs_Callback* callback);
91 extern int Net_Lookup_Name(int AddrType, const void *Addr, char *Dest[256]);