HedongGao opened a new pull request, #17700:
URL: https://github.com/apache/nuttx/pull/17700
## Summary
There is a compile warning information:
`ctc W597: ["/home/mi/code/dev-system/nuttx/libs/libc/net/lib_getifaddrs.c"
215/21] alignment of automatic object limited to 4`
In order to fix compilation issue, the struct ifreq structure is modified.
## Impact
There is no impact for user.
## Testing
`
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
int main(void)
{
int sockfd;
struct ifreq ifr;
unsigned int idx;
char name[IFNAMSIZ] = "eth0";
char namebuf[IFNAMSIZ];
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
perror("socket");
return 1;
}
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, name, IFNAMSIZ-1);
if (ioctl(sockfd, SIOCGIFINDEX, &ifr) < 0) {
perror("ioctl SIOCGIFINDEX");
close(sockfd);
return 1;
}
idx = ifr.ifr_ifindex;
printf("Interface %s has index %u\n", name, idx);
if (if_indextoname(idx, namebuf) == NULL) {
perror("if_indextoname");
close(sockfd);
return 1;
}
printf("Index %u corresponds to interface %s\n", idx, namebuf);
if (strncmp(name, namebuf, IFNAMSIZ) == 0) {
printf("Test PASSED: ifr_ifindex works as expected.\n");
} else {
printf("Test FAILED: name mismatch.\n");
}
close(sockfd);
return 0;
}
`
Result of test:
`
nsh> hello
Interface eth0 has index 1
Index 1 corresponds to interface eth0
Test PASSED: ifr_ifindex works as expected.
`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]