Skip to content

gethostname is a package to mock the gethostname() Sys call with a custom host name

License

Notifications You must be signed in to change notification settings

elulcao/gethostname

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gethostname

C/C++ CI

gethostname is a package to mock the gethostname() Sys call with a custom host name The gethostname() Sys call is intercepted via LD_PRELOAD before other libs are loaded.

The main intention of this change is to allow Host Names with "_" characters.

Installation

Execute the yum or dnf command and verify /usr/lib64/libgethostname.so.1 has been added to the container path:

dnf install -y gethostname

Usage

Define NEWHOSTNAME and LD_PRELOAD to spoof the container Host Name inside a container.

$ export NEWHOSTNAME=my_host_name
$ export LD_PRELOAD=/usr/lib64/libgethostname.so.1
$ hostname
my_host_name

Test

Makefile can be used to verify the result for modifying the hostname.

$ make build
gcc -fPIC -rdynamic -g -Wall -shared -Wl,-soname,libgethostname.so.1 -lc -ldl -o libgethostname.so.1 gethostname.c

$ make test
LD_PRELOAD=~/home/opc/GitLab/cicd/gethostname/libgethostname.so.1 NEWHOSTNAME=my_host_name hostname
my_host_name

About

gethostname is a package to mock the gethostname() Sys call with a custom host name

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published