Mercurial
comparison third_party/libuv/docs/code/interfaces/main.c @ 160:948de3f54cea
[ThirdParty] Added libuv
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 14 Jan 2026 19:39:52 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 159:05cf9467a1c3 | 160:948de3f54cea |
|---|---|
| 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 } |