or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

address-types.mdformat-conversion.mdindex.mdipv4.mdipv6.mdspecial-analysis.mdsubnet-operations.md
tile.json

address-types.mddocs/

0

# Address Type Detection

1

2

Identification and analysis of special address types including multicast, loopback, Teredo, 6to4, and other reserved address ranges for both IPv4 and IPv6.

3

4

## Capabilities

5

6

### IPv4 Address Types

7

8

IPv4 addresses have fewer special types compared to IPv6, but multicast detection is essential for networking applications.

9

10

```typescript { .api }

11

/**

12

* Check if IPv4 address is a multicast address (224.0.0.0/4 range)

13

* Available on Address4 instances

14

* @returns true if the address is in the multicast range

15

*/

16

isMulticast(): boolean;

17

```

18

19

**IPv4 Examples:**

20

21

```typescript

22

import { Address4 } from "ip-address";

23

24

// Multicast addresses (224.0.0.0 to 239.255.255.255)

25

const multicast1 = new Address4("224.0.0.1");

26

const multicast2 = new Address4("239.255.255.255");

27

const unicast = new Address4("192.168.1.1");

28

29

console.log(multicast1.isMulticast()); // true

30

console.log(multicast2.isMulticast()); // true

31

console.log(unicast.isMulticast()); // false

32

33

// Well-known multicast addresses

34

const allHosts = new Address4("224.0.0.1");

35

const allRouters = new Address4("224.0.0.2");

36

const ospf = new Address4("224.0.0.5");

37

38

console.log(`All Hosts: ${allHosts.isMulticast()}`); // true

39

console.log(`All Routers: ${allRouters.isMulticast()}`); // true

40

console.log(`OSPF: ${ospf.isMulticast()}`); // true

41

```

42

43

### IPv6 Address Types and Scopes

44

45

IPv6 has a rich type system with various special-use addresses and scopes.

46

47

```typescript { .api }

48

/**

49

* Get the scope of the IPv6 address

50

* Available on Address6 instances

51

* @returns Scope string (e.g., "Global", "Link local", "Site local", "Interface local")

52

*/

53

getScope(): string;

54

55

/**

56

* Get the type/category of the IPv6 address

57

* Available on Address6 instances

58

* @returns Type string describing the address category

59

*/

60

getType(): string;

61

62

/**

63

* Check if address is a multicast address (ff00::/8)

64

* Available on Address6 instances

65

* @returns true if multicast address

66

*/

67

isMulticast(): boolean;

68

69

/**

70

* Check if address is the loopback address (::1)

71

* Available on Address6 instances

72

* @returns true if loopback address

73

*/

74

isLoopback(): boolean;

75

76

/**

77

* Check if address is link-local (fe80::/10 with specific zero pattern)

78

* Available on Address6 instances

79

* @returns true if properly formatted link-local address

80

*/

81

isLinkLocal(): boolean;

82

83

/**

84

* Check if address contains an IPv4 component (IPv4-in-IPv6)

85

* Available on Address6 instances

86

* @returns true if address has embedded IPv4

87

*/

88

is4(): boolean;

89

90

/**

91

* Check if address is in canonical form (IPv6 only)

92

* Available on Address6 instances

93

* @returns true if address is in canonical representation

94

*/

95

isCanonical(): boolean;

96

```

97

98

**IPv6 Basic Type Examples:**

99

100

```typescript

101

import { Address6 } from "ip-address";

102

103

// Global unicast

104

const global = new Address6("2001:db8::1");

105

console.log(global.getType()); // "Global unicast"

106

console.log(global.getScope()); // "Global"

107

108

// Loopback

109

const loopback = new Address6("::1");

110

console.log(loopback.getType()); // "Loopback"

111

console.log(loopback.isLoopback()); // true

112

113

// Link-local

114

const linkLocal = new Address6("fe80::1");

115

console.log(linkLocal.getType()); // "Link-local unicast"

116

console.log(linkLocal.getScope()); // "Link local"

117

console.log(linkLocal.isLinkLocal()); // true

118

119

// Multicast

120

const multicast = new Address6("ff02::1");

121

console.log(multicast.getType()); // "Multicast (All nodes on this link)"

122

console.log(multicast.getScope()); // "Link local"

123

console.log(multicast.isMulticast()); // true

124

```

125

126

**IPv6 Multicast Examples:**

127

128

```typescript

129

// Various multicast scopes and purposes

130

const examples = [

131

{ addr: "ff01::1", desc: "Interface-local all nodes" },

132

{ addr: "ff02::1", desc: "Link-local all nodes" },

133

{ addr: "ff02::2", desc: "Link-local all routers" },

134

{ addr: "ff05::2", desc: "Site-local all routers" },

135

{ addr: "ff02::5", desc: "OSPFv3 AllSPF routers" },

136

{ addr: "ff02::fb", desc: "mDNSv6" },

137

{ addr: "ff02::1:2", desc: "All DHCP servers and relay agents" }

138

];

139

140

examples.forEach(({ addr, desc }) => {

141

const address = new Address6(addr);

142

console.log(`${addr}: ${address.getType()}`);

143

console.log(` Scope: ${address.getScope()}`);

144

console.log(` Multicast: ${address.isMulticast()}`);

145

console.log(` Description: ${desc}\n`);

146

});

147

```

148

149

### IPv6 Transition Mechanisms

150

151

IPv6 addresses used for IPv4-to-IPv6 transition mechanisms.

152

153

```typescript { .api }

154

/**

155

* Check if address is a Teredo address (2001::/32)

156

* Available on Address6 instances

157

* @returns true if Teredo tunneling address

158

*/

159

isTeredo(): boolean;

160

161

/**

162

* Check if address is a 6to4 address (2002::/16)

163

* Available on Address6 instances

164

* @returns true if 6to4 transition address

165

*/

166

is6to4(): boolean;

167

```

168

169

**Teredo Examples:**

170

171

```typescript

172

// Teredo addresses (2001::/32 prefix)

173

const teredo1 = new Address6("2001:0:ce49:7601:e866:efff:62c3:fffe");

174

const teredo2 = new Address6("2001:0:1234:5678:abcd:ef01:2345:6789");

175

const regular = new Address6("2002:c000:0204::"); // 6to4, not Teredo

176

177

console.log(teredo1.isTeredo()); // true

178

console.log(teredo2.isTeredo()); // true

179

console.log(regular.isTeredo()); // false

180

181

console.log(teredo1.getType()); // "Global unicast"

182

console.log(teredo1.getScope()); // "Global"

183

```

184

185

**6to4 Examples:**

186

187

```typescript

188

// 6to4 addresses (2002::/16 prefix)

189

const sixToFour1 = new Address6("2002:c000:0204::"); // 192.0.2.4 embedded

190

const sixToFour2 = new Address6("2002:cb00:7100::"); // 203.0.113.0 embedded

191

const regular = new Address6("2001:db8::1");

192

193

console.log(sixToFour1.is6to4()); // true

194

console.log(sixToFour2.is6to4()); // true

195

console.log(regular.is6to4()); // false

196

197

console.log(sixToFour1.getType()); // "Global unicast"

198

console.log(sixToFour1.getScope()); // "Global"

199

```

200

201

### IPv4-in-IPv6 Address Detection

202

203

Detect and analyze addresses that contain embedded IPv4 components.

204

205

**IPv4-in-IPv6 Examples:**

206

207

```typescript

208

// IPv4-mapped IPv6 addresses (::ffff:x.x.x.x)

209

const mapped = new Address6("::ffff:192.168.1.1");

210

console.log(mapped.is4()); // true

211

console.log(mapped.getType()); // "Global unicast"

212

213

// IPv4-compatible IPv6 addresses (::x.x.x.x) - deprecated

214

const compatible = new Address6("::192.168.1.1");

215

console.log(compatible.is4()); // true

216

217

// 6to4 with IPv4 embedding

218

const sixToFour = new Address6("2002:c0a8:0101::"); // ::ffff:192.168.1.1 embedded

219

console.log(sixToFour.is4()); // false (no direct IPv4 component)

220

console.log(sixToFour.is6to4()); // true

221

222

// Extract IPv4 from mapped addresses

223

if (mapped.is4() && mapped.address4) {

224

console.log(`Embedded IPv4: ${mapped.address4.correctForm()}`); // "192.168.1.1"

225

}

226

```

227

228

### Comprehensive Address Analysis

229

230

Combine multiple type checks for complete address analysis.

231

232

**Complete Analysis Function:**

233

234

```typescript

235

function analyzeAddress(addrStr: string) {

236

try {

237

// Try IPv6 first

238

const addr6 = new Address6(addrStr);

239

console.log(`IPv6 Address: ${addr6.correctForm()}`);

240

console.log(`Type: ${addr6.getType()}`);

241

console.log(`Scope: ${addr6.getScope()}`);

242

console.log(`Canonical: ${addr6.canonicalForm()}`);

243

244

const properties = [];

245

if (addr6.isMulticast()) properties.push("Multicast");

246

if (addr6.isLoopback()) properties.push("Loopback");

247

if (addr6.isLinkLocal()) properties.push("Link-local");

248

if (addr6.isTeredo()) properties.push("Teredo");

249

if (addr6.is6to4()) properties.push("6to4");

250

if (addr6.is4()) properties.push("Contains IPv4");

251

252

if (properties.length > 0) {

253

console.log(`Special properties: ${properties.join(", ")}`);

254

}

255

256

if (addr6.is4() && addr6.address4) {

257

console.log(`Embedded IPv4: ${addr6.address4.correctForm()}`);

258

}

259

260

} catch (e) {

261

// Try IPv4

262

try {

263

const addr4 = new Address4(addrStr);

264

console.log(`IPv4 Address: ${addr4.correctForm()}`);

265

console.log(`Subnet: ${addr4.subnet}`);

266

267

const properties = [];

268

if (addr4.isMulticast()) properties.push("Multicast");

269

270

if (properties.length > 0) {

271

console.log(`Special properties: ${properties.join(", ")}`);

272

}

273

274

} catch (e2) {

275

console.log(`Invalid address: ${addrStr}`);

276

}

277

}

278

}

279

280

// Test various address types

281

const testAddresses = [

282

"192.168.1.1", // IPv4 unicast

283

"224.0.0.1", // IPv4 multicast

284

"::1", // IPv6 loopback

285

"fe80::1", // IPv6 link-local

286

"ff02::1", // IPv6 multicast

287

"2001:db8::1", // IPv6 global unicast

288

"::ffff:192.168.1.1", // IPv4-mapped IPv6

289

"2001:0:ce49:7601::1", // Teredo

290

"2002:c000:0204::", // 6to4

291

];

292

293

testAddresses.forEach(addr => {

294

console.log(`\n=== Analysis of ${addr} ===`);

295

analyzeAddress(addr);

296

});

297

```

298

299

### Address Type Constants

300

301

The library includes predefined constants for various IPv6 address types and scopes.

302

303

**IPv6 Scopes:**

304

305

- `0`: Reserved

306

- `1`: Interface local

307

- `2`: Link local

308

- `4`: Admin local

309

- `5`: Site local

310

- `8`: Organization local

311

- `14`: Global

312

- `15`: Reserved

313

314

**IPv6 Well-known Types:**

315

316

- `::1/128`: Loopback

317

- `::/128`: Unspecified

318

- `ff00::/8`: Multicast

319

- `fe80::/10`: Link-local unicast

320

- Various multicast addresses for different protocols (OSPFv3, DHCP, mDNS, etc.)

321

322

These constants are used internally by the `getType()` and `getScope()` methods to provide descriptive strings for address classification.