DragonFly BSD
DragonFly bugs List (threaded) for 2012-08
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

[DragonFlyBSD - Bug #1897] (Feedback) SIOCGIFADDR doesn't work


From: Alex Hornung via Redmine <bugtracker-admin@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Aug 2012 07:48:26 -0700

Issue #1897 has been updated by Alex Hornung.

Status changed from New to Feedback
Assignee deleted (0)


----------------------------------------
Bug #1897: SIOCGIFADDR doesn't work
http://bugs.dragonflybsd.org/issues/1897

Author: Steve O'Hara-Smith
Status: Feedback
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.

	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



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]