-
Notifications
You must be signed in to change notification settings - Fork 847
Add method to write an IpAddr value to a sockaddr. #7821
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,6 +463,27 @@ IpAddr::toString(char *dest, size_t len) const | |
| return dest; | ||
| } | ||
|
|
||
| sockaddr * | ||
| IpAddr::toSockAddr(sockaddr *dest) const | ||
| { | ||
| if (AF_INET == _family) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use a switch(_family)?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only two values and those values are not compact, not sure a |
||
| dest->sa_family = AF_INET; | ||
| ats_ip4_addr_cast(dest) = _addr._ip4; | ||
| #if HAVE_STRUCT_SOCKADDR_SA_LEN | ||
| dest->sa_len = sizeof(sockaddr_in); | ||
| #endif | ||
| } else if (AF_INET6 == _family) { | ||
| dest->sa_family = AF_INET6; | ||
| ats_ip6_addr_cast(dest) = _addr._ip6; | ||
| #if HAVE_STRUCT_SOCKADDR_SA_LEN | ||
| dest->sa_len = sizeof(sockaddr_in6); | ||
| #endif | ||
| } else { | ||
| dest->sa_family = AF_UNSPEC; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe return nullptr, as a fail indicator?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on whether you want to crash on use of an invalid instance. The common use case will be something like Currently this will fail on an invalid |
||
| } | ||
| return dest; | ||
| } | ||
|
|
||
| bool | ||
| IpAddr::isMulticast() const | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.