Bug #1897
closedSIOCGIFADDR doesn't work
Description
Hi,
I found this while trying to get ushare to work - the SIOCGIFADDR
ioctl doesn't set the IP address (at least for re devices), what you get is
whatever was in the struct ifreq before the call.
Running v2.9.0.105.gba1cb-DEVELOPMENT - but it's been going on for
a while I just haven't got to the bottom of the problem until now.
My test code (below) always prints 0.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if_dl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
int main (int argc, char **argv)
{
int sock;
int32_t ip;
struct ifreq ifr;
memset (&ifr, 0, sizeof ifr);
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror ("socket");
exit(1);
}
strcpy(ifr.ifr_name, "re0");
ifr.ifr_addr.sa_family = AF_INET;
if (ioctl (sock, SIOCGIFADDR, &ifr) < 0) {
perror("ioctl");
exit(1);
}
ip = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
printf("%x\n", ip);
}
Updated by raitech over 12 years ago
- Description updated (diff)
I had the same issue here, detected while trying do run the NO-IP daemon. It works fine under FreeBSD, so I thinked that it should work too under DragonFlyBSD.
I took this as a solution:
(based on the test posted by Steve)
(basically bypass the ioctl and use getifaddrs(3) - is, therefore, SIOGIFADDR and the like deprecated?!)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <ifaddrs.h>
int main (int argc, char **argv) {
struct ifaddrs *ifa = NULL;
char inaddr[INET_ADDRSTRLEN];
if(getifaddrs(&ifa) != 0) {
printf("Error while trying to get ifaddrs...\n");
exit(1);
}
while(ifa) {
inet_ntop(AF_INET, (struct in_addr *)&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, inaddr, INET_ADDRSTRLEN);
printf("Dev: %s IP %s --> %d\n", ifa->ifa_name, inaddr, ifa->ifa_addr->sa_family);
ifa = ifa->ifa_next;
}
freeifaddrs(ifa);
return(0);
}
Now, working on the NO-IP patch.
Updated by sepherosa over 12 years ago
On Sat, May 5, 2012 at 3:15 PM, Raimundo Santos via Redmine
<bugtracker-admin@leaf.dragonflybsd.org> wrote:
Issue #1897 has been updated by Raimundo Santos.
Description updated
I had the same issue here, detected while trying do run the NO-IP daemon. It works fine under FreeBSD, so I thinked that it should work too under DragonFlyBSD.
I took this as a solution:
(based on the test posted by Steve)
(basically bypass the ioctl and use getifaddrs(3) - is, therefore, SIOGIFADDR and the like deprecated?!)#include <stdio.h>
#include <stdlib.h>
#include <string.h>#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <ifaddrs.h>int main (int argc, char **argv) {
struct ifaddrs *ifa = NULL;
char inaddr[INET_ADDRSTRLEN];if(getifaddrs(&ifa) != 0) {
printf("Error while trying to get ifaddrs...\n");
exit(1);
}while(ifa) {
inet_ntop(AF_INET, (struct in_addr *)&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, inaddr, INET_ADDRSTRLEN);
printf("Dev: %s IP %s --> %d\n", ifa->ifa_name, inaddr, ifa->ifa_addr->sa_family);
ifa = ifa->ifa_next;
}freeifaddrs(ifa);
return(0);
}Now, working on the NO-IP patch.
----------------------------------------
Bug #1897: SIOCGIFADDR doesn't work
http://bugs.dragonflybsd.org/issues/1897Author: Steve O'Hara-Smith
Status: New
Priority: Normal
Assignee:
Category:
Target version:Hi,
I found this while trying to get ushare to work - the SIOCGIFADDR
ioctl doesn't set the IP address (at least for re devices), what you get is
whatever was in the struct ifreq before the call.
It is due to wrongly numbered SIOCGIFDATA; it should have been fixed on master:
401c752a1960c193055c3ab3e6830eb2f259d1f4
Best Regards,
sephe
Running v2.9.0.105.gba1cb-DEVELOPMENT - but it's been going on for
a while I just haven't got to the bottom of the problem until now.My test code (below) always prints 0.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if_dl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <netinet/in.h>int main (int argc, char **argv) {
int sock;
int32_t ip;
struct ifreq ifr;memset (&ifr, 0, sizeof ifr);
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
perror ("socket");
exit(1);
}strcpy(ifr.ifr_name, "re0");
ifr.ifr_addr.sa_family = AF_INET;
if (ioctl (sock, SIOCGIFADDR, &ifr) < 0) {
perror("ioctl");
exit(1);
}
ip = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
printf("%x\n", ip);
}--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://bugs.dragonflybsd.org/my/account
--
Tomorrow Will Never Die
Updated by alexh about 12 years ago
- Status changed from New to Feedback
- Assignee deleted (
0)
Updated by y0n3t4n1 about 12 years ago
Hi, could someone please merge this fix to DragonFly_RELEASE_3_0?
Oh BTW, `sort -nk4,4 /sys/sys/sockio.h' reveals a few more duplicates; are these OK?
#define SIOCGETVIFCNT _IOWR('r', 15, struct sioc_vif_req)/* get vif pkt cnt /
#define SIOCGETSGCNT _IOWR('r', 16, struct sioc_sg_req) / get s,g pkt cnt /
#define OSIOCGIFDSTADDR _IOWR('i', 15, struct ifreq) / get p-p address /
#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) / set ifnet flags */
Updated by tuxillo over 10 years ago
- Description updated (diff)
- Category set to Networking
- Assignee set to tuxillo
- Priority changed from Normal to Low
- Target version set to 3.8
Hi,
Commit 401c752a1960c193055c3ab3e6830eb2f259d1f4 is already on latest stable (since it went to mater a year and a half ago or so).
Let me check the other ones.
Cheers,
Antonio Huete
Updated by liweitianux over 5 years ago
- Status changed from Feedback to Resolved