Esempio n. 1
0
int
main(void)
{
	int i;
	const char *vnd, *libc;
	for (i = 0; i < 42; i++) {
		vnd = vnd_strsyserror(i);
		libc = strerror(i);
		if ((vnd != NULL && libc == NULL) ||
		    (vnd == NULL && libc != NULL)) {
			(void) fprintf(stderr, "errno %d, vnd: %p, libc: %p",
			    i, (void *)vnd, (void *)libc);
			return (1);
		}
		if (vnd != NULL && strcmp(vnd, libc) != 0) {
			(void) fprintf(stderr,
			    "errno %d: libc and vnd disagree.\n", i);
			(void) fprintf(stderr, "vnd: %s\n", vnd);
			(void) fprintf(stderr, "libc: %s\n", libc);
			return (1);
		}
	}

	return (0);
}
Esempio n. 2
0
int
net_init_vnic(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan)
{
	int fd, len, vnderr, syserr;
	const char *ifname, *mac;
	uchar_t *macaddr;
	VLANClientState *ncp;
	VNICState *vsp;
	vnd_prop_buf_t vib;

	if ((ifname = qemu_opt_get(opts, "ifname")) == NULL) {
		error_report("missing ifname required for vnic\n");
		return (-1);
	}

	mac = qemu_opt_get(opts, "macaddr");

	if (mac != NULL) {
		macaddr = _link_aton(mac, &len);
		if (macaddr == NULL || len != ETHERADDRL) {
			error_report("invalid macaddr for vnic: %s\n", mac);
			return (-1);
		}
	}

	ncp = qemu_new_net_client(&net_vnic_info, vlan, NULL, "vnic", name);
	vsp = DO_UPCAST(VNICState, vns_nc, ncp);


	vsp->vns_hdl = vnd_open(NULL, ifname, &vnderr, &syserr);
	if (vsp->vns_hdl == NULL) {
		const char *err = vnderr != VND_E_SYS ?
		    vnd_strerror(vnderr) : vnd_strsyserror(syserr);
		error_report("vnic: failed to open interface %s - %s\n",
		    ifname, err);
		return (-1);
	}

	vib.vpb_size = 1024 * 1024 * 4; 	/* 4 MB */
	if (vnd_prop_set(vsp->vns_hdl, VND_PROP_RXBUF, &vib,
	    sizeof (vib)) != 0) {
		const char *err = vnderr != VND_E_SYS ?
		    vnd_strerror(vnderr) : vnd_strsyserror(syserr);
		error_report("failed to change rx buf size: %s\n", err);
		return (-1);
	}

	vib.vpb_size = 1024 * 1024 * 4; 	/* 4 MB */
	if (vnd_prop_set(vsp->vns_hdl, VND_PROP_TXBUF, &vib,
	    sizeof (vib)) != 0) {
		const char *err = vnderr != VND_E_SYS ?
		    vnd_strerror(vnderr) : vnd_strsyserror(syserr);
		error_report("failed to change tx buf size: %s\n", err);
		return (-1);
	}


	fd = vnd_pollfd(vsp->vns_hdl);
	if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
		error_report("vnic: failed to set fd on interface %s to "
		    "non-blocking: %s\n", ifname, strerror(errno));
		return (-1);
	}

	vsp->vns_fd = fd;

	snprintf(vsp->vns_nc.info_str, sizeof (vsp->vns_nc.info_str), "ifname=%s",
	    qemu_opt_get(opts, "ifname"));

	if (vnic_dhcp_init(&vsp->vns_ds, opts) == 0)
		return (-1);

	if (vnic_frameio_init(vsp) != 0) {
		error_report("vnic: failed initialize frameio: %s\n",
		    strerror(errno));
		return (-1);
	}

	/* We have to manually intialize the polling for read */
	vnic_read_poll(vsp, 1);

	return (0);
}