-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinet_addr.c
More file actions
executable file
·40 lines (35 loc) · 1.25 KB
/
inet_addr.c
File metadata and controls
executable file
·40 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// Created by Administrator on 2018/12/28.
//
#include <stdio.h>
#include <arpa/inet.h>
int main(int argc, char *argv[]) {
char *addr1="10.0.0.0";
char *addr2="10.255.255.255";
char *addr3="11.255.255.255";
unsigned long conv_addr=inet_addr(addr1);
if (conv_addr==INADDR_NONE) {
printf("Error occurred! \n");
} else {
printf("Network ordered integer addr: %#lx \n", conv_addr);
printf("Network ordered integer addr: %lu \n", conv_addr);
printf("Host ordered integer addr: %u \n", ntohl(conv_addr));
}
conv_addr=inet_addr(addr2);
if (conv_addr==INADDR_NONE) {
printf("Error occurred! \n");
} else {
printf("Network ordered integer addr: %#lx \n", conv_addr);
printf("Network ordered integer addr: %lu \n", conv_addr);
printf("Host ordered integer addr: %u \n", ntohl(conv_addr));
}
conv_addr=inet_addr(addr3);
if (conv_addr==INADDR_NONE) {
printf("Error occurred! \n");
} else {
printf("Network ordered integer addr: %#lx \n", conv_addr);
printf("Network ordered integer addr: %lu \n", conv_addr);
printf("Host ordered integer addr: %u \n", ntohl(conv_addr));
}
return 0;
}