[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gnulib ioctl() on OS X 10.6.6 x86
From: |
Markus Gothe |
Subject: |
Re: gnulib ioctl() on OS X 10.6.6 x86 |
Date: |
Fri, 28 Jan 2011 12:58:27 +0100 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
It's an easy thing to fix methinks. The issue is with the definition (changing
it in ioctl.c and sys_ioctl_h.in reverted back to normal behavior, which
however disallowed an unprivileged user to change the MAC-address on an
interface which per se is an OS X-bug).
On FreeBSD and OS X the correct definition of ioctl is 'ioctl(int fd, unsigned
long request, ...)'
using 'int request' in this case mess with 64-bits pointers.
Code example of the bug described using gnulib's ioctl module:
#include "config.h"
#include <stdio.h>
#include <stdlib.h> /* For exit() */
#include <string.h> /* For memset() */
#include <stddef.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <net/if_arp.h>
#include <ifaddrs.h>
#ifdef SIOCSIFLLADDR
#include <net/if_dl.h>
#endif
/* Use GNU xcalloc() */
#include "xalloc.h"
/* Our definitions */
#include "tap.h"
int set_hwaddr_tap(tap *dev, char hwaddr[ETHER_ADDR_LEN]){
int ret = -1;
dev->ifr.ifr_addr.sa_family = AF_LINK;
memcpy(dev->ifr.ifr_addr.sa_data, hwaddr, ETHER_ADDR_LEN);
GET_SA_LEN(dev->ifr.ifr_addr) = ETHER_ADDR_LEN;
#ifdef SIOCSIFLLADDR
if((ret = ioctl(dev->intf_fd, SIOCSIFLLADDR, &dev->ifr)) == -1){
#elif defined(SIOCSIFHWADDR)
dev->ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
(void)memcpy(&dev->ifr.ifr_hwaddr.sa_data, hwaddr, ETHER_ADDR_LEN);
GET_SA_LEN(dev->ifr.ifr_hwaddr) = ETHER_ADDR_LEN;
if((ret = ioctl(dev->intf_fd, SIOCSIFHWADDR, &dev->ifr)) == -1){
#else
#error "Check for SIOCSIFLLADDR or SIOCSIFHWADDR"
#endif
perror("ioctl");
}
return ret;
}
//Markus - The panama-hat hacker
On 28 Jan, 2011, at 12:46 , Bruno Haible wrote:
> Forward from Markus Gothe <address@hidden>:
>
> ---------- Forwarded message ----------
>
> Subject: defunct gnulib ioctl() on OS X 10.6.6 x86
> From: Markus Gothe <address@hidden>
>
> I wanted to report that the arguments to ioctl gets all messed upp, sending a
> 64-bits int instead of 32 and bugon...
>
> -----------------------------------------
>
> Could you please give more details?
> - What is the program source code that you ran?
> - What behaviour did you observe?
> - What makes you think that it's related to gnulib?
>
> Bruno
>
> PS: Don't send me encrypted mails normally.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.16 (Darwin)
iD4DBQFNQq9q6I0XmJx2NrwRAigNAJ95NszKvWMhM9/tCjYLNe4iDDwodgCXZyMR
7ad8rTYFgPaA79FY341G/w==
=q+1v
-----END PGP SIGNATURE-----