Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
adf96282
Commit
adf96282
authored
Aug 19, 2013
by
Ben Straub
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1796 from ethomson/fix_inet_pton
Fix p_inet_pton on windows
parents
25b2a555
238b7614
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
31 deletions
+118
-31
src/win32/posix.h
+7
-0
src/win32/posix_w32.c
+27
-31
tests-clar/core/posix.c
+84
-0
No files found.
src/win32/posix.h
View file @
adf96282
...
@@ -12,6 +12,13 @@
...
@@ -12,6 +12,13 @@
#include "utf-conv.h"
#include "utf-conv.h"
#include "dir.h"
#include "dir.h"
/* define some standard errnos that the runtime may be missing. for example,
* mingw lacks EAFNOSUPPORT. */
#ifndef EAFNOSUPPORT
# define EAFNOSUPPORT (INT_MAX-1)
#endif
GIT_INLINE
(
int
)
p_link
(
const
char
*
old
,
const
char
*
new
)
GIT_INLINE
(
int
)
p_link
(
const
char
*
old
,
const
char
*
new
)
{
{
GIT_UNUSED
(
old
);
GIT_UNUSED
(
old
);
...
...
src/win32/posix_w32.c
View file @
adf96282
...
@@ -518,44 +518,40 @@ p_gmtime_r (const time_t *timer, struct tm *result)
...
@@ -518,44 +518,40 @@ p_gmtime_r (const time_t *timer, struct tm *result)
return
result
;
return
result
;
}
}
int
p_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
)
int
p_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
)
{
{
union
{
struct
sockaddr_storage
sin
;
struct
sockaddr_in6
sin6
;
void
*
addr
;
struct
sockaddr_in
sin
;
int
sin_len
=
sizeof
(
struct
sockaddr_storage
),
addr_len
;
}
sa
;
int
error
=
0
;
int
srcsize
;
switch
(
af
)
if
(
af
==
AF_INET
)
{
{
addr
=
&
((
struct
sockaddr_in
*
)
&
sin
)
->
sin_addr
;
case
AF_INET
:
addr_len
=
sizeof
(
struct
in_addr
);
sa
.
sin
.
sin_family
=
AF_INET
;
}
else
if
(
af
==
AF_INET6
)
{
srcsize
=
(
int
)
sizeof
(
sa
.
sin
);
addr
=
&
((
struct
sockaddr_in6
*
)
&
sin
)
->
sin6_addr
;
break
;
addr_len
=
sizeof
(
struct
in6_addr
);
case
AF_INET6
:
}
else
{
sa
.
sin6
.
sin6_family
=
AF_INET6
;
errno
=
EAFNOSUPPORT
;
srcsize
=
(
int
)
sizeof
(
sa
.
sin6
);
break
;
default:
errno
=
WSAEPFNOSUPPORT
;
return
-
1
;
return
-
1
;
}
}
if
(
WSAStringToAddress
((
LPSTR
)
src
,
af
,
NULL
,
(
struct
sockaddr
*
)
&
sa
,
&
srcsize
)
!=
0
)
if
((
error
=
WSAStringToAddressA
((
LPSTR
)
src
,
af
,
NULL
,
(
LPSOCKADDR
)
&
sin
,
&
sin_len
))
==
0
)
{
{
memcpy
(
dst
,
addr
,
addr_len
);
errno
=
WSAGetLastError
();
return
1
;
return
-
1
;
}
}
switch
(
af
)
switch
(
WSAGetLastError
())
{
{
case
WSAEINVAL
:
case
AF_INET
:
return
0
;
memcpy
(
dst
,
&
sa
.
sin
.
sin_addr
,
sizeof
(
sa
.
sin
.
sin_addr
));
case
WSAEFAULT
:
break
;
errno
=
ENOSPC
;
case
AF_INET6
:
return
-
1
;
memcpy
(
dst
,
&
sa
.
sin6
.
sin6_addr
,
sizeof
(
sa
.
sin6
.
sin6_addr
));
case
WSA_NOT_ENOUGH_MEMORY
:
break
;
errno
=
ENOMEM
;
return
-
1
;
}
}
return
1
;
errno
=
EINVAL
;
return
-
1
;
}
}
tests-clar/core/posix.c
0 → 100644
View file @
adf96282
#ifndef _WIN32
# include <arpa/inet.h>
#else
# include <ws2tcpip.h>
# ifdef _MSC_VER
# pragma comment(lib, "ws2_32")
# endif
#endif
#include "clar_libgit2.h"
#include "posix.h"
void
test_core_posix__initialize
(
void
)
{
#ifdef GIT_WIN32
/* on win32, the WSA context needs to be initialized
* before any socket calls can be performed */
WSADATA
wsd
;
cl_git_pass
(
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
wsd
));
cl_assert
(
LOBYTE
(
wsd
.
wVersion
)
==
2
&&
HIBYTE
(
wsd
.
wVersion
)
==
2
);
#endif
}
void
test_core_posix__inet_pton
(
void
)
{
struct
in_addr
addr
;
struct
in6_addr
addr6
;
size_t
i
;
struct
in_addr_data
{
const
char
*
p
;
const
uint8_t
n
[
4
];
};
struct
in6_addr_data
{
const
char
*
p
;
const
uint8_t
n
[
16
];
};
static
struct
in_addr_data
in_addr_data
[]
=
{
{
"0.0.0.0"
,
{
0
,
0
,
0
,
0
}
},
{
"10.42.101.8"
,
{
10
,
42
,
101
,
8
}
},
{
"127.0.0.1"
,
{
127
,
0
,
0
,
1
}
},
{
"140.177.10.12"
,
{
140
,
177
,
10
,
12
}
},
{
"204.232.175.90"
,
{
204
,
232
,
175
,
90
}
},
{
"255.255.255.255"
,
{
255
,
255
,
255
,
255
}
},
};
static
struct
in6_addr_data
in6_addr_data
[]
=
{
{
"::"
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
}
},
{
"::1"
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x01
}
},
{
"0:0:0:0:0:0:0:1"
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x01
}
},
{
"2001:db8:8714:3a90::12"
,
{
0x20
,
0x01
,
0x0d
,
0xb8
,
0x87
,
0x14
,
0x3a
,
0x90
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x12
}
},
{
"fe80::f8ba:c2d6:86be:3645"
,
{
0xfe
,
0x80
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xf8
,
0xba
,
0xc2
,
0xd6
,
0x86
,
0xbe
,
0x36
,
0x45
}
},
{
"::ffff:204.152.189.116"
,
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0xff
,
0xff
,
0xcc
,
0x98
,
0xbd
,
0x74
}
},
};
/* Test some ipv4 addresses */
for
(
i
=
0
;
i
<
6
;
i
++
)
{
cl_assert
(
p_inet_pton
(
AF_INET
,
in_addr_data
[
i
].
p
,
&
addr
)
==
1
);
cl_assert
(
memcmp
(
&
addr
,
in_addr_data
[
i
].
n
,
sizeof
(
struct
in_addr
))
==
0
);
}
/* Test some ipv6 addresses */
for
(
i
=
0
;
i
<
6
;
i
++
)
{
cl_assert
(
p_inet_pton
(
AF_INET6
,
in6_addr_data
[
i
].
p
,
&
addr6
)
==
1
);
cl_assert
(
memcmp
(
&
addr6
,
in6_addr_data
[
i
].
n
,
sizeof
(
struct
in6_addr
))
==
0
);
}
/* Test some invalid strings */
cl_assert
(
p_inet_pton
(
AF_INET
,
""
,
&
addr
)
==
0
);
cl_assert
(
p_inet_pton
(
AF_INET
,
"foo"
,
&
addr
)
==
0
);
cl_assert
(
p_inet_pton
(
AF_INET
,
" 127.0.0.1"
,
&
addr
)
==
0
);
cl_assert
(
p_inet_pton
(
AF_INET
,
"bar"
,
&
addr
)
==
0
);
cl_assert
(
p_inet_pton
(
AF_INET
,
"10.foo.bar.1"
,
&
addr
)
==
0
);
/* Test unsupported address families */
cl_git_fail
(
p_inet_pton
(
12
,
"52.472"
,
NULL
));
/* AF_DECnet */
cl_assert_equal_i
(
EAFNOSUPPORT
,
errno
);
cl_git_fail
(
p_inet_pton
(
5
,
"315.124"
,
NULL
));
/* AF_CHAOS */
cl_assert_equal_i
(
EAFNOSUPPORT
,
errno
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment