File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 4
4
#include "cpu/cpu_info.h"
5
5
#include "rom/rom_info.h"
6
6
#include "hlp/hlp_info.h"
7
+ #include "net/net_info.h"
7
8
8
9
int main (int argc , char * * argv ) {
9
10
if (argc == 1 ) {
@@ -27,6 +28,13 @@ int main(int argc, char **argv) {
27
28
print_ram_info ();
28
29
} else if (strcmp (argv [1 ], "-rom" ) == 0 ) {
29
30
print_rom_info ();
31
+ } else if (strcmp (argv [1 ], "-net" ) == 0 ) {
32
+ char host_name [100 ];
33
+ printf ("Enter a hostname: " );
34
+ fgets (host_name , sizeof (host_name ), stdin );
35
+ host_name [strcspn (host_name , "\n" )] = '\0' ;
36
+
37
+ print_net_info (host_name );
30
38
} else if (strcmp (argv [1 ], "-v" ) == 0 || strcmp (argv [1 ], "--version" ) == 0 ) {
31
39
print_ver_info ();
32
40
} else if (strcmp (argv [1 ], "-b" ) == 0 || strcmp (argv [1 ], "--banner" ) == 0 ) {
Original file line number Diff line number Diff line change
1
+ #include <ifaddrs.h>
2
+ #include <stdio.h>
3
+ #include <stdlib.h>
4
+ #include <sys/socket.h>
5
+ #include <netdb.h>
6
+ #include <arpa/inet.h>
7
+
8
+ void print_net_info (char * hostname ){
9
+ struct hostent * host = gethostbyname (hostname );
10
+ if (host == NULL ){
11
+ perror ("gethostbyname" );
12
+ exit (1 );
13
+ } else {
14
+ printf ("Host Name: %s\n" , host -> h_name );
15
+ printf ("IP Address: " );
16
+ for (int i = 0 ; host -> h_addr_list [i ] != NULL ; i ++ ){
17
+ printf ("%s " , inet_ntoa (* (struct in_addr * )host -> h_addr_list [i ]));
18
+ }
19
+ printf ("\n" );
20
+ }
21
+
22
+ struct ifaddrs * ifaddr , * ifa ;
23
+ if (getifaddrs (& ifaddr ) == -1 ) {
24
+ perror ("getifaddrs error" );
25
+ exit (1 );
26
+ }
27
+ for (ifa = ifaddr ; ifa != NULL ; ifa = ifa -> ifa_next ){
28
+ if (ifa -> ifa_addr != NULL && ifa -> ifa_addr -> sa_family == AF_INET ){
29
+ printf ("Interface: %s\n" , ifa -> ifa_name );
30
+ printf ("Address: %s\n" , inet_ntoa (((struct sockaddr_in * )ifa -> ifa_addr )-> sin_addr ));
31
+ printf ("Netmask: %s\n" , inet_ntoa (((struct sockaddr_in * )ifa -> ifa_netmask )-> sin_addr ));
32
+ }
33
+ }
34
+
35
+ freeifaddrs (ifaddr );
36
+ }
You can’t perform that action at this time.
0 commit comments