C/airpcap-nl.c
/* adapted (lifted) from lorcon2 nl80211_create_vap */
adapted (lifted) from lorcon2 nl80211_create_vap
adapted ( lifted ) from lorcon2 nl80211_create_vap
static
int nl80211_create_monitor(PAirpcapHandle handle, PCHAR Ebuf)
{
    struct nl_msg *msg;
    int err;
    handle->monitor_ifindex = if_nametoindex(handle->monitor_ifname);
    if (0 != handle->monitor_ifindex) {
        return 0;
    }
    msg = nlmsg_alloc();
    if (NULL == msg) {
        setebuf(Ebuf, "Failed to allocate netlink message.");
        return -1;
    }
    genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ,
                genl_family_get_id(handle->nl80211), 0, 0, 
                NL80211_CMD_NEW_INTERFACE, 0);
    NLA_PUT_U32(msg,    NL80211_ATTR_IFINDEX, handle->ifindex);
    NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, handle->monitor_ifname);
    NLA_PUT_U32(msg,    NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MONITOR);
    err = nl_send_and_recv(handle->nl_socket, msg,
                           cmd_new_interface_handler,
                           NULL);
    if (err < 0) {
    nla_put_failure:
        setebuf(Ebuf, "Failed to create monitor interface %s from %s: %s",
                handle->monitor_ifname,
                handle->master_ifname,
                strerror(-err));
        return -1;
    }
    handle->monitor_ifindex = if_nametoindex(handle->monitor_ifname);
    if (0 == handle->monitor_ifindex) {
        setebuf(Ebuf,
                "nl80211_create_monitor() thought we made a "
                "monitor interface, but it wasn't there when we looked");
        return -1;
    }
    return 0;
}
static int nl80211_create_monitor ( PAirpcapHandle handle , PCHAR Ebuf ) { struct nl_msg * msg ; int err ; handle -> monitor_ifindex = if_nametoindex ( handle -> monitor_ifname ) ; if ( 0 != handle -> monitor_ifindex ) { return 0 ; } msg = nlmsg_alloc ( ) ; if ( NULL == msg ) { setebuf ( Ebuf , " " ) ; return -1 ; } genlmsg_put ( msg , NL_AUTO_PID , NL_AUTO_SEQ , genl_family_get_id ( handle -> nl80211 ) , 0 , 0 , NL80211_CMD_NEW_INTERFACE , 0 ) ; NLA_PUT_U32 ( msg , NL80211_ATTR_IFINDEX , handle -> ifindex ) ; NLA_PUT_STRING ( msg , NL80211_ATTR_IFNAME , handle -> monitor_ifname ) ; NLA_PUT_U32 ( msg , NL80211_ATTR_IFTYPE , NL80211_IFTYPE_MONITOR ) ; err = nl_send_and_recv ( handle -> nl_socket , msg , cmd_new_interface_handler , NULL ) ; if ( err < 0 ) { nla_put_failure : setebuf ( Ebuf , " " , handle -> monitor_ifname , handle -> master_ifname , strerror ( - err ) ) ; return -1 ; } handle -> monitor_ifindex = if_nametoindex ( handle -> monitor_ifname ) ; if ( 0 == handle -> monitor_ifindex ) { setebuf ( Ebuf , " " " " ) ; return -1 ; } return 0 ; }
adapted (lifted) from lorcon2 nl80211_create_vap
adapted ( lifted ) from lorcon2 nl80211_create_vap
/* Check if this interface already exists. */ /* TODO: Check to make sure it is the correct wiphy and
         * already in IFTYPE_MONITOR */ /* PROTIP: If you get -ENFILE (-23 / Too many open files in system),
     * it's (likely) because the interface already exists.
     * Why doesn't it return -EEXIST?!
     */ /* Save this ifindex */