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

Remove addrlen switch duplication #864

Open
skliper opened this issue Mar 10, 2021 · 0 comments · May be fixed by #1388
Open

Remove addrlen switch duplication #864

skliper opened this issue Mar 10, 2021 · 0 comments · May be fixed by #1388

Comments

@skliper
Copy link
Contributor

skliper commented Mar 10, 2021

Is your feature request related to a problem? Please describe.
Switch to get addrlen repeated multiple times:

switch (sa->sa_family)
{
case AF_INET:
addrlen = sizeof(struct sockaddr_in);
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
addrlen = sizeof(struct sockaddr_in6);
break;
#endif
default:
addrlen = 0;
break;
}

sa = (const struct sockaddr *)&Addr->AddrData;
switch (sa->sa_family)
{
case AF_INET:
slen = sizeof(struct sockaddr_in);
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
slen = sizeof(struct sockaddr_in6);
break;
#endif
default:
slen = 0;
break;
}

sa = (const struct sockaddr *)&RemoteAddr->AddrData;
switch (sa->sa_family)
{
case AF_INET:
addrlen = sizeof(struct sockaddr_in);
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case AF_INET6:
addrlen = sizeof(struct sockaddr_in6);
break;
#endif
default:
addrlen = 0;
break;
}

switch (Domain)
{
case OS_SocketDomain_INET:
sa_family = AF_INET;
addrlen = sizeof(struct sockaddr_in);
break;
#ifdef OS_NETWORK_SUPPORTS_IPV6
case OS_SocketDomain_INET6:
sa_family = AF_INET6;
addrlen = sizeof(struct sockaddr_in6);
break;
#endif
default:
sa_family = 0;
addrlen = 0;
break;
}

Describe the solution you'd like
Calculate once and store or implement once and inline

Describe alternatives you've considered
Leave as-is (future work)

Additional context
None

Requester Info
Jacob Hageman - NASA/GSFC, OSAL code review

jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
thnkslprpt added a commit to thnkslprpt/osal that referenced this issue May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant