1085
1085
errno = old_errno;
1089
* This function determines if a directory entry in /sys/class/net
1090
* corresponds to an acceptable network device.
1091
* (This function is passed to scandir(3) as a filter function.)
1093
int good_interface(const struct dirent *if_entry){
1088
bool get_flags(const char *ifname, struct ifreq *ifr){
1096
if(if_entry->d_name[0] == '.'){
1099
1091
int s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
1101
1093
perror_plus("socket");
1105
strcpy(ifr.ifr_name, if_entry->d_name);
1106
ret = ioctl(s, SIOCGIFFLAGS, &ifr);
1096
strcpy(ifr->ifr_name, ifname);
1097
ret = ioctl(s, SIOCGIFFLAGS, ifr);
1109
1100
perror_plus("ioctl SIOCGIFFLAGS");
1107
bool good_flags(const char *ifname, const struct ifreq *ifr){
1113
1109
/* Reject the loopback device */
1114
if(ifr.ifr_flags & IFF_LOOPBACK){
1110
if(ifr->ifr_flags & IFF_LOOPBACK){
1116
1112
fprintf(stderr, "Rejecting loopback interface \"%s\"\n",
1121
1117
/* Accept point-to-point devices only if connect_to is specified */
1122
if(connect_to != NULL and (ifr.ifr_flags & IFF_POINTOPOINT)){
1118
if(connect_to != NULL and (ifr->ifr_flags & IFF_POINTOPOINT)){
1124
1120
fprintf(stderr, "Accepting point-to-point interface \"%s\"\n",
1129
1125
/* Otherwise, reject non-broadcast-capable devices */
1130
if(not (ifr.ifr_flags & IFF_BROADCAST)){
1126
if(not (ifr->ifr_flags & IFF_BROADCAST)){
1132
1128
fprintf(stderr, "Rejecting non-broadcast interface \"%s\"\n",
1137
1133
/* Reject non-ARP interfaces (including dummy interfaces) */
1138
if(ifr.ifr_flags & IFF_NOARP){
1134
if(ifr->ifr_flags & IFF_NOARP){
1140
fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n",
1136
fprintf(stderr, "Rejecting non-ARP interface \"%s\"\n", ifname);
1145
1141
/* Accept this device */
1147
fprintf(stderr, "Interface \"%s\" is acceptable\n",
1143
fprintf(stderr, "Interface \"%s\" is good\n", ifname);
1149
* This function determines if a directory entry in /sys/class/net
1150
* corresponds to an acceptable network device.
1151
* (This function is passed to scandir(3) as a filter function.)
1153
int good_interface(const struct dirent *if_entry){
1155
if(if_entry->d_name[0] == '.'){
1160
if(not get_flags(if_entry->d_name, &ifr)){
1164
if(not good_flags(if_entry->d_name, &ifr)){