C library for api.ipify.org
lipify connects to http://api.ipify.org to query your current IP address. Both IPv4 and IPv6 is supported, for connecting to the ipify server and returning your address.
The library weighs in at 14 kiB. A versioned tarball can be downloaded from GitHub: https://github.com/troglobit/lipify/releases
Build & Install
By default, lipify installs to /usr/local:
make
make install
The default can be changed by setting the prefix= variable at install:
make install prefix=/opt
The
DESTDIR=variable is also supported, for the benefit of packagers.
Example
The simplest example of lipify looks like this:
#include <stdio.h>
#include <ipify.h>
int main(void)
{
char addr[256];
if (ipify(addr, sizeof(addr)))
return 1;
printf("%s\n", addr);
return 0;
}
You can also get a descriptor, to use with poll() or an event loop library like
libuEv, like this:
#include <ipify.h>
int main(void)
{
int sd;
char addr[256];
sd = ipify_connect();
if (sd < 0)
return 1;
if (!ipify_query(sd, addr, sizeof(addr)))
printf("%s\n", addr);
return ipify_disconnect(sd);
}
License
lipify is free software, licensed to you under the very permissive ISC license. See the file LICENSE in the lipify distribution for details.
Origin & References
lipify is written by Joachim Wiberg, post bug reports and pull requests to the project's GitHub repository at https://github.com/troglobit/lipify
Copyright (c) 2015-2022 Joachim Wiberg <troglobit@gmail.com> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Contributing to the Project
Thank you for considering contributing back to Free Software!
There are a few things we would like you to consider when filing an issue or pull request with this project:
-
If you are filing a bug report or feature request
Please take the time to check if an issue already has been filed matching your problem
-
What version are you running, have you tried the latest release?
UNIX distributions often package and test software for their particular brand. If you are using a pre-packaged version, then please file a bug with that distribution instead.
-
Coding Style
Lines are allowed to be longer than 72 characters these days, there is no enforced max. length.
Tip: Always submit code that follows the style of surrounding code!
The coding style itself is strictly Linux KNF, like GIT it is becoming a de facto standard for C programming
https://www.kernel.org/doc/Documentation/CodingStyle
-
Logical Change Sets
Changes should be broken down into logical units that add a feature or fix a bug. Keep changes separate from each other and do not mix a bug fix with a whitespace cleanup or a new feature addition.
This is important not only for readability, or for the possibility of maintainers to revert changes, but does also increase your chances of having a change accepted.
-
Commit messages
Commit messages exist to track why a change was made. Try to be as clear and concise as possible in your commit messages, and always, be proud of your work and set up a proper GIT identity for your commits:
git config --global user.name "J. Random Hacker" git config --global user.email random.j.hacker@example.comSee this helpful guide for how to write simple, readable commit messages, or have at least a look at the below example.
http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
Example
Example commit message from the Pro Git online book, notice
how git commit -s is used to automatically add a Signed-off-by:
Capitalized, short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Write your commit message in the imperative: "Fix bug" and not "Fixed bug"
or "Fixes bug." This convention matches up with commit messages generated
by commands like git merge and git revert.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, followed by a
single space, with blank lines in between, but conventions vary here
- Use a hanging indent
Signed-off-by: J. Random Hacker <random.j.hacker@example.com>