xref: /netbsd-src/external/mit/libuv/dist/docs/code/interfaces/main.c (revision 5f2f42719cd62ff11fd913b40b7ce19f07c4fd25)
10e552da7Schristos #include <stdio.h>
20e552da7Schristos #include <uv.h>
30e552da7Schristos 
main()40e552da7Schristos int main() {
50e552da7Schristos     char buf[512];
60e552da7Schristos     uv_interface_address_t *info;
70e552da7Schristos     int count, i;
80e552da7Schristos 
90e552da7Schristos     uv_interface_addresses(&info, &count);
100e552da7Schristos     i = count;
110e552da7Schristos 
120e552da7Schristos     printf("Number of interfaces: %d\n", count);
130e552da7Schristos     while (i--) {
14*5f2f4271Schristos         uv_interface_address_t interface_a = info[i];
150e552da7Schristos 
16*5f2f4271Schristos         printf("Name: %s\n", interface_a.name);
17*5f2f4271Schristos         printf("Internal? %s\n", interface_a.is_internal ? "Yes" : "No");
180e552da7Schristos 
19*5f2f4271Schristos         if (interface_a.address.address4.sin_family == AF_INET) {
20*5f2f4271Schristos             uv_ip4_name(&interface_a.address.address4, buf, sizeof(buf));
210e552da7Schristos             printf("IPv4 address: %s\n", buf);
220e552da7Schristos         }
23*5f2f4271Schristos         else if (interface_a.address.address4.sin_family == AF_INET6) {
24*5f2f4271Schristos             uv_ip6_name(&interface_a.address.address6, buf, sizeof(buf));
250e552da7Schristos             printf("IPv6 address: %s\n", buf);
260e552da7Schristos         }
270e552da7Schristos 
280e552da7Schristos         printf("\n");
290e552da7Schristos     }
300e552da7Schristos 
310e552da7Schristos     uv_free_interface_addresses(info, count);
320e552da7Schristos     return 0;
330e552da7Schristos }
34