Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
400744f2
Commit
400744f2
authored
Mar 11, 2015
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a new VSS_resolver() function which feeds suckaddr's to a
callback function.
parent
ce4894b1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
14 deletions
+60
-14
vss.h
include/vss.h
+6
-0
vss.c
lib/libvarnish/vss.c
+54
-14
No files found.
include/vss.h
View file @
400744f2
...
...
@@ -28,8 +28,14 @@
/* vss.c */
struct
vss_addr
;
struct
suckaddr
;
const
char
*
VSS_parse
(
char
*
str
,
char
**
addr
,
char
**
port
);
typedef
int
resolved_f
(
void
*
priv
,
const
struct
suckaddr
*
);
int
VSS_resolver
(
const
char
*
addr
,
const
char
*
def_port
,
resolved_f
*
func
,
void
*
priv
,
const
char
**
err
);
int
VSS_resolve
(
const
char
*
addr
,
const
char
*
port
,
struct
vss_addr
***
ta
);
int
VSS_bind
(
const
struct
vss_addr
*
addr
);
int
VSS_listen
(
const
struct
vss_addr
*
addr
,
int
depth
);
...
...
lib/libvarnish/vss.c
View file @
400744f2
...
...
@@ -44,6 +44,7 @@
#include <unistd.h>
#include "vas.h"
#include "vsa.h"
#include "vss.h"
#include "vtcp.h"
...
...
@@ -105,6 +106,56 @@ VSS_parse(char *str, char **addr, char **port)
return
(
NULL
);
}
/*
* Look up an address, using a default port if provided, and call
* the callback function with the suckaddrs we find.
* If the callback function returns anything but zero, we terminate
* and pass that value.
*/
int
VSS_resolver
(
const
char
*
addr
,
const
char
*
def_port
,
resolved_f
*
func
,
void
*
priv
,
const
char
**
err
)
{
struct
addrinfo
hints
,
*
res0
,
*
res
;
struct
suckaddr
*
vsa
;
char
*
h
;
char
*
adp
,
*
hop
;
int
ret
;
*
err
=
NULL
;
h
=
strdup
(
addr
);
AN
(
h
);
*
err
=
VSS_parse
(
h
,
&
hop
,
&
adp
);
if
(
*
err
!=
NULL
)
{
free
(
h
);
return
(
-
1
);
}
if
(
adp
!=
NULL
)
def_port
=
adp
;
memset
(
&
hints
,
0
,
sizeof
hints
);
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_flags
=
AI_PASSIVE
;
ret
=
getaddrinfo
(
hop
,
def_port
,
&
hints
,
&
res0
);
free
(
h
);
if
(
ret
!=
0
)
{
*
err
=
gai_strerror
(
ret
);
return
(
-
1
);
}
for
(
res
=
res0
;
res
!=
NULL
;
res
=
res
->
ai_next
)
{
vsa
=
VSA_Malloc
(
res
->
ai_addr
,
res
->
ai_addrlen
);
if
(
vsa
!=
NULL
)
{
ret
=
func
(
priv
,
vsa
);
free
(
vsa
);
if
(
ret
)
break
;
}
}
freeaddrinfo
(
res0
);
return
(
ret
);
}
/*
* For a given host and port, return a list of struct vss_addr, which
* contains all the information necessary to open and bind a socket. One
...
...
@@ -128,7 +179,6 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap)
struct
addrinfo
hints
,
*
res0
,
*
res
;
struct
vss_addr
**
va
;
int
i
,
ret
;
long
int
ptst
;
char
*
h
;
char
*
adp
,
*
hop
;
...
...
@@ -144,25 +194,15 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap)
return
(
0
);
}
if
(
adp
==
NULL
)
ret
=
getaddrinfo
(
addr
,
port
,
&
hints
,
&
res0
);
else
{
ptst
=
strtol
(
adp
,
NULL
,
10
);
if
(
ptst
<
0
||
ptst
>
65535
)
{
free
(
h
);
return
(
0
);
}
ret
=
getaddrinfo
(
hop
,
adp
,
&
hints
,
&
res0
);
}
ret
=
getaddrinfo
(
hop
,
adp
==
NULL
?
port
:
adp
,
&
hints
,
&
res0
);
free
(
h
);
if
(
ret
!=
0
)
return
(
0
);
XXXAN
(
res0
);
for
(
res
=
res0
,
i
=
0
;
res
!=
NULL
;
res
=
res
->
ai_next
,
++
i
)
/* nothing */
;
for
(
res
=
res0
,
i
=
0
;
res
!=
NULL
;
res
=
res
->
ai_next
)
i
++
;
if
(
i
==
0
)
{
freeaddrinfo
(
res0
);
return
(
0
);
...
...
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