mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Enumerate list of IP addresses.
This commit is contained in:
36
main.c
36
main.c
@@ -17,12 +17,48 @@
|
|||||||
|
|
||||||
#include "dicmote.h"
|
#include "dicmote.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <libnet.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
struct ifaddrs* ifa;
|
||||||
|
int ret;
|
||||||
|
char ipv4Address[INET_ADDRSTRLEN];
|
||||||
|
char ipv6Address[INET6_ADDRSTRLEN];
|
||||||
|
|
||||||
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
|
printf("DiscImageChef Remote Server %s\n", DICMOTE_VERSION);
|
||||||
printf("Copyright (C) 2019 Natalia Portillo\n");
|
printf("Copyright (C) 2019 Natalia Portillo\n");
|
||||||
|
|
||||||
|
ret = getifaddrs(&ifa);
|
||||||
|
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
printf("Error %d enumerating interfaces\n", errno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Available addresses:\n");
|
||||||
|
while(ifa != NULL)
|
||||||
|
{
|
||||||
|
if(ifa->ifa_addr)
|
||||||
|
{
|
||||||
|
if(ifa->ifa_addr->sa_family == AF_INET)
|
||||||
|
{
|
||||||
|
inet_ntop(AF_INET, &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, ipv4Address, INET_ADDRSTRLEN);
|
||||||
|
printf("%s port 6666\n", ipv4Address);
|
||||||
|
}
|
||||||
|
else if(ifa->ifa_addr->sa_family == AF_INET6)
|
||||||
|
{
|
||||||
|
inet_ntop(AF_INET6, &((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr, ipv6Address, INET6_ADDRSTRLEN);
|
||||||
|
printf("%s port 6666\n", ipv6Address);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ifa = ifa->ifa_next;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user