Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
33a2a872
Commit
33a2a872
authored
Nov 18, 2007
by
Jan Djärv
Browse files
(socket_connection): Use getaddrinfo if available.
parent
95fbaefc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
5 deletions
+55
-5
lib-src/ChangeLog
lib-src/ChangeLog
+4
-0
lib-src/pop.c
lib-src/pop.c
+51
-5
No files found.
lib-src/ChangeLog
View file @
33a2a872
2007-11-18 Jan Dj,Ad(Brv <jan.h.d@swipnet.se>
* pop.c (socket_connection): Use getaddrinfo if available.
2007-11-15 Francesco Potort,Al(B <pot@gnu.org>
* etags.c: Make prototypes for extern definitions, and add all
...
...
lib-src/pop.c
View file @
33a2a872
...
...
@@ -1010,7 +1010,13 @@ socket_connection (host, flags)
char
*
host
;
int
flags
;
{
#ifdef HAVE_GETADDRINFO
struct
addrinfo
*
res
,
*
it
;
struct
addrinfo
hints
;
int
ret
;
#else
/* !HAVE_GETADDRINFO */
struct
hostent
*
hostent
;
#endif
struct
servent
*
servent
;
struct
sockaddr_in
addr
;
char
found_port
=
0
;
...
...
@@ -1036,6 +1042,7 @@ socket_connection (host, flags)
#endif
/* KERBEROS */
int
try_count
=
0
;
int
connect_ok
;
#ifdef WINDOWSNT
{
...
...
@@ -1097,6 +1104,41 @@ socket_connection (host, flags)
}
#ifdef HAVE_GETADDRINFO
memset
(
&
hints
,
0
,
sizeof
(
hints
));
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_flags
=
AI_ADDRCONFIG
;
hints
.
ai_family
=
AF_INET
;
do
{
ret
=
getaddrinfo
(
host
,
service
,
&
hints
,
&
res
);
try_count
++
;
if
(
ret
!=
0
&&
(
ret
!=
EAI_AGAIN
||
try_count
==
5
))
{
strcpy
(
pop_error
,
"Could not determine POP server's address"
);
return
(
-
1
);
}
}
while
(
ret
!=
0
);
if
(
ret
==
0
)
{
it
=
res
;
while
(
it
)
{
if
(
it
->
ai_addrlen
==
sizeof
(
addr
))
{
struct
sockaddr_in
*
in_a
=
(
struct
sockaddr_in
*
)
it
->
ai_addr
;
bcopy
(
&
in_a
->
sin_addr
,
(
char
*
)
&
addr
.
sin_addr
,
sizeof
(
addr
.
sin_addr
));
if
(
!
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
)))
break
;
}
it
=
it
->
ai_next
;
}
connect_ok
=
it
!=
NULL
;
freeaddrinfo
(
res
);
}
#else
/* !HAVE_GETADDRINFO */
do
{
hostent
=
gethostbyname
(
host
);
...
...
@@ -1116,10 +1158,12 @@ socket_connection (host, flags)
break
;
hostent
->
h_addr_list
++
;
}
connect_ok
=
*
hostent
->
h_addr_list
!=
NULL
;
#endif
/* !HAVE_GETADDRINFO */
#define CONNECT_ERROR "Could not connect to POP server: "
if
(
!
*
hostent
->
h_addr_list
)
if
(
!
connect_ok
)
{
CLOSESOCKET
(
sock
);
strcpy
(
pop_error
,
CONNECT_ERROR
);
...
...
@@ -1130,6 +1174,10 @@ socket_connection (host, flags)
}
#ifdef KERBEROS
realhost
=
alloca
(
strlen
(
hostent
->
h_name
)
+
1
);
strcpy
(
realhost
,
hostent
->
h_name
);
#define KRB_ERROR "Kerberos error connecting to POP server: "
if
(
!
(
flags
&
POP_NO_KERBEROS
))
{
...
...
@@ -1157,7 +1205,7 @@ socket_connection (host, flags)
if
(
rem
=
krb5_cc_get_principal
(
kcontext
,
ccdef
,
&
client
))
goto
krb5error
;
for
(
cp
=
host
ent
->
h_name
;
*
cp
;
cp
++
)
for
(
cp
=
real
host
;
*
cp
;
cp
++
)
{
if
(
isupper
(
*
cp
))
{
...
...
@@ -1165,7 +1213,7 @@ socket_connection (host, flags)
}
}
if
(
rem
=
krb5_sname_to_principal
(
kcontext
,
host
ent
->
h_name
,
if
(
rem
=
krb5_sname_to_principal
(
kcontext
,
real
host
,
POP_SERVICE
,
FALSE
,
&
server
))
goto
krb5error
;
...
...
@@ -1210,7 +1258,6 @@ socket_connection (host, flags)
}
#else
/* ! KERBEROS5 */
ticket
=
(
KTEXT
)
malloc
(
sizeof
(
KTEXT_ST
));
realhost
=
strdup
(
hostent
->
h_name
);
rem
=
krb_sendauth
(
0L
,
sock
,
ticket
,
"pop"
,
realhost
,
(
char
*
)
krb_realmofhost
(
realhost
),
(
unsigned
long
)
0
,
&
msg_data
,
&
cred
,
schedule
,
...
...
@@ -1218,7 +1265,6 @@ socket_connection (host, flags)
(
struct
sockaddr_in
*
)
0
,
"KPOPV0.1"
);
free
((
char
*
)
ticket
);
free
(
realhost
);
if
(
rem
!=
KSUCCESS
)
{
strcpy
(
pop_error
,
KRB_ERROR
);
...
...
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