Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/block-ip: show how to block IP addresses #15748

Closed
wants to merge 1 commit into from

Conversation

jay
Copy link
Member

@jay jay commented Dec 15, 2024

  • Show how CURLOPT_OPENSOCKETFUNCTION can be used to block IP addresses.

This is a new example that demonstrates IP blocking.

Ref: #15710 (reply in thread)

Closes #xxxx

@jay
Copy link
Member Author

jay commented Dec 15, 2024

Is -Werror=missing-prototypes really needed for examples?

@vszakats
Copy link
Member

vszakats commented Dec 15, 2024

Is -Werror=missing-prototypes really needed for examples?

It adds complexity to apply and remember different rules for
different parts of the codebase. Examples can be copied and
compiled by users outside of curl and may have this warning
enabled there.

Isn't it simpler to add static to the 4 local functions?

@bagder
Copy link
Member

bagder commented Dec 15, 2024

Isn't it simpler to add static to the 4 local functions?

I believe so. We encourage use of static for local functions anyway.

@jay
Copy link
Member Author

jay commented Dec 17, 2024

@vszakats do you have any suggestion for the failing amiga CI job? Does it not have a working inet ntop/pton? I see in your commit that recently created the job that: inet_ntop, inet_pton: fix using it for AmigaOS. cmake detects them, and they did not compile with AmigaOS. Should this example be excluded from that platform?

@vszakats
Copy link
Member

@vszakats do you have any suggestion for the failing amiga CI job? Does it not have a working inet ntop/pton? I see in your commit that recently created the job that: inet_ntop, inet_pton: fix using it for AmigaOS. cmake detects them, and they did not compile with AmigaOS. Should this example be excluded from that platform?

These functions exist on AmigaOS3, but they possibly require proto/bsdsocket.h (can't double-check ATM). Looking at lib/curl_setup.h, it would have to be detected, alongside some "magic" conditions for including it. Then they have slightly different signatures, needing casts.

Sounds overkill for a standalone example. I think excluding it is a reasonable solution.

@jay
Copy link
Member Author

jay commented Dec 19, 2024

I disabled it for Amiga by defining an alternate main in the example for __AMIGA__ that says amiga is not supported.

I had considered instead removing block_ip, when amiga host, from the check_PROGRAMS list after it's imported by CMakeLists.txt and Makefile.am. In cmake it would be easy list(REMOVE_ITEM check_PROGRAMS "block_ip"), however in Makefile.am the code would need to be POSIX compliant and there's no good way to do it without string comparison ($(host_os) = amigaos) and something like a GNU automake text function filter-out. Though technically there are some workarounds like use the shell to filter the variable and then re-import it, it would be messy. Also there's POSIX substitution but it only works with suffixes, eg $(check_PROGRAMS:block_ip=)

docs/examples/block_ip.c Outdated Show resolved Hide resolved
@vszakats
Copy link
Member

I disabled it for Amiga by defining an alternate main in the example for __AMIGA__ that says amiga is not supported.

I had considered instead removing block_ip, when amiga host, from the check_PROGRAMS list after it's imported by CMakeLists.txt and Makefile.am. In cmake it would be easy list(REMOVE_ITEM check_PROGRAMS "block_ip"), however in Makefile.am the code would need to be POSIX compliant and there's no good way to do it without string comparison ($(host_os) = amigaos) and something like a GNU automake text function filter-out. Though technically there are some workarounds like use the shell to filter the variable and then re-import it, it would be messy. Also there's POSIX substitution but it only works with suffixes, eg $(check_PROGRAMS:block_ip=)

Agreed, it sounds messy on the build-level.

I think it's perfectly fine to handle it in C. Somebody may compile
it as-is as a C source (outside cmake or autotools), and this is now
handled too.

- Show how CURLOPT_OPENSOCKETFUNCTION can be used to block IP addresses.

This is a new example that demonstrates IP blocking.

Ref: curl#15710 (reply in thread)

Closes curl#15748
@jay jay closed this in a9d881c Dec 22, 2024
@jay jay deleted the block_ip branch December 22, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants