Netman:Data in network order

This commit is contained in:
David Sidrane
2020-10-15 09:29:41 -07:00
committed by Lorenz Meier
parent d22eb76187
commit 39c6229c37
+5 -29
View File
@@ -56,7 +56,7 @@ constexpr char DEFAULT_NETMAN_CONFIG[] = "/fs/microsd/net.cfg";
# define DEFAULT_PROTO IPv4PROTO_FALLBACK # define DEFAULT_PROTO IPv4PROTO_FALLBACK
# define DEFAULT_IP 0XC0A80003 // 192.168.0.3 # define DEFAULT_IP 0XC0A80003 // 192.168.0.3
#else #else
# define DEFAULT_PROTO IPv4PROTO_STATIC # define DEFAULT_PROTO IPv4PROTO_STATIC
# define DEFAULT_IP CONFIG_NETINIT_IPADDR # define DEFAULT_IP CONFIG_NETINIT_IPADDR
#endif #endif
#define DEFAULT_NETMASK CONFIG_NETINIT_NETMASK #define DEFAULT_NETMASK CONFIG_NETINIT_NETMASK
@@ -206,23 +206,21 @@ public:
if (rv == -EINVAL || if (rv == -EINVAL ||
(rv == OK && (ipcfg.proto > IPv4PROTO_FALLBACK || ipcfg.ipaddr == 0xffffffff))) { (rv == OK && (ipcfg.proto > IPv4PROTO_FALLBACK || ipcfg.ipaddr == 0xffffffff))) {
// Build a default // Build a default
ipcfg.ipaddr = DEFAULT_IP; ipcfg.ipaddr = HTONL(DEFAULT_IP);
ipcfg.netmask = DEFAULT_NETMASK; ipcfg.netmask = HTONL(DEFAULT_NETMASK);
ipcfg.router = DEFAULT_ROUTER; ipcfg.router = HTONL(DEFAULT_ROUTER);
ipcfg.dnsaddr = DEFAULT_DNS; ipcfg.dnsaddr = HTONL(DEFAULT_DNS);
ipcfg.proto = DEFAULT_PROTO; ipcfg.proto = DEFAULT_PROTO;
rv = ENOENT; rv = ENOENT;
} }
device.set_name(netdev); device.set_name(netdev);
*this = ipcfg; *this = ipcfg;
hton();
return rv; return rv;
} }
int write() int write()
{ {
ntoh();
struct ipv4cfg_s ipcfg; struct ipv4cfg_s ipcfg;
ipcfg.proto = proto.e; ipcfg.proto = proto.e;
ipcfg.ipaddr = ipaddr.u; ipcfg.ipaddr = ipaddr.u;
@@ -231,28 +229,6 @@ public:
ipcfg.dnsaddr = dnsaddr.u; ipcfg.dnsaddr = dnsaddr.u;
return ipcfg_write(device.name(), (FAR struct ipcfg_s *) &ipcfg, AF_INET); return ipcfg_write(device.name(), (FAR struct ipcfg_s *) &ipcfg, AF_INET);
} }
void hton()
{
/* Store them in network order */
netmask.l = htonl(netmask.l);
ipaddr.l = htonl(ipaddr.l);
router.l = htonl(router.l);
dnsaddr.l = htonl(dnsaddr.l);
}
void ntoh()
{
/* Store them in host order */
netmask.l = ntohl(netmask.l);
ipaddr.l = ntohl(ipaddr.l);
router.l = ntohl(router.l);
dnsaddr.l = ntohl(dnsaddr.l);
}
}; };
int save(const char *path, const char *netdev) int save(const char *path, const char *netdev)