|
Last change
on this file since 2036 was 2036, checked in by bird, 20 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
|
File size:
671 bytes
|
| Line | |
|---|
| 1 | #include <stdio.h>
|
|---|
| 2 | #include <string.h>
|
|---|
| 3 | #include <arpa/inet.h>
|
|---|
| 4 | #include <netinet/in.h>
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 | static int
|
|---|
| 8 | test (unsigned int inaddr, const char *expected)
|
|---|
| 9 | {
|
|---|
| 10 | struct in_addr addr;
|
|---|
| 11 | char *res;
|
|---|
| 12 | int fail;
|
|---|
| 13 |
|
|---|
| 14 | addr.s_addr = htonl (inaddr);
|
|---|
| 15 | res = inet_ntoa (addr);
|
|---|
| 16 | fail = strcmp (res, expected);
|
|---|
| 17 |
|
|---|
| 18 | printf ("%#010x -> \"%s\" -> %s%s\n", inaddr, res,
|
|---|
| 19 | fail ? "fail, expected" : "ok", fail ? expected : "");
|
|---|
| 20 |
|
|---|
| 21 | return fail;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | int
|
|---|
| 26 | main (void)
|
|---|
| 27 | {
|
|---|
| 28 | int result = 0;
|
|---|
| 29 |
|
|---|
| 30 | result |= test (INADDR_LOOPBACK, "127.0.0.1");
|
|---|
| 31 | result |= test (INADDR_BROADCAST, "255.255.255.255");
|
|---|
| 32 | result |= test (INADDR_ANY, "0.0.0.0");
|
|---|
| 33 | result |= test (0xc0060746, "192.6.7.70");
|
|---|
| 34 |
|
|---|
| 35 | return result;
|
|---|
| 36 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.