A simple little wrapper script to allow you to fake the local hostname (Linux)
Shell Makefile C Java
Switch branches/tags
Nothing to show
Latest commit ea5a15c Jan 16, 2017 @nonspecialist committed on GitHub Merge pull request #2 from codemedic/fix-issue-1-shellcheck-warnings
Fix #1 fixed all shellcheck errors / warnings
Permalink
Failed to load latest commit information.
.gitignore
HostnameApp.java
LICENSE
Makefile
README.md
fakehostname
fakehostname.c
fakehostname.spec

README.md

What is this?

An example override of the libc function gethostname(2).

How do I use it?

  • build the shared library (make) or the RPM (make rpm)
  • install it somewhere (make install) or (rpm -ivh .../path/to/new-rpm)
  • either:
    • set the installed shared library to be loaded prior to libc (export LD_PRELOAD=/path/to/shared/library.so.1)
    • set the environment variable MYHOSTNAME to whatever hostname you want (note HOST_NAME_MAX is usually 64 characters)
    • run your application normally
  • or
    • use the included fakehostname wrapper to launch your application

If you don't set $MYHOSTNAME, the actual hostname returned by the real gethostname(2) call will be used

Wrapper Script

I also wrote a little wrapper script called fakehostname which you can install in your $PATH (eg /usr/local/bin) which will set LD_PRELOAD for you and call your binary with the hostname set:

fakehostname <pretend-hostname> <original-command> [original-command-args]

License

This code is licensed under the GPLv3 -- a copy of the license can be found in the file LICENSE.