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

Check for NULL ifa_addr in getlocalip() #410

Merged
merged 1 commit into from
Feb 20, 2012
Merged
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
4 changes: 2 additions & 2 deletions src/support/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void getlocalip(char *buf, size_t len)
getifaddrs(&ifAddrStruct);

for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4
if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_INET) { // check it is IP4
// is a valid IP4 Address
tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
inet_ntop(AF_INET, tmpAddrPtr, buf, len);
Expand All @@ -188,7 +188,7 @@ void getlocalip(char *buf, size_t len)
//printf("%s IP Address %s\n", ifa->ifa_name, addressBuffer);
}
/*
else if (ifa->ifa_addr->sa_family==AF_INET6) { // check it is IP6
else if (ifa->ifa_addr && ifa->ifa_addr->sa_family==AF_INET6) { // check it is IP6
// is a valid IP6 Address
tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
char addressBuffer[INET6_ADDRSTRLEN];
Expand Down