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
345eef23
Commit
345eef23
authored
Nov 07, 2012
by
Eduardo Bart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move inet_pton to posix platform-compatibility layer
parent
d1a69d0f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
52 deletions
+49
-52
src/netops.c
+2
-50
src/netops.h
+0
-1
src/posix.c
+2
-0
src/unix/posix.h
+1
-0
src/win32/posix.h
+1
-0
src/win32/posix_w32.c
+43
-1
No files found.
src/netops.c
View file @
345eef23
...
...
@@ -274,11 +274,11 @@ static int verify_server_cert(gitno_ssl *ssl, const char *host)
}
/* Try to parse the host as an IP address to see if it is */
if
(
gitno
_inet_pton
(
AF_INET
,
host
,
&
addr4
))
{
if
(
p
_inet_pton
(
AF_INET
,
host
,
&
addr4
))
{
type
=
GEN_IPADD
;
addr
=
&
addr4
;
}
else
{
if
(
gitno
_inet_pton
(
AF_INET6
,
host
,
&
addr6
))
{
if
(
p
_inet_pton
(
AF_INET6
,
host
,
&
addr6
))
{
type
=
GEN_IPADD
;
addr
=
&
addr6
;
}
...
...
@@ -597,51 +597,3 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const
return
0
;
}
int
gitno_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
)
{
/* inet_pton is only available in Windows Vista or later
* mingw32 and cygwin give compile errors */
#ifndef GIT_WIN32
return
inet_pton
(
af
,
src
,
dst
);
#else
union
{
struct
sockaddr_in6
sin6
;
struct
sockaddr_in
sin
;
}
sa
;
size_t
srcsize
;
switch
(
af
)
{
case
AF_INET
:
sa
.
sin
.
sin_family
=
AF_INET
;
srcsize
=
sizeof
(
sa
.
sin
);
break
;
case
AF_INET6
:
sa
.
sin6
.
sin6_family
=
AF_INET6
;
srcsize
=
sizeof
(
sa
.
sin6
);
break
;
default:
errno
=
WSAEPFNOSUPPORT
;
return
-
1
;
}
if
(
WSAStringToAddress
(
src
,
af
,
NULL
,
(
struct
sockaddr
*
)
&
sa
,
&
srcsize
)
!=
0
)
{
errno
=
WSAGetLastError
();
return
-
1
;
}
switch
(
af
)
{
case
AF_INET
:
memcpy
(
dst
,
&
sa
.
sin
.
sin_addr
,
sizeof
(
sa
.
sin
.
sin_addr
));
break
;
case
AF_INET6
:
memcpy
(
dst
,
&
sa
.
sin6
.
sin6_addr
,
sizeof
(
sa
.
sin6
.
sin6_addr
));
break
;
}
return
1
;
#endif
}
src/netops.h
View file @
345eef23
...
...
@@ -67,6 +67,5 @@ int gitno_close(gitno_socket *s);
int
gitno_select_in
(
gitno_buffer
*
buf
,
long
int
sec
,
long
int
usec
);
int
gitno_extract_host_and_port
(
char
**
host
,
char
**
port
,
const
char
*
url
,
const
char
*
default_port
);
int
gitno_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
);
#endif
src/posix.c
View file @
345eef23
...
...
@@ -205,3 +205,5 @@ int p_write(git_file fd, const void *buf, size_t cnt)
}
return
0
;
}
src/unix/posix.h
View file @
345eef23
...
...
@@ -21,5 +21,6 @@
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
#define p_mkstemp(p) mkstemp(p)
#define p_setenv(n,v,o) setenv(n,v,o)
#define p_inet_pton(a, b, c) inet_pton(a, b, c)
#endif
src/win32/posix.h
View file @
345eef23
...
...
@@ -48,5 +48,6 @@ extern int p_getcwd(char *buffer_out, size_t size);
extern
int
p_rename
(
const
char
*
from
,
const
char
*
to
);
extern
int
p_recv
(
GIT_SOCKET
socket
,
void
*
buffer
,
size_t
length
,
int
flags
);
extern
int
p_send
(
GIT_SOCKET
socket
,
const
void
*
buffer
,
size_t
length
,
int
flags
);
extern
int
p_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
);
#endif
src/win32/posix_w32.c
View file @
345eef23
...
...
@@ -11,7 +11,7 @@
#include <errno.h>
#include <io.h>
#include <fcntl.h>
#include <ws2tcpip.h>
int
p_unlink
(
const
char
*
path
)
{
...
...
@@ -504,3 +504,45 @@ int p_gettimeofday(struct timeval *tv, struct timezone *tz)
return
0
;
}
int
p_inet_pton
(
int
af
,
const
char
*
src
,
void
*
dst
)
{
union
{
struct
sockaddr_in6
sin6
;
struct
sockaddr_in
sin
;
}
sa
;
size_t
srcsize
;
switch
(
af
)
{
case
AF_INET
:
sa
.
sin
.
sin_family
=
AF_INET
;
srcsize
=
sizeof
(
sa
.
sin
);
break
;
case
AF_INET6
:
sa
.
sin6
.
sin6_family
=
AF_INET6
;
srcsize
=
sizeof
(
sa
.
sin6
);
break
;
default:
errno
=
WSAEPFNOSUPPORT
;
return
-
1
;
}
if
(
WSAStringToAddress
(
src
,
af
,
NULL
,
(
struct
sockaddr
*
)
&
sa
,
&
srcsize
)
!=
0
)
{
errno
=
WSAGetLastError
();
return
-
1
;
}
switch
(
af
)
{
case
AF_INET
:
memcpy
(
dst
,
&
sa
.
sin
.
sin_addr
,
sizeof
(
sa
.
sin
.
sin_addr
));
break
;
case
AF_INET6
:
memcpy
(
dst
,
&
sa
.
sin6
.
sin6_addr
,
sizeof
(
sa
.
sin6
.
sin6_addr
));
break
;
}
return
1
;
}
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