Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
dCache
cta
Commits
cadead6a
Commit
cadead6a
authored
23 years ago
by
Jean-Philippe Baud
Committed by
Steven Murray
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Initial release
parent
70f28b40
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mediachanger/castorrmc/common/Cdomainname.c
+129
-0
129 additions, 0 deletions
mediachanger/castorrmc/common/Cdomainname.c
with
129 additions
and
0 deletions
mediachanger/castorrmc/common/Cdomainname.c
0 → 100644
+
129
−
0
View file @
cadead6a
/*
* Copyright (C) 2002 by CERN/IT/DS/HSM
* All rights reserved
*/
#ifndef lint
static
char
sccsid
[]
=
"@(#)$RCSfile: Cdomainname.c,v $ $Revision: 1.1 $ $Date: 2002/03/14 11:18:42 $ CERN IT-DS/HSM Jean-Philippe Baud"
;
#endif
/* not lint */
#include
<errno.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#if defined(_WIN32)
#include
<winsock2.h>
#else
#include
<netdb.h>
#include
<netinet/in.h>
#include
<sys/socket.h>
#endif
#include
"Castor_limits.h"
#include
"Cnetdb.h"
#include
"serrno.h"
/* Cdomainname - get domain name */
int
DLL_DECL
Cdomainname
(
char
*
name
,
int
namelen
)
{
char
hostname
[
CA_MAXHOSTNAMELEN
+
1
];
struct
hostent
*
hp
;
char
*
p
;
#ifndef _WIN32
FILE
*
fd
;
/*
* try looking in /etc/resolv.conf
* putting this here and assuming that it is correct, eliminates
* calls to gethostbyname, and therefore DNS lookups. This helps
* those on dialup systems.
*/
if
((
fd
=
fopen
(
"/etc/resolv.conf"
,
"r"
))
!=
NULL
)
{
char
line
[
300
];
while
(
fgets
(
line
,
sizeof
(
line
),
fd
)
!=
NULL
)
{
if
((
strncmp
(
line
,
"domain"
,
6
)
==
0
||
strncmp
(
line
,
"search"
,
6
)
==
0
)
&&
line
[
6
]
==
' '
)
{
p
=
line
+
6
;
while
(
*
p
==
' '
)
p
++
;
if
(
*
p
)
*
(
p
+
strlen
(
p
)
-
1
)
=
'\0'
;
if
(
sizeof
(
p
)
>
namelen
)
{
serrno
=
EINVAL
;
return
(
-
1
);
}
strcpy
(
name
,
p
);
return
(
0
);
}
}
fclose
(
fd
);
}
#endif
/* Try gethostname */
gethostname
(
hostname
,
CA_MAXHOSTNAMELEN
+
1
);
if
(
hp
=
Cgethostbyname
(
hostname
))
{
struct
in_addr
*
haddrarray
;
struct
in_addr
**
haddrlist
;
struct
hostent
*
hp2
;
int
i
;
int
naddr
=
0
;
/* need to save list (at least on Digital Unix) */
haddrlist
=
(
struct
in_addr
**
)
hp
->
h_addr_list
;
while
(
*
haddrlist
)
{
naddr
++
;
haddrlist
++
;
}
if
((
haddrarray
=
(
struct
in_addr
*
)
malloc
(
naddr
*
sizeof
(
struct
in_addr
)))
==
NULL
)
{
serrno
=
ENOMEM
;
return
(
-
1
);
}
haddrlist
=
(
struct
in_addr
**
)
hp
->
h_addr_list
;
for
(
i
=
0
;
i
<
naddr
;
i
++
)
{
memcpy
(
haddrarray
+
i
,
*
haddrlist
,
sizeof
(
struct
in_addr
));
haddrlist
++
;
}
for
(
i
=
0
;
i
<
naddr
;
i
++
)
{
if
(
hp2
=
Cgethostbyaddr
(
haddrarray
+
i
,
sizeof
(
struct
in_addr
),
AF_INET
))
{
char
**
hal
;
if
(
p
=
strchr
(
hp2
->
h_name
,
'.'
))
{
free
(
haddrarray
);
p
++
;
if
(
sizeof
(
p
)
>
namelen
)
{
serrno
=
EINVAL
;
return
(
-
1
);
}
strcpy
(
name
,
p
);
return
(
0
);
}
/* Look for aliases */
hal
=
hp2
->
h_aliases
;
while
(
*
hal
)
{
if
(
p
=
strchr
(
*
hal
,
'.'
))
{
free
(
haddrarray
);
p
++
;
if
(
sizeof
(
p
)
>
namelen
)
{
serrno
=
EINVAL
;
return
(
-
1
);
}
strcpy
(
name
,
p
);
return
(
0
);
}
hal
++
;
}
printf
(
"end of list
\n
"
);
}
}
free
(
haddrarray
);
}
serrno
=
SEINTERNAL
;
return
(
-
1
);
}
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