# wlynxg/anet architecture

> Architecture diagram of the GitHub repository wlynxg/anet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wlynxg/anet
- Repository: https://github.com/wlynxg/anet

## Overview

##### Main Components

a) Core Components:
- Two main function blocks: "Interface()" and "InterfaceAddrs()"
- Android-specific implementation layer

b) Integration Layer:
- Compatibility with both standard "net" package and "golang.org/x/net"
- Android API integration point (NetworkInterface.getNetworkInterfaces())

##### Interaction Flows

**[Application Layer]**
- ↓
**[anet Package Interface]**
- ↓
**[Implementation Layer]**
- Android API Calls
- Modified Netlink Socket Handling

##### Technical Details to Highlight

- Modified Netlink Socket Implementation
- Removal of Bind() operation
- Ioctl-based retrieval system
- Permission Handling Layer
- Demonstrate how it bypasses Android 11+ restrictions
- Interface Information Flow
- How network interface data is gathered
- Limited MAC address accessibility

##### Component Relationships

**[Go Application] → [anet Interface] → [Android System Calls]**
- → [Modified Netlink Operations]

##### Implementation Details

- CGO Bridges (reference android_api_level_cgo.go)
- Mobile-specific implementations (mobile/mobile.go)
- Platform-specific code (interface_android.go, netlink_android.go)

Keep the abstraction level focused on the architectural components while including enough technical detail to show the unique aspects of this networking solution, particularly its Android-specific modifications and permission handling.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        style Legend fill:#f5f5f5,stroke:#333
        L1[Core Components]:::core
        L2[Android Components]:::android
        L3[Modified Operations]:::modified
        L4[Restricted Operations]:::restricted
        
        classDef core fill:#blue,color:white
        classDef android fill:#green,color:white
        classDef modified fill:#yellow,color:black
        classDef restricted fill:#red,color:white
    end

    subgraph "Application Layer"
        APP[Go Application]:::core
    end

    subgraph "anet Package Interface"
        CORE[Core Interface]:::core
        INTERFACE[Interface Function]:::core
        ADDRS[InterfaceAddrs Function]:::core
    end

    subgraph "Implementation Layer"
        ANDROID[Android Implementation]:::android
        NETLINK[Modified Netlink Socket]:::modified
        PERM[Permission Handler]:::android
        CGO[CGO Bridge]:::android
    end

    subgraph "Mobile Integration"
        MOBILE[Mobile Implementation]:::android
        LIBS[Mobile Libraries]:::android
    end

    subgraph "Restrictions & Notes"
        NOTE1[No MAC Address Access]:::restricted
        NOTE2[IP-Only Interfaces]:::restricted
        NOTE3["Go 1.23.0+ Required\n-checklinkname=0"]:::modified
    end

    APP --> CORE
    CORE --> INTERFACE
    CORE --> ADDRS
    INTERFACE --> ANDROID
    ADDRS --> ANDROID
    ANDROID --> NETLINK
    ANDROID --> PERM
    PERM --> CGO
    CGO --> MOBILE
    MOBILE --> LIBS

    click CORE "https://github.com/wlynxg/anet/blob/main/interface.go"
    click ANDROID "https://github.com/wlynxg/anet/blob/main/interface_android.go"
    click NETLINK "https://github.com/wlynxg/anet/blob/main/netlink_android.go"
    click PERM "https://github.com/wlynxg/anet/blob/main/android_api_level.go"
    click CGO "https://github.com/wlynxg/anet/blob/main/android_api_level_cgo.go"
    click MOBILE "https://github.com/wlynxg/anet/blob/main/mobile/mobile.go"
    click LIBS "https://github.com/wlynxg/anet/tree/main/mobile/libs"

    classDef core fill:#0066cc,color:white
    classDef android fill:#4CAF50,color:white
    classDef modified fill:#FFC107,color:black
    classDef restricted fill:#f44336,color:white
```
