Skip to content

Commit d237ee8

Browse files
committed
nsapi - Reversed arguments to gethostbyname
Updated to match prior conventions - netconn_gethostbyname - gethostbyname_r - gethostbyname2_r - gethostbyaddr_r
1 parent 3858a13 commit d237ee8

File tree

11 files changed

+62
-69
lines changed

11 files changed

+62
-69
lines changed

features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static int lwip_err_remap(err_t err) {
273273

274274

275275
/* LWIP network stack implementation */
276-
static int lwip_gethostbyname(nsapi_stack_t *stack, nsapi_addr_t *addr, const char *host)
276+
static int lwip_gethostbyname(nsapi_stack_t *stack, const char *host, nsapi_addr_t *addr)
277277
{
278278
err_t err = netconn_gethostbyname(host, (ip_addr_t *)addr->bytes);
279279
if (err != ERR_OK) {

features/net/network-socket/NetworkInterface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ int NetworkInterface::set_dhcp(bool dhcp)
5555
}
5656

5757
// DNS operations go through the underlying stack by default
58-
int NetworkInterface::gethostbyname(SocketAddress *address, const char *name)
58+
int NetworkInterface::gethostbyname(const char *name, SocketAddress *address)
5959
{
60-
return get_stack()->gethostbyname(address, name);
60+
return get_stack()->gethostbyname(name, address);
6161
}
6262

63-
int NetworkInterface::gethostbyname(SocketAddress *address, const char *name, nsapi_version_t version)
63+
int NetworkInterface::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
6464
{
65-
return get_stack()->gethostbyname(address, name, version);
65+
return get_stack()->gethostbyname(name, address, version);
6666
}
6767

6868
int NetworkInterface::add_dns_server(const SocketAddress &address)

features/net/network-socket/NetworkInterface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ class NetworkInterface {
108108
* If no stack-specific DNS resolution is provided, the hostname
109109
* will be resolve using a UDP socket on the stack.
110110
*
111-
* @param host Hostname to resolve
112111
* @param address Destination for the host SocketAddress
112+
* @param host Hostname to resolve
113113
* @return 0 on success, negative error code on failure
114114
*/
115-
virtual int gethostbyname(SocketAddress *address, const char *host);
115+
virtual int gethostbyname(const char *host, SocketAddress *address);
116116

117117
/** Translates a hostname to an IP address with specific version
118118
*
@@ -127,7 +127,7 @@ class NetworkInterface {
127127
* @param version IP version of address to resolve
128128
* @return 0 on success, negative error code on failure
129129
*/
130-
virtual int gethostbyname(SocketAddress *address, const char *host, nsapi_version_t version);
130+
virtual int gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version);
131131

132132
/** Add a domain name server to list of servers to query
133133
*

features/net/network-socket/NetworkStack.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323

2424
// Default NetworkStack operations
25-
int NetworkStack::gethostbyname(SocketAddress *address, const char *name)
25+
int NetworkStack::gethostbyname(const char *name, SocketAddress *address)
2626
{
27-
return nsapi_dns_query(this, address, name);
27+
return nsapi_dns_query(this, name, address);
2828
}
2929

30-
int NetworkStack::gethostbyname(SocketAddress *address, const char *name, nsapi_version_t version)
30+
int NetworkStack::gethostbyname(const char *name, SocketAddress *address, nsapi_version_t version)
3131
{
32-
return nsapi_dns_query(this, address, name, version);
32+
return nsapi_dns_query(this, name, address, version);
3333
}
3434

3535
int NetworkStack::add_dns_server(const SocketAddress &address)
@@ -86,14 +86,14 @@ class NetworkStackWrapper : public NetworkStack
8686
return address->get_ip_address();
8787
}
8888

89-
virtual int gethostbyname(SocketAddress *address, const char *name)
89+
virtual int gethostbyname(const char *name, SocketAddress *address)
9090
{
9191
if (!_stack_api()->gethostbyname) {
92-
return NetworkStack::gethostbyname(address, name);
92+
return NetworkStack::gethostbyname(name, address);
9393
}
9494

9595
nsapi_addr_t addr = {NSAPI_IPv4, 0};
96-
int err = _stack_api()->gethostbyname(_stack(), &addr, name);
96+
int err = _stack_api()->gethostbyname(_stack(), name, &addr);
9797
address->set_addr(addr);
9898
return err;
9999
}

features/net/network-socket/NetworkStack.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ class NetworkStack
4949
* If no stack-specific DNS resolution is provided, the hostname
5050
* will be resolve using a UDP socket on the stack.
5151
*
52-
* @param address Destination for the host SocketAddress
5352
* @param host Hostname to resolve
53+
* @param address Destination for the host SocketAddress
5454
* @return 0 on success, negative error code on failure
5555
*/
56-
virtual int gethostbyname(SocketAddress *address, const char *host);
56+
virtual int gethostbyname(const char *host, SocketAddress *address);
5757

5858
/** Translates a hostname to an IP address with specific version
5959
*
@@ -68,7 +68,7 @@ class NetworkStack
6868
* @param version IP version of address to resolve
6969
* @return 0 on success, negative error code on failure
7070
*/
71-
virtual int gethostbyname(SocketAddress *address, const char *host, nsapi_version_t version);
71+
virtual int gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version);
7272

7373
/** Add a domain name server to list of servers to query
7474
*

features/net/network-socket/SocketAddress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void SocketAddress::_SocketAddress(NetworkStack *iface, const char *host, uint16
292292
_port = port;
293293
} else {
294294
// DNS lookup
295-
int err = iface->gethostbyname(this, host);
295+
int err = iface->gethostbyname(host, this);
296296
_port = port;
297297
if (err) {
298298
_addr = nsapi_addr_t();

features/net/network-socket/TCPSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int TCPSocket::connect(const SocketAddress &address)
5252
int TCPSocket::connect(const char *host, uint16_t port)
5353
{
5454
SocketAddress address;
55-
int err = _stack->gethostbyname(&address, host);
55+
int err = _stack->gethostbyname(host, &address);
5656
if (err) {
5757
return NSAPI_ERROR_DNS_FAILURE;
5858
}

features/net/network-socket/UDPSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ nsapi_protocol_t UDPSocket::get_proto()
3737
int UDPSocket::sendto(const char *host, uint16_t port, const void *data, unsigned size)
3838
{
3939
SocketAddress address;
40-
int err = _stack->gethostbyname(&address, host);
40+
int err = _stack->gethostbyname(host, &address);
4141
if (err) {
4242
return NSAPI_ERROR_DNS_FAILURE;
4343
}

features/net/network-socket/nsapi_dns.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,8 @@ static int dns_scan_response(const uint8_t **p, nsapi_addr_t *addr, unsigned add
295295
}
296296

297297
// core query function
298-
static int nsapi_dns_query_multiple(NetworkStack *stack,
299-
nsapi_addr_t *addr, unsigned addr_count,
300-
const char *host, nsapi_version_t version)
298+
static int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
299+
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version)
301300
{
302301
// check for valid host name
303302
int host_len = host ? strlen(host) : 0;
@@ -378,20 +377,18 @@ static int nsapi_dns_query_multiple(NetworkStack *stack,
378377
}
379378

380379
// convenience functions for other forms of queries
381-
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack,
382-
nsapi_addr_t *addr, unsigned addr_count,
383-
const char *host, nsapi_version_t version)
380+
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
381+
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version)
384382
{
385383
NetworkStack *nstack = nsapi_create_stack(stack);
386-
return nsapi_dns_query_multiple(nstack, addr, addr_count, host, version);
384+
return nsapi_dns_query_multiple(nstack, host, addr, addr_count, version);
387385
}
388386

389-
int nsapi_dns_query_multiple(NetworkStack *stack,
390-
SocketAddress *addresses, unsigned addr_count,
391-
const char *host, nsapi_version_t version)
387+
int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
388+
SocketAddress *addresses, unsigned addr_count, nsapi_version_t version)
392389
{
393390
nsapi_addr_t *addrs = new nsapi_addr_t[addr_count];
394-
int result = nsapi_dns_query_multiple(stack, addrs, addr_count, host, version);
391+
int result = nsapi_dns_query_multiple(stack, host, addrs, addr_count, version);
395392

396393
if (result > 0) {
397394
for (int i = 0; i < result; i++) {
@@ -403,19 +400,19 @@ int nsapi_dns_query_multiple(NetworkStack *stack,
403400
return result;
404401
}
405402

406-
extern "C" int nsapi_dns_query(nsapi_stack_t *stack,
407-
nsapi_addr_t *addr, const char *host, nsapi_version_t version)
403+
extern "C" int nsapi_dns_query(nsapi_stack_t *stack, const char *host,
404+
nsapi_addr_t *addr, nsapi_version_t version)
408405
{
409406
NetworkStack *nstack = nsapi_create_stack(stack);
410-
int result = nsapi_dns_query_multiple(nstack, addr, 1, host, version);
407+
int result = nsapi_dns_query_multiple(nstack, host, addr, 1, version);
411408
return (result > 0) ? 0 : result;
412409
}
413410

414-
int nsapi_dns_query(NetworkStack *stack,
415-
SocketAddress *address, const char *host, nsapi_version_t version)
411+
int nsapi_dns_query(NetworkStack *stack, const char *host,
412+
SocketAddress *address, nsapi_version_t version)
416413
{
417414
nsapi_addr_t addr;
418-
int result = nsapi_dns_query_multiple(stack, &addr, 1, host, version);
415+
int result = nsapi_dns_query_multiple(stack, host, &addr, 1, version);
419416
address->set_addr(addr);
420417
return (result > 0) ? 0 : result;
421418
}

features/net/network-socket/nsapi_dns.h

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,27 @@
2828
/** Query a domain name server for an IP address of a given hostname
2929
*
3030
* @param stack Network stack as target for DNS query
31-
* @param addr Destination for the host address
3231
* @param host Hostname to resolve
32+
* @param addr Destination for the host address
3333
* @param version IP version to resolve
3434
* @return 0 on success, negative error code on failure
3535
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
3636
*/
37-
int nsapi_dns_query(nsapi_stack_t *stack, nsapi_addr_t *addr,
38-
const char *host, nsapi_version_t version);
37+
int nsapi_dns_query(nsapi_stack_t *stack, const char *host,
38+
nsapi_addr_t *addr, nsapi_version_t version);
3939

4040
/** Query a domain name server for multiple IP address of a given hostname
4141
*
4242
* @param stack Network stack as target for DNS query
43+
* @param host Hostname to resolve
4344
* @param addr Array for the host addresses
4445
* @param addr_count Number of addresses allocated in the array
45-
* @param host Hostname to resolve
4646
* @param version IP version to resolve
4747
* @return Number of addresses found on success, negative error code on failure
4848
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
4949
*/
50-
int nsapi_dns_query_multiple(nsapi_stack_t *stack,
51-
nsapi_addr_t *addr, unsigned addr_count,
52-
const char *host, nsapi_version_t version);
50+
int nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
51+
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version);
5352

5453
/** Add a domain name server to list of servers to query
5554
*
@@ -65,88 +64,85 @@ int nsapi_dns_add_server(nsapi_addr_t addr);
6564
/** Query a domain name server for an IP address of a given hostname
6665
*
6766
* @param stack Network stack as target for DNS query
68-
* @param addr Destination for the host address
6967
* @param host Hostname to resolve
68+
* @param addr Destination for the host address
7069
* @param version IP version to resolve (defaults to NSAPI_IPv4)
7170
* @return 0 on success, negative error code on failure
7271
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
7372
*/
74-
int nsapi_dns_query(NetworkStack *stack, SocketAddress *addr,
75-
const char *host, nsapi_version_t version = NSAPI_IPv4);
73+
int nsapi_dns_query(NetworkStack *stack, const char *host,
74+
SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4);
7675

7776
/** Query a domain name server for an IP address of a given hostname
7877
*
7978
* @param stack Network stack as target for DNS query
80-
* @param addr Destination for the host address
8179
* @param host Hostname to resolve
80+
* @param addr Destination for the host address
8281
* @param version IP version to resolve (defaults to NSAPI_IPv4)
8382
* @return 0 on success, negative error code on failure
8483
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
8584
*/
86-
extern "C" int nsapi_dns_query(nsapi_stack_t *stack, nsapi_addr_t *addr,
87-
const char *host, nsapi_version_t version = NSAPI_IPv4);
85+
extern "C" int nsapi_dns_query(nsapi_stack_t *stack, const char *host,
86+
nsapi_addr_t *addr, nsapi_version_t version = NSAPI_IPv4);
8887

8988
/** Query a domain name server for an IP address of a given hostname
9089
*
9190
* @param stack Network stack as target for DNS query
92-
* @param addr Destination for the host address
9391
* @param host Hostname to resolve
92+
* @param addr Destination for the host address
9493
* @param version IP version to resolve (defaults to NSAPI_IPv4)
9594
* @return 0 on success, negative error code on failure
9695
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
9796
*/
9897
template <typename S>
99-
int nsapi_dns_query(S *stack, SocketAddress *addr,
100-
const char *host, nsapi_version_t version = NSAPI_IPv4)
98+
int nsapi_dns_query(S *stack, const char *host,
99+
SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4)
101100
{
102-
return nsapi_dns_query(nsapi_create_stack(stack), addr, host, version);
101+
return nsapi_dns_query(nsapi_create_stack(stack), host, addr, version);
103102
}
104103

105104
/** Query a domain name server for multiple IP address of a given hostname
106105
*
107106
* @param stack Network stack as target for DNS query
107+
* @param host Hostname to resolve
108108
* @param addr Array for the host addresses
109109
* @param addr_count Number of addresses allocated in the array
110-
* @param host Hostname to resolve
111110
* @param version IP version to resolve (defaults to NSAPI_IPv4)
112111
* @return Number of addresses found on success, negative error code on failure
113112
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
114113
*/
115-
int nsapi_dns_query_multiple(NetworkStack *stack,
116-
SocketAddress *addr, unsigned addr_count,
117-
const char *host, nsapi_version_t version = NSAPI_IPv4);
114+
int nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
115+
SocketAddress *addr, unsigned addr_count, nsapi_version_t version = NSAPI_IPv4);
118116

119117
/** Query a domain name server for multiple IP address of a given hostname
120118
*
121119
* @param stack Network stack as target for DNS query
120+
* @param host Hostname to resolve
122121
* @param addr Array for the host addresses
123122
* @param addr_count Number of addresses allocated in the array
124-
* @param host Hostname to resolve
125123
* @param version IP version to resolve (defaults to NSAPI_IPv4)
126124
* @return Number of addresses found on success, negative error code on failure
127125
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
128126
*/
129-
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack,
130-
nsapi_addr_t *addr, unsigned addr_count,
131-
const char *host, nsapi_version_t version = NSAPI_IPv4);
127+
extern "C" int nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
128+
nsapi_addr_t *addr, unsigned addr_count, nsapi_version_t version = NSAPI_IPv4);
132129

133130
/** Query a domain name server for multiple IP address of a given hostname
134131
*
135132
* @param stack Network stack as target for DNS query
133+
* @param host Hostname to resolve
136134
* @param addr Array for the host addresses
137135
* @param addr_count Number of addresses allocated in the array
138-
* @param host Hostname to resolve
139136
* @param version IP version to resolve (defaults to NSAPI_IPv4)
140137
* @return Number of addresses found on success, negative error code on failure
141138
* NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
142139
*/
143140
template <typename S>
144-
int nsapi_dns_query_multiple(S *stack,
145-
SocketAddress *addr, unsigned addr_count,
146-
const char *host, nsapi_version_t version = NSAPI_IPv4)
141+
int nsapi_dns_query_multiple(S *stack, const char *host,
142+
SocketAddress *addr, unsigned addr_count, nsapi_version_t version = NSAPI_IPv4)
147143
{
148144
return nsapi_dns_query_multiple(nsapi_create_stack(stack),
149-
addr, addr_count, host, version);
145+
host, addr, addr_count, version);
150146
}
151147

152148
/** Add a domain name server to list of servers to query

0 commit comments

Comments
 (0)