Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
ef0d9929
Commit
ef0d9929
authored
14 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
bug 1362: reverted accidental changes
parent
e9f91d1c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
LCS/Common/src/Net/Socket.cc
+35
-24
35 additions, 24 deletions
LCS/Common/src/Net/Socket.cc
with
35 additions
and
24 deletions
LCS/Common/src/Net/Socket.cc
+
35
−
24
View file @
ef0d9929
...
@@ -374,6 +374,21 @@ int32 Socket::initTCPSocket(bool asServer)
...
@@ -374,6 +374,21 @@ int32 Socket::initTCPSocket(bool asServer)
itsTCPAddr
.
sin_family
=
AF_INET
;
itsTCPAddr
.
sin_family
=
AF_INET
;
itsTCPAddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
itsTCPAddr
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
#ifndef HAVE_BGL
// Construct hints for various getaddrinfo lookups
struct
addrinfo
hints
;
memset
(
&
hints
,
0
,
sizeof
(
struct
addrinfo
));
hints
.
ai_family
=
AF_INET
;
// no IPv6
if
(
itsType
==
UDP
)
{
hints
.
ai_socktype
=
SOCK_DGRAM
;
hints
.
ai_protocol
=
IPPROTO_UDP
;
}
else
{
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_protocol
=
IPPROTO_TCP
;
}
#endif
// as Client we must resolve the hostname to connect to.
// as Client we must resolve the hostname to connect to.
if
(
!
asServer
)
{
if
(
!
asServer
)
{
uint32
IPbytes
;
uint32
IPbytes
;
...
@@ -386,25 +401,22 @@ int32 Socket::initTCPSocket(bool asServer)
...
@@ -386,25 +401,22 @@ int32 Socket::initTCPSocket(bool asServer)
return
(
itsErrno
=
BADHOST
);
return
(
itsErrno
=
BADHOST
);
}
}
#else
#else
struct
hostent
*
hostEnt
;
// server host entry
struct
addrinfo
*
hostEnt
;
// server host entry
// No, try to resolve the name
// No, try to resolve the name
if
(
!
(
hostEnt
=
gethostbyname
(
itsHost
.
c_str
()))
)
{
if
(
getaddrinfo
(
itsHost
.
c_str
(),
NULL
,
&
hints
,
&
hostEnt
)
!=
0
)
{
LOG_ERROR
(
formatString
(
"Socket:Hostname (%s) can not be resolved"
,
LOG_ERROR
(
formatString
(
"Socket:Hostname (%s) can not be resolved"
,
itsHost
.
c_str
()));
itsHost
.
c_str
()));
return
(
itsErrno
=
BADHOST
);
return
(
itsErrno
=
BADHOST
);
}
}
// Check type
if
(
hostEnt
->
h_addrtype
!=
AF_INET
)
{
memcpy
(
&
IPbytes
,
&
reinterpret_cast
<
struct
sockaddr_in
*>
(
hostEnt
->
ai_addr
)
->
sin_addr
,
sizeof
IPbytes
);
LOG_ERROR
(
formatString
(
"Socket:Hostname(%s) is not of type AF_INET"
,
freeaddrinfo
(
hostEnt
);
itsHost
.
c_str
()));
return
(
itsErrno
=
BADADDRTYPE
);
}
memcpy
(
&
IPbytes
,
hostEnt
->
h_addr
,
sizeof
(
IPbytes
));
#endif
#endif
}
}
memcpy
((
char
*
)
&
itsTCPAddr
.
sin_addr
.
s_addr
,
(
char
*
)
&
IPbytes
,
memcpy
((
char
*
)
&
itsTCPAddr
.
sin_addr
.
s_addr
,
(
char
*
)
&
IPbytes
,
sizeof
(
IPbytes
)
)
;
sizeof
IPbytes
);
}
}
// try to resolve the service
// try to resolve the service
...
@@ -412,25 +424,24 @@ int32 Socket::initTCPSocket(bool asServer)
...
@@ -412,25 +424,24 @@ int32 Socket::initTCPSocket(bool asServer)
itsProtocolType
=
6
;
// assume tcp
itsProtocolType
=
6
;
// assume tcp
if
(
!
(
itsTCPAddr
.
sin_port
=
htons
((
uint16
)
atoi
(
itsPort
.
c_str
()))))
{
if
(
!
(
itsTCPAddr
.
sin_port
=
htons
((
uint16
)
atoi
(
itsPort
.
c_str
()))))
{
LOG_ERROR
(
formatString
(
"Socket:Portnr/service(%s) can not be resolved"
,
LOG_ERROR
(
formatString
(
"Socket:Portnr/service(%s) can not be resolved"
,
its
Hos
t
.
c_str
()));
its
Por
t
.
c_str
()));
return
(
itsErrno
=
PORT
);
return
(
itsErrno
=
PORT
);
}
}
#else
#else
const
char
*
protocol
=
(
itsType
==
UDP
?
"udp"
:
"tcp"
);
struct
addrinfo
*
servEnt
;
// service info entry
struct
servent
*
servEnt
;
// service info entry
if
((
servEnt
=
getservbyname
(
itsPort
.
c_str
(),
protocol
)))
{
if
(
getaddrinfo
(
NULL
,
itsPort
.
c_str
(),
&
hints
,
&
servEnt
)
!=
0
)
{
itsTCPAddr
.
sin_port
=
servEnt
->
s_port
;
LOG_ERROR
(
formatString
(
}
"Socket:Portnr/service(%s) can not be resolved"
,
else
{
itsPort
.
c_str
()));
if
(
!
(
itsTCPAddr
.
sin_port
=
htons
((
uint16
)
atoi
(
itsPort
.
c_str
()))))
{
return
(
itsErrno
=
PORT
);
LOG_ERROR
(
formatString
(
"Socket:Portnr/service(%s) can not be resolved"
,
itsHost
.
c_str
()));
return
(
itsErrno
=
PORT
);
}
}
}
itsTCPAddr
.
sin_port
=
reinterpret_cast
<
struct
sockaddr_in
*>
(
servEnt
->
ai_addr
)
->
sin_port
;
freeaddrinfo
(
servEnt
);
// Try to map protocol name to protocol number
// Try to map protocol name to protocol number
const
char
*
protocol
=
(
itsType
==
UDP
?
"udp"
:
"tcp"
);
#if defined(HAVE_GETPROTOBYNAME_R)
#if defined(HAVE_GETPROTOBYNAME_R)
struct
protoent
*
protoEnt
;
struct
protoent
*
protoEnt
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment