blob: 7638b6e9f210e630257d59928468b38ff8353b14 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include "../include/sane/config.h"
#ifndef HAVE_INET_PTON
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
int
inet_pton (int af, const char *src, void *dst)
{
if (af == AF_INET)
{
#if defined(HAVE_INET_ATON)
int result;
struct in_addr in;
result = inet_aton (src, &in);
if (result)
{
memcpy (dst, &in.s_addr, sizeof (in.s_addr));
return 1;
}
else
return 0;
#elif defined(HAVE_INET_ADDR)
# if !defined(INADDR_NONE)
# define INADDR_NONE -1
# endif /* !defined(INADDR_NONE) */
u_int32_t in;
in = inet_addr (src);
if (in != INADDR_NONE)
{
memcpy (dst, &in, sizeof (in));
return 1;
}
else
return 0;
#endif /* defined(HAVE_INET_ATON) */
}
return -1;
}
#endif /* !HAVE_INET_PTON */
|