1 /* Operations on network stuff.
2 Copyright (C) 2018-2024 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #ifndef COMMON_NETSTUFF_H
20 #define COMMON_NETSTUFF_H
24 /* Like NI_MAXHOST/NI_MAXSERV, but enough for numeric forms. */
25 #define GDB_NI_MAX_ADDR 64
26 #define GDB_NI_MAX_PORT 16
28 /* Helper class to guarantee that we always call 'freeaddrinfo'. */
30 class scoped_free_addrinfo
33 /* Default constructor. */
34 explicit scoped_free_addrinfo (struct addrinfo
*ainfo
)
39 /* Destructor responsible for free'ing M_RES by calling
41 ~scoped_free_addrinfo ();
43 DISABLE_COPY_AND_ASSIGN (scoped_free_addrinfo
);
46 /* The addrinfo resource. */
47 struct addrinfo
*m_res
;
50 /* The struct we return after parsing the connection spec. */
52 struct parsed_connection_spec
57 /* The port, if any. */
62 /* Parse SPEC (which is a string in the form of "ADDR:PORT") and
63 return a 'parsed_connection_spec' structure with the proper fields
64 filled in. Also adjust HINT accordingly. */
65 extern parsed_connection_spec
66 parse_connection_spec_without_prefix (std::string spec
,
67 struct addrinfo
*hint
);
69 /* Parse SPEC (which is a string in the form of
70 "[tcp[6]:|udp[6]:]ADDR:PORT") and return a 'parsed_connection_spec'
71 structure with the proper fields filled in. Also adjust HINT
73 extern parsed_connection_spec
parse_connection_spec (const char *spec
,
74 struct addrinfo
*hint
);
76 #endif /* COMMON_NETSTUFF_H */