Пример #1
0
static void
config_router(void)
{
	int rv;

	/* configure networking using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem1"));
	NOFAIL_RV(rump_pub_netconfig_ipv4_ifaddr("shmif0",
	    "1.0.0.2", "255.255.255.0"));

	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif1"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif1", "busmem2"));
	NOFAIL_RV(rump_pub_netconfig_ipv4_ifaddr("shmif1",
	    "1.0.1.2", "255.255.255.0"));
}
Пример #2
0
int
main()
{
	struct sockaddr_in client;
	struct sockaddr_in server;
	char msg[500];
	char buf[65535];
	socklen_t clen;
	ssize_t nn;
	ssize_t off;
	int size = 1024 * 1024;
	int s;


	rump_init();
	rump_pub_lwproc_rfork(0);
	if (rump_pub_netconfig_ifcreate(IFNAME) != 0)
		errx(1, "failed to create " IFNAME);

	if (rump_pub_netconfig_ipv4_ifaddr(IFNAME,
	    IF_ADDR, "255.255.255.0") != 0)
		errx(1, "failed to create " IFNAME);

	//rump_pub_netconfig_dhcp_ipv4_oneshot(IFNAME);


	s = rump_sys_socket(PF_INET, SOCK_DGRAM, 0);
	if (s == -1)
		err(1,"socket");

	memset(&server, 0, sizeof(server));
	server.sin_family = AF_INET;
	server.sin_port = htons(ECHOSERVER_RX_PORT);  
	server.sin_addr.s_addr = inet_addr(IF_ADDR);

	rump_sys_setsockopt(s, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));

	if (rump_sys_bind(s, (struct sockaddr *)&server, sizeof(server)) == -1)
		err(1, "binded");
	printf("socket binded\r\n");

	printf("Waiting connection on port = %d\r\n",ECHOSERVER_RX_PORT);

	memset(&client, 0, sizeof(client));

	while(1)
	{
		memset(msg,0,sizeof(msg));
		clen = sizeof(client);

		nn = rump_sys_recvfrom(s,msg,sizeof(msg),0,(struct sockaddr *)&client,&clen);


		if (nn<0) {
			perror("Error receiving data");
		} else {
			rump_sys_sendto(s,buf,nn,0,(struct sockaddr *)&client,clen);
		}
	}
}
Пример #3
0
static void
config_server(void)
{

	/* configure interface using the portable interfaces */
	NOFAIL_RV(rump_pub_netconfig_ifcreate("shmif0"));
	NOFAIL_RV(rump_pub_netconfig_ifsetlinkstr("shmif0", "busmem"));
	NOFAIL_RV(rump_pub_netconfig_ipv4_ifaddr("shmif0",
	    "1.0.0.1", "255.255.255.0"));
}
Пример #4
0
static void
rumprun_config_net(const char *if_index)
{
	char *if_type = NULL;
	char *if_method = NULL;
	char *if_addr = NULL;
	char *if_mask = NULL;
	char *if_gw = NULL;
	char buf[128];
	int rv;
	
	rv = xs_read_netconfig(if_index, &if_type, &if_method, &if_addr,
		&if_mask, &if_gw);
	if (rv != 0)
		return;
	
	printf("rumprun_config: configuring xenif%s as %s with %s %s\n",
		if_index, if_type, if_method, if_addr ? if_addr : "");
	snprintf(buf, sizeof buf, "xenif%s", if_index);
	if ((rv = rump_pub_netconfig_ifcreate(buf)) != 0) {
		warnx("rumprun_config: %s: ifcreate failed: %s\n", buf,
			strerror(rv));
		goto out;
	}
	if (strcmp(if_type, "inet") == 0 &&
	    strcmp(if_method, "dhcp") == 0) {
		if ((rv = rump_pub_netconfig_dhcp_ipv4_oneshot(buf)) != 0) {
			warnx("rumprun_config: %s: dhcp_ipv4 failed: %s\n", buf,
				strerror(rv));
			goto out;
		}
	}
	else if (strcmp(if_type, "inet") == 0 &&
		 strcmp(if_method, "static") == 0) {
		if (if_addr == NULL || if_mask == NULL) {
			warnx("rumprun_config: %s: missing if_addr/mask\n",
			    buf);
			goto out;
		}
		if ((rv = rump_pub_netconfig_ipv4_ifaddr(buf, if_addr,
			if_mask)) != 0) {
			warnx("rumprun_config: %s: ipv4_ifaddr failed: %s\n",
				buf, strerror(rv));
			goto out;
		}
		if (if_gw &&
			(rv = rump_pub_netconfig_ipv4_gw(if_gw)) != 0) {
			warnx("rumprun_config: %s: ipv4_gw failed: %s\n",
				buf, strerror(rv));
			goto out;
		}
	}
	else {
		warnx("rumprun_config: %s: unknown type/method %s/%s\n",
			buf, if_type, if_method);
	}

out:
	free(if_type);
	free(if_method);
	if (if_addr)
		free(if_addr);
	if (if_mask)
		free(if_mask);
	if (if_gw)
		free(if_gw);
}