Skip to content

Commit db02574

Browse files
committed
C library: model inet_ntoa
Implement IPv4 inet_ntoa (translation from numeric addresses to a string representation) by non-deterministically setting the byte string.
1 parent 71edec7 commit db02574

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _WIN32
2+
# include <arpa/inet.h>
3+
#endif
4+
5+
int main()
6+
{
7+
#ifndef _WIN32
8+
struct in_addr input;
9+
char *result = inet_ntoa(input);
10+
(void)*result;
11+
#endif
12+
return 0;
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--pointer-check --bounds-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/ansi-c/library/inet.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ int inet_aton(const char *cp, struct in_addr *pin)
5151

5252
#endif
5353

54+
/* FUNCTION: inet_ntoa */
55+
56+
#ifndef _WIN32
57+
58+
# ifndef __CPROVER_INET_H_INCLUDED
59+
# include <arpa/inet.h>
60+
# define __CPROVER_INET_H_INCLUDED
61+
# endif
62+
63+
char __inet_ntoa_buffer[16];
64+
65+
char *inet_ntoa(struct in_addr in)
66+
{
67+
__CPROVER_HIDE:;
68+
(void)in;
69+
// the last byte remains zero to ensure string termination
70+
__CPROVER_havoc_slice(__inet_ntoa_buffer, 15);
71+
return __inet_ntoa_buffer;
72+
}
73+
74+
#endif
75+
5476
/* FUNCTION: inet_network */
5577

5678
#ifndef _WIN32

0 commit comments

Comments
 (0)