Code Monkey home page Code Monkey logo

bindp's Introduction

bindp

Intro

With LD_PRELOAD and bindp, you can do:

  • For server application
    • Assign ip and port for listening
    • Add SO_REUSEADDR/SO_REUSEPORT for existing application
  • For socket client
    • Assign special ip and port for connection
    • Add SO_REUSEPORT for reuse the ip add port

Compile

Compile on Linux with:

make

Usage

IP & Port

How to use it:

REUSE_ADDR=1 REUSE_PORT=1 BIND_ADDR="your ip" BIND_PORT="your port" LD_PRELOAD=/your_path/libindp.so The_Command_Here ...

Example in bash to make inetd only listen to the localhost lo interface, thus disabling remote connections and only enable to/from localhost:

BIND_ADDR="127.0.0.1" BIND_PORT="49888" LD_PRELOAD=/your_path/libindp.so curl http://192.168.190.128

OR:

BIND_ADDR="127.0.0.1" LD_PRELOAD=/your_path/libindp.so curl http://192.168.190.128

Just want to change the nginx's listen port:

BIND_PORT=8888 LD_PRELOAD=/your_path/libindp.so /usr/sbin/nginx -c /etc/nginx/nginx.conf

Example in bash to use your virtual IP as your outgoing sourceaddress for ircII:

BIND_ADDR="your-virt-ip" LD_PRELOAD=/your_path/bind.so ircII

Note that you have to set up your server's virtual IP first.

SO_REUSEADDR/SO_REUSEPORT

Now, I add the SO_REUSEADDR/SO_REUSEPORT support within Centos7 or Linux OS with kernel >= 3.9, for the old applictions with multi-process just listen the same port now:

REUSE_ADDR=1 REUSE_PORT=1 LD_PRELOAD=./libindp.so python server.py &

OR

REUSE_ADDR=1 REUSE_PORT=1 BIND_PORT=9999 LD_PRELOAD=./libindp.so java -server -jar your.jar &

With libindp.so's support, you can run your app multi-instance just for you need.

And, for socket client's connect you can also reuse the same client's ip and port:

REUSE_PORT=1 BIND_ADDR="10.10.10.10" BIND_PORT=49999 LD_PRELOAD=/the_path/libindp.so nc 10.10.10.11 10001

REUSE_PORT=1 BIND_ADDR="10.10.10.10" BIND_PORT=49999 LD_PRELOAD=/the_path/libindp.so nc 10.10.10.11 10011

Enjoy it :))

bindp's People

Contributors

yongboy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.