Skip to content

Commit

Permalink
linux-user: add ioctl(SIOCGIWNAME, ...) support.
Browse files Browse the repository at this point in the history
Allow to run properly following program from linux-user:

/* cc -o wifi wifi.c */

 #include <stdio.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <linux/wireless.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>

int main(int argc, char **argv)
{
    int ret;
    struct ifreq req;
    struct sockaddr_in *addr;
    int s;

    if (argc != 2) {
        fprintf(stderr, "Need an interface name (like wlan0)\n");
	return 1;
    }

    s = socket( AF_INET, SOCK_DGRAM, 0 );
    if (s < 0) {
        perror("Cannot open socket");
        return 1;
    }
    strncpy(req.ifr_name, argv[1], sizeof(req.ifr_name));
    ret = ioctl( s, SIOCGIWNAME, &req );
    if (ret < 0) {
	fprintf(stderr, "No wireless extension\n");
        return 1;
    }

    printf("%s\n", req.ifr_name);
    printf("%s\n", req.ifr_newname);
    return 0;
}

$ ./wifi eth0
No wireless extension

$ ./wifi wlan0
wlan0
IEEE 802.11bg

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
  • Loading branch information
vivier authored and suihkulokki committed Apr 26, 2011
1 parent 059c2f2 commit 86fcd94
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions linux-user/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
IOCTL(SIOCDRARP, IOC_W, MK_PTR(MK_STRUCT(STRUCT_arpreq)))
IOCTL(SIOCSRARP, IOC_W, MK_PTR(MK_STRUCT(STRUCT_arpreq)))
IOCTL(SIOCGRARP, IOC_R, MK_PTR(MK_STRUCT(STRUCT_arpreq)))
IOCTL(SIOCGIWNAME, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_char_ifreq)))

IOCTL(CDROMPAUSE, 0, TYPE_NULL)
IOCTL(CDROMSTART, 0, TYPE_NULL)
Expand Down
2 changes: 1 addition & 1 deletion linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int __clone2(int (*fn)(void *), void *child_stack_base,
//#include <sys/user.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <net/if.h>
#include <linux/wireless.h>
#include <qemu-common.h>
#ifdef TARGET_GPROF
#include <sys/gmon.h>
Expand Down
3 changes: 3 additions & 0 deletions linux-user/syscall_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ struct target_pollfd {
#define TARGET_SIOCADDDLCI 0x8980 /* Create new DLCI device */
#define TARGET_SIOCDELDLCI 0x8981 /* Delete DLCI device */

/* From <linux/wireless.h> */

#define TARGET_SIOCGIWNAME 0x8B01 /* get name == wireless protocol */

/* From <linux/fs.h> */

Expand Down

0 comments on commit 86fcd94

Please sign in to comment.