@@ -297,94 +297,73 @@ def ip_unpack
297
297
298
298
def ipv4_loopback?
299
299
return false unless ipv4?
300
-
301
300
Truffle ::Socket ::Foreign . inet_network ( ip_address ) & 0xff000000 == 0x7f000000
302
301
end
303
302
304
303
def ipv4_multicast?
305
304
return false unless ipv4?
306
-
307
305
Truffle ::Socket ::Foreign . inet_network ( ip_address ) & 0xf0000000 == 0xe0000000
308
306
end
309
307
310
308
def ipv4_private?
311
309
return false unless ipv4?
312
-
313
310
num = Truffle ::Socket ::Foreign . inet_network ( ip_address )
314
-
315
311
num & 0xff000000 == 0x0a000000 ||
316
312
num & 0xfff00000 == 0xac100000 ||
317
313
num & 0xffff0000 == 0xc0a80000
318
314
end
319
315
320
316
def ipv6_loopback?
321
317
return false unless ipv6?
322
-
323
318
Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address ) ==
324
319
Truffle ::Socket ::IPv6 ::LOOPBACK
325
320
end
326
321
327
322
def ipv6_linklocal?
328
323
return false unless ipv6?
329
-
330
324
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
331
-
332
325
bytes [ 0 ] == 0xfe && bytes [ 1 ] >= 0x80
333
326
end
334
327
335
328
def ipv6_multicast?
336
329
return false unless ipv6?
337
-
338
330
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
339
-
340
331
bytes [ 0 ] == 0xff
341
332
end
342
333
343
334
def ipv6_sitelocal?
344
335
return false unless ipv6?
345
-
346
336
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
347
-
348
337
bytes [ 0 ] == 0xfe && bytes [ 1 ] >= 0xe0
349
338
end
350
339
351
340
def ipv6_mc_global?
352
341
return false unless ipv6?
353
-
354
342
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
355
-
356
343
bytes [ 0 ] == 0xff && bytes [ 1 ] & 0xf == 0xe
357
344
end
358
345
359
346
def ipv6_mc_linklocal?
360
347
return false unless ipv6?
361
-
362
348
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
363
-
364
349
bytes [ 0 ] == 0xff && bytes [ 1 ] & 0xf == 0x2
365
350
end
366
351
367
352
def ipv6_mc_nodelocal?
368
353
return false unless ipv6?
369
-
370
354
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
371
-
372
355
bytes [ 0 ] == 0xff && bytes [ 1 ] & 0xf == 0x1
373
356
end
374
357
375
358
def ipv6_mc_orglocal?
376
359
return false unless ipv6?
377
-
378
360
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
379
-
380
361
bytes [ 0 ] == 0xff && bytes [ 1 ] & 0xf == 0x8
381
362
end
382
363
383
364
def ipv6_mc_sitelocal?
384
365
return false unless ipv6?
385
-
386
366
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
387
-
388
367
bytes [ 0 ] == 0xff && bytes [ 1 ] & 0xf == 0x5
389
368
end
390
369
@@ -402,33 +381,25 @@ def ipv6_to_ipv4
402
381
403
382
def ipv6_unspecified?
404
383
return false unless ipv6?
405
-
406
384
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
407
-
408
385
bytes == Truffle ::Socket ::IPv6 ::UNSPECIFIED
409
386
end
410
387
411
388
def ipv6_v4compat?
412
389
return false unless ipv6?
413
-
414
390
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
415
-
416
391
Truffle ::Socket ::IPv6 . ipv4_compatible? ( bytes )
417
392
end
418
393
419
394
def ipv6_v4mapped?
420
395
return false unless ipv6?
421
-
422
396
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
423
-
424
397
Truffle ::Socket ::IPv6 . ipv4_mapped? ( bytes )
425
398
end
426
399
427
400
def ipv6_unique_local?
428
401
return false unless ipv6?
429
-
430
402
bytes = Truffle ::Socket ::Foreign . ip_to_bytes ( afamily , ip_address )
431
-
432
403
bytes [ 0 ] == 0xfc || bytes [ 0 ] == 0xfd
433
404
end
434
405
0 commit comments