コード例 #1
0
ファイル: wire_client.c プロジェクト: noka57/packetdrill
/* Connect to the wire server, pass it our command line argument
 * options, the script we're going to execute, and our MAC address.
 */
int wire_client_init(struct wire_client *wire_client,
                     const struct config *config,
                     const struct script *script,
                     const struct state *state)
{
	DEBUGP("wire_client_init\n");
	assert(config->is_wire_client);

	get_hw_address(config->wire_client_device,
	               &wire_client->client_ether_addr);

	wire_client->wire_conn = wire_conn_new();
	wire_conn_connect(wire_client->wire_conn,
	                  &config->wire_server_ip,
	                  config->wire_server_port);

	wire_client_send_args(wire_client, config);

	wire_client_send_script_path(wire_client, config);

	wire_client_send_script(wire_client, script);

	wire_client_send_hw_address(wire_client, config);

	wire_client_receive_server_ready(wire_client);

	return STATUS_OK;
}
コード例 #2
0
ファイル: wire_server.c プロジェクト: nplab/packetdrill
static struct wire_server *wire_server_new(struct wire_conn *accepted_conn,
					   const char *wire_server_device,
					   u16 wire_server_port)
{
	struct wire_server *wire_server = calloc(1, sizeof(struct wire_server));
	wire_server->wire_conn = accepted_conn;
	wire_server->wire_server_device = strdup(wire_server_device);
	get_hw_address(wire_server_device, &wire_server->server_ether_addr);
	wire_server->port = wire_server_port;
	return wire_server;
}
コード例 #3
0
ファイル: netapi32.c プロジェクト: NVIDIA/winex_lgpl
static UCHAR NETBIOS_Enum(PNCB ncb)
{
#ifdef HAVE_NET_IF_H
    int             sd;
    struct ifconf   ifc;
    int             i;
    int             lastlen, numAddresses = 2;
    int             ioctlRet = 0;
    caddr_t         ifPtr;
#endif
    LANA_ENUM *lanas = NULL;

    if (ncb)
    {
        lanas = (PLANA_ENUM) ncb->ncb_buffer;
        lanas->length = 0;
    }

    TRACE("NCBENUM\n");

#ifdef HAVE_NET_IF_H
    /* BSD 4.4 defines the size of an ifreq to be
     * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
     * However, under earlier systems, sa_len isn't present, so
     *  the size is just sizeof(struct ifreq)
     */

    sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
    if (sd < 0)
        return NRC_OPENERROR;

    ifc.ifc_len = 0;
    ifc.ifc_buf = NULL;

    do {
        lastlen = ifc.ifc_len;
        HeapFree (GetProcessHeap (), 0, ifc.ifc_buf);
        numAddresses *= 2;

        ifc.ifc_len = sizeof (struct ifreq) * numAddresses;
        ifc.ifc_buf = HeapAlloc (GetProcessHeap (), 0, ifc.ifc_len);
        if (!ifc.ifc_buf)
        {
            close (sd);
            return NRC_OPENERROR;
        }

        ioctlRet = ioctl (sd, SIOCGIFCONF, (char *)&ifc);
    } while ((ioctlRet == 0) && (ifc.ifc_len != lastlen));

    if (ioctlRet)
    {
        HeapFree (GetProcessHeap (), 0, ifc.ifc_buf);
        close (sd);
        return NRC_OPENERROR;
    }

    /* loop through the interfaces, looking for a valid one */
    /* n = ifc.ifc_len; */
    ifPtr = ifc.ifc_buf;
    i = 0;
    while (ifPtr && (ifPtr < (ifc.ifc_buf + ifc.ifc_len)))
    {
        unsigned char *a = NETBIOS_Adapter[i].address;
        struct ifreq   ifr, *ifrp;

        ifrp = (struct ifreq *)ifPtr;

        ifPtr += ifreq_len ((struct ifreq *)ifPtr);
        i++;

        if (ifrp->ifr_addr.sa_family != AF_INET)
            continue;

        strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);

        /* try to get the address for this interface */
        if(get_hw_address(sd, &ifr, a)==0)
        {
            /* make sure it's not blank */
            /* if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
            continue; */

            TRACE("Found valid adapter %d at %02x:%02x:%02x:%02x:%02x:%02x\n", i,
                  a[0],a[1],a[2],a[3],a[4],a[5]);

            if (a[0] || a[1] || a[2] || a[3] || a[4] || a[5])
                NETBIOS_Adapter[i - 1].valid = TRUE;

            if (lanas)
            {
                lanas->lana[lanas->length] = i - 1;
                lanas->length++;
            }
        }
    }
    close(sd);
    HeapFree (GetProcessHeap (), 0, ifc.ifc_buf);

#endif /* HAVE_NET_IF_H */
    EnumDone = TRUE;
    return NRC_GOODRET;
}