Comments (8)
Switching from gethostbyname to getaddrinfo isn't so straight forward - it's not a 1:1 replacement. If anyone has some spare-cycles to code this piece, I'm open for some PR :-)
from libdnet.
Given how gethostbyname() is used here, the correct use of getaddrinfo() actually would be a 1:1 replacement for gethostbyname(). Yes it's more lines of code, but it'd be functionally equivalent.
However, I'd argue that just removing it is the right thing to do here. It's never been appropriate to invoke the resolver from addr_pton(); it overloads the function inappropriately. It should always return an error when the first argument is not a valid address string. And it should have done this before IPv6 was common. Today, where it's common to have AAAA and A records for a given host name, it's unquestionably the wrong thing to do. Code that expect to pass a hostname (canonical or not) as the first argument to addr_pton() and get a valid result is just incorrect in today's world.
I'd say make it obvious by removing that 'else if' entirely and updating the manpage. That's what my local patches for the FreeBSD port do. I haven't seen any negative consequences (I've had these patches for many years, maybe a decade), but I don't think I have any code that depends on libdnet that's not my own code, which has never called addr_pton() with a host name. The only things I see in the FreeBSD ports tree that depends on libdnet are the perl5 and python interfaces to libdnet, plus p5-Class-Gomor. I haven't checked the linux distributions but I assume the situation is similar.
Also note that the original code sets errno to EINVAL if host lookup fails, which is misleading at best if a host name is passed as the first argument. "xyqzfooygnfb" isn't an invalid host name, but there are no A or AAAA records for it in my search domains.
Basically... name resolution is orthogonal to address format conversion. Keep in mind that when someone wants name resolution, they should want RFC 8305 behavior in many/most cases (they're doing name lookup simply to get an address for connect(), for example). That's much more involved than just calling getaddrinfo() or the obsolete gethostbyname().
from libdnet.
Pull request created, if you want it.
from libdnet.
Packages on Ubuntu 20.04 that depend on libdumbnet1:
% apt-cache rdepends libdumbnet1
libdumbnet1
Reverse Depends:
libdumbnet-dev
snort
scanssh
libnet-libdnet-perl
arpon
labrea
farpd
daemonlogger
snort, scanssh and farpd don't pass host names to addr_pton().
arpon, labrea and daemonlogger don't call addr_pton() at all.
So I don't think my pull request will break debian-based distros in any consequential way; direct dnet-dependent packages are not calling addr_pton() with host names. At the moment I don't have time to chase down the whole dependency tree, but I think it's good to remove the host lookup stuff in addr_pton() and update the documentation.
If desired, there could be a new function that uses gettaddrinfo() and fills an array of struct addr, and possibly another function that just fills one struct addr with the first entry found matching a given family? Family could be 0 for "Don't care".
hname_tonarr(const char *hname, struct addr *addrs, size_t numAddrs, int family);
hname_ton(const char *hname, struct addr *addr, int family);
from libdnet.
Thx a lot @dwmcrobb for your work on that. I'll have a look at the PR!
from libdnet.
I reverted the README.md changes on my addr_pton-no-gethostbyname branch and master branch. So sorry about that goof up on my part!
Let me know if I need to do anything else.
from libdnet.
No worries @dwmcrobb ! I guessed it happened by accident!
from libdnet.
Squash-Merged and close this issue.
Thanks again for your efforts @dwmcrobb !
from libdnet.
Related Issues (20)
- 1.14: libdnet is not LTO ready HOT 17
- ImportError at start HOT 2
- Allow building on Debian GNU/kFreeBSD HOT 2
- manpages: Distinguish between groff hyphens and minus signs HOT 1
- mapages: fix some typos HOT 1
- Conflicting parameter types of strlcpy, strlcat to cause undefined behaviour HOT 3
- Investigate modifications applied by Nmap HOT 5
- Detect "check" lib multi-arch aware via pkg-config HOT 1
- arp-ioctl.c:221: 3 * off by one error HOT 1
- Cross compiling fails with 1.16.1 HOT 6
- Fix groff "empty input lines" warning HOT 1
- dnet 1.16.1 with python 3.11 error: incomplete definition of type 'struct _frame' HOT 7
- Update dnet on PyPi to make this fork installable via pip HOT 2
- libdnet fails to build with Python 3.12: ModuleNotFoundError: No module named 'distutils' HOT 4
- Error while configuring it. Please advise HOT 4
- Cmake support HOT 2
- Python bindings fail to build on macOS HOT 5
- configure missing auxiliary file: compile? HOT 3
- HOWTO to compile HOT 2
- Reduce compiler warnings HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libdnet.