Skip to content

Removed ntoa assumption on endianness #42

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions source/inet_ntoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,24 @@ inet_ntoa(struct socket_addr ina)
{
static char buf[4*sizeof "123"];
in_addr_t ia = socket_addr_get_ipv4_addr(&ina);
unsigned char *ucp = (unsigned char *)&ia;

sprintf(buf, "%d.%d.%d.%d",
ucp[0] & 0xff,
ucp[1] & 0xff,
ucp[2] & 0xff,
ucp[3] & 0xff);
sprintf(buf, "%u.%u.%u.%u",
(unsigned)((ia >> 24) & 0xff),
(unsigned)((ia >> 16) & 0xff),
(unsigned)((ia >> 8) & 0xff),
(unsigned)((ia >> 0) & 0xff));
return buf;
}

char *
inet_ntoa_r(struct socket_addr ina, char *buf)
{
in_addr_t ia = socket_addr_get_ipv4_addr(&ina);
unsigned char *ucp = (unsigned char *)&ia;

sprintf(buf, "%d.%d.%d.%d",
ucp[0] & 0xff,
ucp[1] & 0xff,
ucp[2] & 0xff,
ucp[3] & 0xff);
sprintf(buf, "%u.%u.%u.%u",
(unsigned)((ia >> 24) & 0xff),
(unsigned)((ia >> 16) & 0xff),
(unsigned)((ia >> 8) & 0xff),
(unsigned)((ia >> 0) & 0xff));
return buf;
}