Overview

HTTPS SSH

ip: A simple c library for some useful IP address related functions

I had a small need for some simple IP address related functions, thus this library.

Specifically, there are four functions, that provide the following:

  • cidr_to_netmask - convert a cidr, to a netmask. e.g. /24 to 255.255.255.0
  • broadcast_from_ip - get the broadcast address from an ip address and cidr
  • subnet_from_ip - get the subnet address from an ip address and cidr
  • is_ip_in_subnet - check if an ip address is in a subnet against a cidr.
  • cidr_format_to_ip_and_netmask - convert an ip address in 127.0.0.1/24 format to an ip address and netmask.

I do very little programming of this sort (especially in C!) so I figured I'd publish these so people who are in the same boat as me can hopefully find and use it without too much trouble.

The functions do no error checking of any kind, assuming valid input at all times. If you want error checking you'll have to implement that yourself. I can't do everything for you :)

Also, BSD license. See the LICENSE file for full details. Basically, I don't really care what you do with it. I doubt it would even be legal to claim these bitwise OR and AND operations as my own, to be honest...