curl/docs/examples
Viktor Szakats 39dec13ec0
build: always use local inet_pton()/inet_ntop() implementations
Also repurpose existing build-time feature checks into unit test 1961,
to verify.

Prior to this patch these functions were auto-detected with both
autotools and cmake. In case of autotools there was an extra
verification phase ensuring the functions work as expected. This step
required running the function, thus was limited to non-cross-builds. For
cross-builds and CMake it always used the system implementation if
present. On Windows it always used the local implementation, because
availability/use is complicated there.

After this patch all platforms, always use the local implementation,
which is known to be accurate. This makes curl behave more consistently,
and simplifies the build process, a fixes cross-builds and CMake
auto-detection differences.

Also:
- test1960: enable unconditionally.
- checksrc: disallow globally, allowlist in `block_ip.c` example.
- dnsd: verify ntop result for NULL before passing to printf.

Ref: https://github.com/curl/curl/pull/22137#issuecomment-4797440983
Ref: #22137
Ref: 8537a5b0bc #16577

Closes #22170
2026-06-27 01:24:39 +02:00
..
.checksrc build: tidy up curl-specific fstat calls and stat struct type 2026-02-02 18:57:13 +01:00
.gitignore examples/threaded-ssl: delete in favor of examples/threaded 2025-12-17 00:32:20 +01:00
10-at-a-time.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
adddocsref.pl tidy-up: syntax and code nits 2026-06-26 15:45:24 +02:00
address-scope.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
altsvc.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
anyauthput.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
block_ip.c build: always use local inet_pton()/inet_ntop() implementations 2026-06-27 01:24:39 +02:00
cacertinmem.c tidy-up: make 'CA' uppercase, where missing 2026-06-22 21:04:45 +02:00
certinfo.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
chkspeed.c tidy-up: miscellaneous 2026-06-11 19:48:07 +02:00
CMakeLists.txt cmake: drop support for CMake 3.17 and older 2026-03-21 13:24:47 +01:00
connect-to.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
cookie_interface.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
crawler.c tidy-up: drop redundant != NULL syntax 2026-06-09 14:37:36 +02:00
debug.c tidy-up: miscellaneous 2026-04-14 01:08:32 +02:00
default-scheme.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ephiperfifo.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
evhiperfifo.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
externalsocket.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
fileupload.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
ftp-delete.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
ftp-wildcard.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftpget.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
ftpgetinfo.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
ftpgetresp.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ftpsget.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
ftpupload.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
ftpuploadfrommem.c docs: rename CURLcode variables to 'result' 2025-12-17 08:55:12 +01:00
ftpuploadresume.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
getinfo.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
getinmemory.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
getredirect.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
getreferrer.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ghiper.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
headerapi.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
hiperfifo.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
hsts-preload.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
htmltidy.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
htmltitle.cpp tidy-up: drop redundant == NULL syntax 2026-06-09 14:37:36 +02:00
http-options.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http-post.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
http2-download.c tidy-up: miscellaneous 2026-06-11 19:48:07 +02:00
http2-pushinmemory.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
http2-serverpush.c tidy-up: docs, comments, typos, whitespace 2026-06-26 11:36:09 +02:00
http2-upload.c tidy-up: miscellaneous 2026-06-11 19:48:07 +02:00
http3-present.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
http3.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
httpcustomheader.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
httpput-postfields.c tidy-up: miscellaneous 2026-06-14 20:10:28 +02:00
httpput.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
https.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-append.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-authzid.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-copy.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-create.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-delete.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-examine.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-fetch.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-list.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-lsub.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-multi.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-noop.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
imap-search.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
imap-ssl.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-store.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
imap-tls.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
interface.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
ipv6.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
keepalive.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
localport.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
log_failed_transfers.c tidy-up: syntax and code nits 2026-06-26 15:45:24 +02:00
Makefile.am cmake: support building some complicated examples, build them in CI 2025-10-07 19:09:02 +02:00
Makefile.example Makefile.example: make default options more likely to work 2025-10-20 13:52:58 +02:00
Makefile.inc examples/threaded-ssl: delete in favor of examples/threaded 2025-12-17 00:32:20 +01:00
maxconnects.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
multi-app.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
multi-debugcallback.c tidy-up: miscellaneous 2026-04-14 01:08:32 +02:00
multi-double.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
multi-event.c tool_operate: remove call to abort() 2026-06-26 13:41:55 +02:00
multi-formadd.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-legacy.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
multi-post.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
multi-single.c badwords: avoid 'simply' 2026-03-10 19:34:06 +01:00
multi-uv.c tool_operate: remove call to abort() 2026-06-26 13:41:55 +02:00
netrc.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
parseurl.c examples: tidy-up headers and includes 2025-11-18 02:05:07 +01:00
persistent.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-authzid.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-dele.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-list.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-multi.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-noop.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
pop3-retr.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-ssl.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-stat.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
pop3-tls.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
pop3-top.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
pop3-uidl.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
post-callback.c docs: rename CURLcode variables to 'result' 2025-12-17 08:55:12 +01:00
postinmemory.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
postit2-formadd.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
postit2.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
progressfunc.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
protofeats.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
range.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
README.md stop using the word 'just' 2026-03-03 15:30:22 +01:00
resolve.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
rtsp-options.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
sendrecv.c gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings 2026-03-18 11:33:37 +01:00
sepheaders.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
sessioninfo.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
sftpget.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
sftpuploadresume.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
shared-connection-cache.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
simple.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
simplepost.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
simplessl.c tidy-up: miscellaneous 2026-05-20 00:50:43 +02:00
smooth-gtk-thread.c tidy-up: drop stray comparisons with literal zero 2026-06-10 15:15:54 +02:00
smtp-authzid.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-expn.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
smtp-mail.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-mime.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
smtp-multi.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-ssl.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-tls.c stop using the word 'just' 2026-03-03 15:30:22 +01:00
smtp-vrfy.c tidy-up: miscellaneous 2026-02-25 14:44:56 +01:00
sslbackend.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
synctime.c tidy-up: syntax and code nits 2026-06-26 15:45:24 +02:00
threaded.c build: drop redundant HAVE_PTHREAD_H guard 2026-03-30 18:57:07 +02:00
unixsocket.c tidy-up: miscellaneous 2026-02-12 14:52:16 +01:00
url2file.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
urlapi.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
usercertinmem.c docs: use the correct CURLOPT_WRITEFUNCTION signature 2026-04-08 11:25:54 +02:00
version-check.pl perl: || die -> or die 2026-06-16 00:41:29 +02:00
websocket-cb.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00
websocket-updown.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
websocket.c build: enable -Wformat-signedness, fix issues found 2026-06-10 15:14:08 +02:00
xmlstream.c docs: compare result against literal CURLE_OK (where missing) 2026-02-07 19:40:45 +01:00

libcurl examples

This directory is for libcurl programming examples. They are meant to show some simple steps on how you can build your own application to take full advantage of libcurl.

If you end up with other small but still useful example sources, please mail them for submission in future packages and on the website.

Building

The Makefile.example is an example Makefile that could be used to build these examples. Edit the file according to your system and requirements first.

Most examples should build fine using a command line like this:

`curl-config --cc --cflags --libs` -o example-my example.c

Some compilers do not like having the arguments in this order but instead want you do reorganize them like:

`curl-config --cc` -o example-my example.c `curl-config --cflags --libs`

Please do not use the curl.se site as a test target for your libcurl applications/experiments. Even if some of the examples use that site as a URL at some places, it does not mean that the URLs work or that we expect you to actually torture our website with your tests. Thanks.

Examples

Each example source code file is designed to be and work stand-alone and rather self-explanatory. The examples may at times lack the level of error checks you need in a real world, but that is then only for the sake of readability: to make the code smaller and easier to follow.