Skip to content

Commit

Permalink
Merge pull request #410 from nzmsv/master
Browse files Browse the repository at this point in the history
Check for NULL ifa_addr in getlocalip()
  • Loading branch information
ViralBShah committed Feb 20, 2012
2 parents e18cb47 + d5e96a3 commit 383f6c1
Showing 1 changed file with 2 additions and 2 deletions.
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

0 comments on commit 383f6c1

Please sign in to comment.