Skip to content

Commit d2a9eee

Browse files
pizhenweiintel-lab-lkp
authored andcommitted
selftests: mptcp: use IPPROTO_MPTCP for getaddrinfo
mptcp_connect.c is a startup tutorial of MPTCP programming, however there is a lack of ai_protocol(IPPROTO_MPTCP) usage. Add comment for getaddrinfo MPTCP support. This patch first uses IPPROTO_MPTCP to get addrinfo, and if glibc version is too old, it falls back to using IPPROTO_TCP. v2: - use IPPROTO_MPTCP for getaddrinfo Co-developed-by: Geliang Tang <[email protected]> Signed-off-by: Geliang Tang <[email protected]> Signed-off-by: zhenwei pi <[email protected]>
1 parent 5426f98 commit d2a9eee

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tools/testing/selftests/net/mptcp/mptcp_connect.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,26 @@ static void xgetnameinfo(const struct sockaddr *addr, socklen_t addrlen,
180180
}
181181

182182
static void xgetaddrinfo(const char *node, const char *service,
183-
const struct addrinfo *hints,
183+
struct addrinfo *hints,
184184
struct addrinfo **res)
185185
{
186+
again:
186187
int err = getaddrinfo(node, service, hints, res);
187188

188189
if (err) {
189-
const char *errstr = getxinfo_strerr(err);
190+
const char *errstr;
191+
192+
/* glibc starts to support MPTCP since v2.42.
193+
* For older versions, use IPPROTO_TCP to resolve,
194+
* and use TCP/MPTCP to create socket.
195+
* Link: https://sourceware.org/git/?p=glibc.git;a=commit;h=a8e9022e0f82
196+
*/
197+
if (err == EAI_SOCKTYPE) {
198+
hints->ai_protocol = IPPROTO_TCP;
199+
goto again;
200+
}
201+
202+
errstr = getxinfo_strerr(err);
190203

191204
fprintf(stderr, "Fatal: getaddrinfo(%s:%s): %s\n",
192205
node ? node : "", service ? service : "", errstr);
@@ -292,7 +305,7 @@ static int sock_listen_mptcp(const char * const listenaddr,
292305
{
293306
int sock = -1;
294307
struct addrinfo hints = {
295-
.ai_protocol = IPPROTO_TCP,
308+
.ai_protocol = IPPROTO_MPTCP,
296309
.ai_socktype = SOCK_STREAM,
297310
.ai_flags = AI_PASSIVE | AI_NUMERICHOST
298311
};
@@ -356,7 +369,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,
356369
int infd, struct wstate *winfo)
357370
{
358371
struct addrinfo hints = {
359-
.ai_protocol = IPPROTO_TCP,
372+
.ai_protocol = IPPROTO_MPTCP,
360373
.ai_socktype = SOCK_STREAM,
361374
};
362375
struct addrinfo *a, *addr;

0 commit comments

Comments
 (0)