MCPcopy Index your code
hub / github.com/nodejs/node / lookup

Function lookup

lib/dns.js:142–251  ·  view source on GitHub ↗
(hostname, options, callback)

Source from the content-addressed store, hash-verified

140// Easy DNS A/AAAA look up
141// lookup(hostname, [options,] callback)
142function lookup(hostname, options, callback) {
143 let hints = 0;
144 let family = 0;
145 let all = false;
146 let dnsOrder = getDefaultResultOrder();
147
148 // Parse arguments
149 if (hostname) {
150 validateStringWithoutNullBytes(hostname, 'hostname');
151 }
152
153 if (typeof options === 'function') {
154 callback = options;
155 family = 0;
156 } else if (typeof options === 'number') {
157 validateFunction(callback, 'callback');
158
159 validateOneOf(options, 'family', validFamilies);
160 // Coerce -0 to +0.
161 family = options + 0;
162 } else if (options !== undefined && typeof options !== 'object') {
163 validateFunction(arguments.length === 2 ? options : callback, 'callback');
164 throw new ERR_INVALID_ARG_TYPE('options', ['integer', 'object'], options);
165 } else {
166 validateFunction(callback, 'callback');
167
168 if (options?.hints != null) {
169 validateNumber(options.hints, 'options.hints');
170 hints = options.hints >>> 0;
171 validateHints(hints);
172 }
173 if (options?.family != null) {
174 switch (options.family) {
175 case 'IPv4':
176 family = 4;
177 break;
178 case 'IPv6':
179 family = 6;
180 break;
181 default:
182 validateOneOf(options.family, 'options.family', validFamilies);
183 // Coerce -0 to +0.
184 family = options.family + 0;
185 break;
186 }
187 }
188 if (options?.all != null) {
189 validateBoolean(options.all, 'options.all');
190 all = options.all;
191 }
192 if (options?.verbatim != null) {
193 validateBoolean(options.verbatim, 'options.verbatim');
194 dnsOrder = options.verbatim ? 'verbatim' : 'ipv4first';
195 }
196 if (options?.order != null) {
197 validateOneOf(options.order, 'options.order', validDnsOrders);
198 dnsOrder = options.order;
199 }

Callers 4

lookupAndConnectFunction · 0.70
lookupAndConnectMultipleFunction · 0.70
mainFunction · 0.50
mainFunction · 0.50

Calls 5

getDefaultResultOrderFunction · 0.85
validateHintsFunction · 0.85
isIPFunction · 0.85
hasObserverFunction · 0.85
startPerfFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…