From: John Hodge Date: Wed, 23 Mar 2011 05:35:22 +0000 (+0800) Subject: Usermode/libnet - Added support for change to routing API X-Git-Tag: rel0.10~149 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3fd9baa3ff076bc424b77b31928a0fee34f883f9;p=tpg%2Facess2.git Usermode/libnet - Added support for change to routing API --- diff --git a/Usermode/Libraries/libnet.so_src/main.c b/Usermode/Libraries/libnet.so_src/main.c index 938d1142..7f8d0482 100644 --- a/Usermode/Libraries/libnet.so_src/main.c +++ b/Usermode/Libraries/libnet.so_src/main.c @@ -28,6 +28,32 @@ int Net_GetAddressSize(int AddressType) } } +int Net_OpenSocket(int AddrType, void *Addr, const char *Filename) +{ + int addrLen = Net_GetAddressSize(AddrType); + int i; + uint8_t *addrBuffer = Addr; + char hexAddr[addrLen*2+1]; + + for( i = 0; i < addrLen; i ++ ) + sprintf(hexAddr+i*2, "%02x", addrBuffer[i]); + + if(Filename) + { + int len = snprintf(NULL, 100, "/Devices/ip/routes/%i:%s/%s", AddrType, hexAddr, Filename); + char path[len+1]; + snprintf(path, 100, "/Devices/ip/routes/%i:%s/%s", AddrType, hexAddr, Filename); + return open(path, OPENFLAG_READ|OPENFLAG_WRITE); + } + else + { + int len = snprintf(NULL, 100, "/Devices/ip/routes/%i:%s", AddrType, hexAddr); + char path[len+1]; + snprintf(path, 100, "/Devices/ip/routes/%i:%s", AddrType, hexAddr); + return open(path, OPENFLAG_READ); + } +} + //TODO: Move out to another file char *Net_GetInterface(int AddressType, void *Address) { diff --git a/Usermode/Libraries/libnet.so_src/net.h b/Usermode/Libraries/libnet.so_src/net.h index fcd213f0..d02da0bd 100644 --- a/Usermode/Libraries/libnet.so_src/net.h +++ b/Usermode/Libraries/libnet.so_src/net.h @@ -6,6 +6,12 @@ #ifndef __LIBNET_H_ #define __LIBNET_H_ +enum { + NET_ADDRTYPE_NULL = 0, + NET_ADDRTYPE_IPV4 = 4, + NET_ADDRTYPE_IPV6 = 6 +}; + /** * \brief Parse a string as an IP Address * \param String Input string @@ -36,4 +42,17 @@ extern int Net_GetAddressSize(int AddressType); */ extern char *Net_GetInterface(int AddrType, void *Addr); +/** + * \brief Open a network socket file + * \param AddrType Address family + * \param Addr Binary address + * \param SocketName Socket type to open (e.g. tcpc for TCP client) + * If NULL, the node directory is opened + * \return Socket file descriptor (as returned by \a open), or -1 on error + * + * Opens a file using /Devices/ip/routes/:/ + * + */ +extern int Net_OpenSocket(int AddrType, void *Addr, const char *SocketName); + #endif