mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Separate printing available IP addresses by platform.
This commit is contained in:
52
unix/network.c
Normal file
52
unix/network.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of the DiscImageChef Remote Server.
|
||||
* Copyright (c) 2019 Natalia Portillo.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../dicmote.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int PrintNetworkAddresses()
|
||||
{
|
||||
int ret;
|
||||
struct ifaddrs* ifa;
|
||||
struct ifaddrs* ifa_start;
|
||||
char ipv4_address[INET_ADDRSTRLEN];
|
||||
|
||||
ret = getifaddrs(&ifa);
|
||||
|
||||
if(ret) return -1;
|
||||
|
||||
ifa_start = ifa;
|
||||
|
||||
printf("Available addresses:\n");
|
||||
while(ifa != NULL)
|
||||
{
|
||||
if(ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET)
|
||||
{
|
||||
inet_ntop(AF_INET, &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, ipv4_address, INET_ADDRSTRLEN);
|
||||
printf("%s port %d\n", ipv4_address, DICMOTE_PORT);
|
||||
}
|
||||
|
||||
ifa = ifa->ifa_next;
|
||||
}
|
||||
|
||||
freeifaddrs(ifa_start);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user