Mercurial
comparison third_party/libuv/docs/code/interfaces/main.c @ 173:827c6ac504cd hg-web
Merged in default here.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 19 Jan 2026 18:59:10 -0800 |
| parents | 948de3f54cea |
| children |
comparison
equal
deleted
inserted
replaced
| 151:c033667da5f9 | 173:827c6ac504cd |
|---|---|
| 1 #include <stdio.h> | |
| 2 #include <uv.h> | |
| 3 | |
| 4 int main() { | |
| 5 char buf[512]; | |
| 6 uv_interface_address_t *info; | |
| 7 int count, i; | |
| 8 | |
| 9 uv_interface_addresses(&info, &count); | |
| 10 i = count; | |
| 11 | |
| 12 printf("Number of interfaces: %d\n", count); | |
| 13 while (i--) { | |
| 14 uv_interface_address_t interface_a = info[i]; | |
| 15 | |
| 16 printf("Name: %s\n", interface_a.name); | |
| 17 printf("Internal? %s\n", interface_a.is_internal ? "Yes" : "No"); | |
| 18 | |
| 19 if (interface_a.address.address4.sin_family == AF_INET) { | |
| 20 uv_ip4_name(&interface_a.address.address4, buf, sizeof(buf)); | |
| 21 printf("IPv4 address: %s\n", buf); | |
| 22 } | |
| 23 else if (interface_a.address.address4.sin_family == AF_INET6) { | |
| 24 uv_ip6_name(&interface_a.address.address6, buf, sizeof(buf)); | |
| 25 printf("IPv6 address: %s\n", buf); | |
| 26 } | |
| 27 | |
| 28 printf("\n"); | |
| 29 } | |
| 30 | |
| 31 uv_free_interface_addresses(info, count); | |
| 32 return 0; | |
| 33 } |