• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "../include/sane/config.h"
2 
3 #ifndef HAVE_INET_PTON
4 
5 #include <string.h>
6 #include <sys/types.h>
7 #ifdef HAVE_WINSOCK2_H
8 #include <winsock2.h>
9 #endif
10 #ifdef HAVE_SYS_SOCKET_H
11 #include <sys/socket.h>
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
14 #endif
15 
16 int
inet_pton(int af,const char * src,void * dst)17 inet_pton (int af, const char *src, void *dst)
18 {
19 
20   if (af == AF_INET)
21     {
22 
23 #if defined(HAVE_INET_ATON)
24       int result;
25       struct in_addr in;
26 
27       result = inet_aton (src, &in);
28       if (result)
29 	{
30 	  memcpy (dst, &in.s_addr, sizeof (in.s_addr));
31 	  return 1;
32 	}
33       else
34 	return 0;
35 
36 #elif defined(HAVE_INET_ADDR)
37 
38 # if !defined(INADDR_NONE)
39 #  define INADDR_NONE -1
40 # endif /* !defined(INADDR_NONE) */
41       u_int32_t in;
42 
43       in = inet_addr (src);
44       if (in != INADDR_NONE)
45 	{
46 	  memcpy (dst, &in, sizeof (in));
47 	  return 1;
48 	}
49       else
50 	return 0;
51 
52 #endif /* defined(HAVE_INET_ATON) */
53     }
54   return -1;
55 }
56 
57 #endif /* !HAVE_INET_PTON */
58