From cfe4da687ca6d65b09414a243d1feebb879b91cd Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Tue, 5 Feb 2013 16:56:37 +1030 Subject: [PATCH] New hton_in_addr() function To silence warnings in struct in_addr assignments on Solaris, whose struct in_addr definition is a monstrosity. --- conf_schema.h | 8 ++++---- net.c | 7 +++++++ net.h | 8 ++++++++ overlay_interface.c | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/conf_schema.h b/conf_schema.h index 5958655c..1a606e3a 100644 --- a/conf_schema.h +++ b/conf_schema.h @@ -278,7 +278,7 @@ END_STRUCT STRUCT(rhizome_api_addfile) STRING(64, uri_path, "", cf_opt_absolute_path,, "URI path for HTTP add-file request") -ATOM(struct in_addr, allow_host, (struct in_addr){htonl(INADDR_LOOPBACK)}, cf_opt_in_addr,, "IP address of host allowed to make HTTP add-file request") +ATOM(struct in_addr, allow_host, hton_in_addr(INADDR_LOOPBACK), cf_opt_in_addr,, "IP address of host allowed to make HTTP add-file request") STRING(256, manifest_template_file, "", cf_opt_str_nonempty,, "Path of manifest template file, either absolute or relative to instance directory") ATOM(sid_t, default_author, SID_ANY, cf_opt_sid,, "Author of add-file bundle if sender not given") ATOM(rhizome_bk_t, bundle_secret_key, RHIZOME_BK_NONE, cf_opt_rhizome_bk,, "Secret key of add-file bundle to try if sender not given") @@ -319,7 +319,7 @@ END_STRUCT STRUCT(host) STRING(INTERFACE_NAME_STRLEN, interface, "", cf_opt_str_nonempty,, "Interface name") STRING(256, host, "", cf_opt_str_nonempty,, "Host Name") -ATOM(struct in_addr, address, (struct in_addr){htonl(INADDR_NONE)}, cf_opt_in_addr,, "Host IP address") +ATOM(struct in_addr, address, hton_in_addr(INADDR_NONE), cf_opt_in_addr,, "Host IP address") ATOM(uint16_t, port, PORT_DNA, cf_opt_uint16_nonzero,, "Port number") END_STRUCT @@ -332,8 +332,8 @@ STRUCT(network_interface, vld_network_interface) ATOM(int, exclude, 0, cf_opt_int_boolean,, "If true, do not use matching interfaces") ATOM(struct pattern_list, match, PATTERN_LIST_EMPTY, cf_opt_pattern_list,, "Names that match network interface") STRING(256, dummy, "", cf_opt_str_nonempty,, "Path of dummy file, absolute or relative to server.dummy_interface_dir") -ATOM(struct in_addr, dummy_address, (struct in_addr){htonl(0x7F000001)}, cf_opt_in_addr,, "Dummy interface address") -ATOM(struct in_addr, dummy_netmask, (struct in_addr){htonl(0xFFFFFF00)}, cf_opt_in_addr,, "Dummy interface netmask") +ATOM(struct in_addr, dummy_address, hton_in_addr(INADDR_LOOPBACK), cf_opt_in_addr,, "Dummy interface address") +ATOM(struct in_addr, dummy_netmask, hton_in_addr(0xFFFFFF00), cf_opt_in_addr,, "Dummy interface netmask") ATOM(char, dummy_filter_broadcasts, 0, cf_opt_char_boolean,, "If true, drop all incoming broadcast packets") ATOM(char, dummy_filter_unicasts, 0, cf_opt_char_boolean,, "If true, drop all incoming unicast packets") ATOM(short, type, OVERLAY_INTERFACE_WIFI, cf_opt_interface_type,, "Type of network interface") diff --git a/net.c b/net.c index ecb11f86..a4540617 100644 --- a/net.c +++ b/net.c @@ -29,6 +29,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "net.h" #include "str.h" +struct in_addr hton_in_addr(in_addr_t addr) +{ + struct in_addr a; + a.s_addr = htonl(addr); + return a; +} + int _set_nonblock(int fd, struct __sourceloc __whence) { int flags; diff --git a/net.h b/net.h index 7fa7febc..cde8dad1 100644 --- a/net.h +++ b/net.h @@ -21,8 +21,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include // for size_t, ssize_t #include // for struct sockaddr, socklen_t +#include // for struct in_addr +#include // for in_addr_t #include "log.h" // for __WHENCE__ and struct __sourceloc +/* Build a struct in_addr from a host-byte-order integer. + * + * @author Andrew Bettison + */ +struct in_addr hton_in_addr(in_addr_t); + #define set_nonblock(fd) (_set_nonblock(fd, __WHENCE__)) #define set_block(fd) (_set_block(fd, __WHENCE__)) #define read_nonblock(fd,buf,len) (_read_nonblock(fd, buf, len, __WHENCE__)) diff --git a/overlay_interface.c b/overlay_interface.c index cebe417f..f41bcbd5 100644 --- a/overlay_interface.c +++ b/overlay_interface.c @@ -803,7 +803,7 @@ void overlay_interface_discover(struct sched_ent *alarm) } if (i >= overlay_interface_count) { // New dummy interface, so register it. - struct in_addr dummyaddr = (struct in_addr){htonl(INADDR_NONE)}; + struct in_addr dummyaddr = hton_in_addr(INADDR_NONE); overlay_interface_init(ifconfig->dummy, dummyaddr, dummyaddr, dummyaddr, ifconfig); } }