Esempio n. 1
0
void test_AddrMatch_ipv6(void)
{
	sockaddr_u   a1, a2;
	unsigned int bits;
	int          want;
	
	TEST_ASSERT_TRUE(getaddr(AF_INET6, "FEDC:BA98:7654:3210::2:FFFF", &a1));
	TEST_ASSERT_TRUE(getaddr(AF_INET6, "FEDC:BA98:7654:3210::3:FFFF", &a2));

	/* the first 111 bits are equal, so any prefix <= 111 should match */
	for (bits = 0; bits < 136; ++bits) {
		snprintf(msgbuf, sizeof(msgbuf),
			 "keyacc_amatch(*,*,%u) wrong", bits);
		want = (bits <= 111);
		TEST_ASSERT_EQUAL_MESSAGE(want, keyacc_amatch(&a1, &a2, bits), msgbuf);
	}

	TEST_ASSERT_TRUE(getaddr(AF_INET6, "FEDC:BA98:7654:3210::2:7FFF", &a1));
	TEST_ASSERT_TRUE(getaddr(AF_INET6, "FEDC:BA98:7654:3210::2:8000", &a2));

	/* the first 112 bits are equal, so any prefix <= 112 should match */
	for (bits = 0; bits < 136; ++bits) {
		snprintf(msgbuf, sizeof(msgbuf),
			 "keyacc_amatch(*,*,%u) wrong", bits);
		want = (bits <= 112);
		TEST_ASSERT_EQUAL_MESSAGE(want, keyacc_amatch(&a1, &a2, bits), msgbuf);
	}
}
Esempio n. 2
0
/*
 *  add warning headers of the form
 *	X-warning: <reason>
 *  for any headers that looked like they might be forged.
 *
 *  return byte count of new headers
 */
static int
forgedheaderwarnings(void)
{
	int nbytes;
	Field *f;

	nbytes = 0;

	/* warn about envelope sender */
	if(senders.last != nil && senders.last->p != nil &&
	    strcmp(s_to_c(senders.last->p), "/dev/null") != 0 &&
	    masquerade(senders.last->p, nil))
		nbytes += Bprint(pp->std[0]->fp,
			"X-warning: suspect envelope domain\n");

	/*
	 *  check Sender: field.  If it's OK, ignore the others because this
	 *  is an exploded mailing list.
	 */
	for(f = firstfield; f; f = f->next)
		if(f->node->c == SENDER)
			if(masquerade(getaddr(f->node), him))
				nbytes += Bprint(pp->std[0]->fp,
					"X-warning: suspect Sender: domain\n");
			else
				return nbytes;

	/* check From: */
	for(f = firstfield; f; f = f->next){
		if(f->node->c == FROM && masquerade(getaddr(f->node), him))
			nbytes += Bprint(pp->std[0]->fp,
				"X-warning: suspect From: domain\n");
	}
	return nbytes;
}
Esempio n. 3
0
void test_AddrMatch_ipv4(void)
{
	sockaddr_u   a1, a2;
	unsigned int bits;
	int          want;

	TEST_ASSERT_TRUE(getaddr(AF_INET, "192.128.2.1", &a1));
	TEST_ASSERT_TRUE(getaddr(AF_INET, "192.128.3.1", &a2));

	/* the first 23 bits are equal, so any prefix <= 23 should match */
	for (bits = 0; bits < 40; ++bits) {
		snprintf(msgbuf, sizeof(msgbuf),
			 "keyacc_amatch(*,*,%u) wrong", bits);
		want = (bits <= 23);
		TEST_ASSERT_EQUAL_MESSAGE(want, keyacc_amatch(&a1, &a2, bits), msgbuf);
	}

	TEST_ASSERT_TRUE(getaddr(AF_INET, "192.128.2.127", &a1));
	TEST_ASSERT_TRUE(getaddr(AF_INET, "192.128.2.128", &a2));

	/* the first 24 bits are equal, so any prefix <= 24 should match */
	for (bits = 0; bits < 40; ++bits) {
		snprintf(msgbuf, sizeof(msgbuf),
			 "keyacc_amatch(*,*,%u) wrong", bits);
		want = (bits <= 24);
		TEST_ASSERT_EQUAL_MESSAGE(want, keyacc_amatch(&a1, &a2, bits), msgbuf);
	}
}
Esempio n. 4
0
static int32_t getdetail(char *str,char *output,int32_t size) {
	void *addr;
	char  path[256]={0};
	char  cmd[1024]={0};
	FILE *pipe;
	int   i,j;
	char *so = strstr(str,".so");
	if(so){
		strncpy(path,str,(so-str)+3);
		if(!(addr = getaddr(str))) return -1;
		if(!(addr = getsoaddr(path,addr))) return -1;
	}
	else{
		if(0 >= readlink("/proc/self/exe", path, 256))
			return -1;
		else if(!(addr = getaddr(str))) return -1;
	}

	snprintf(cmd,1024,"addr2line -fCse %s %p", path,addr);
	pipe = popen(cmd, "r");
	if(!pipe) return -1;
	i = fread(output,1,size-1,pipe);	
	pclose(pipe);
	output[i] = '\0';
	for(j=0; j<=i; ++j) if(output[j] == '\n') output[j] = ' ';	
	return 0;
}
Esempio n. 5
0
void test_AddrMatch_anull(void)
{
	/* Check the not-an-address logic with a prefix/check length of
	 * zero bits. Any compare with a NULL or AF_UNSPEC address
	 * returns inequality (aka FALSE).
	 */
	sockaddr_u   ip4, ip6, ipn;

	memset(&ipn, 0, sizeof(ipn));
	AF(&ipn) = AF_UNSPEC;

	TEST_ASSERT_TRUE(getaddr(AF_INET , "192.128.1.1", &ip4));
	TEST_ASSERT_TRUE(getaddr(AF_INET6, "::1"        , &ip6));

	TEST_ASSERT_FALSE(keyacc_amatch(NULL, NULL, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(NULL, &ipn, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(NULL, &ip4, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(NULL, &ip6, 0));

	TEST_ASSERT_FALSE(keyacc_amatch(&ipn, NULL, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ipn, &ipn, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ipn, &ip4, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ipn, &ip6, 0));

	TEST_ASSERT_FALSE(keyacc_amatch(&ip4, NULL, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ip4, &ipn, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ip6, NULL, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ip6, &ipn, 0));
}
Esempio n. 6
0
/*
 * Remove iroutes from the push_list.
 */
void
remove_iroutes_from_push_route_list(struct options *o)
{
    if (o && o->push_list.head && o->iroutes)
    {
        struct gc_arena gc = gc_new();
        struct push_entry *e = o->push_list.head;

        /* cycle through the push list */
        while (e)
        {
            char *p[MAX_PARMS];
            bool enable = true;

            /* parse the push item */
            CLEAR(p);
            if (e->enable
                && parse_line(e->option, p, SIZE(p), "[PUSH_ROUTE_REMOVE]", 1, D_ROUTE_DEBUG, &gc))
            {
                /* is the push item a route directive? */
                if (p[0] && !strcmp(p[0], "route") && !p[3])
                {
                    /* get route parameters */
                    bool status1, status2;
                    const in_addr_t network = getaddr(GETADDR_HOST_ORDER, p[1], 0, &status1, NULL);
                    const in_addr_t netmask = getaddr(GETADDR_HOST_ORDER, p[2] ? p[2] : "255.255.255.255", 0, &status2, NULL);

                    /* did route parameters parse correctly? */
                    if (status1 && status2)
                    {
                        const struct iroute *ir;

                        /* does route match an iroute? */
                        for (ir = o->iroutes; ir != NULL; ir = ir->next)
                        {
                            if (network == ir->network && netmask == netbits_to_netmask(ir->netbits >= 0 ? ir->netbits : 32))
                            {
                                enable = false;
                                break;
                            }
                        }
                    }
                }

                /* should we copy the push item? */
                e->enable = enable;
                if (!enable)
                {
                    msg(D_PUSH, "REMOVE PUSH ROUTE: '%s'", e->option);
                }
            }

            e = e->next;
        }

        gc_free(&gc);
    }
}
Esempio n. 7
0
void test_AddrMatch_afmix(void)
{
	sockaddr_u ip6, ip4;
	
	TEST_ASSERT_TRUE(getaddr(AF_INET , "192.128.1.1", &ip4));
	TEST_ASSERT_TRUE(getaddr(AF_INET6, "::1"        , &ip6));

	TEST_ASSERT_FALSE(keyacc_amatch(&ip4, &ip6, 0));
	TEST_ASSERT_FALSE(keyacc_amatch(&ip6, &ip4, 0));
}
Esempio n. 8
0
/* send message adding our own reply-to and precedence */
void
getaddrs(void)
{
	Field *f;

	for(f = firstfield; f; f = f->next){
		if(f->node->c == FROM && from == nil)
			from = getaddr(f->node);
		if(f->node->c == SENDER && sender == nil)
			sender = getaddr(f->node);
	}
}
Esempio n. 9
0
File: bot.c Progetto: ct187/irc-bot
static int connect_to_server()
{
	struct addrinfo *addr;
	int fd, getaddr_res;
	int conn_result;

	time(&last_activity);

	getaddr_res = getaddr(&addr);
	if (getaddr_res == -1)
		return -1;

	fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
	if (fd < 0) {
		log_err("Error creating socket: %s", strerror(errno));
		freeaddrinfo(addr);
		exit(EXIT_FAILURE);
	}

	conn_result = connect(fd, addr->ai_addr, addr->ai_addrlen);
	if (conn_result < 0) {
		log_err("Error connecting to server: %s",
				strerror(errno));
		freeaddrinfo(addr);
		return -1;
	}
	freeaddrinfo(addr);

	return fd;
}
Esempio n. 10
0
static void _log_stack(int32_t logLev,int32_t start,char *str) {
	void*                   bt[64];
	char**                  strings;
	size_t                  sz;
	int32_t                 i,f;
	int32_t 				size = 0;	
	char 					logbuf[MAX_LOG_SIZE];
	char                    addr[32],buf[1024];
	char 				   *ptr;		
	sz      = backtrace(bt, 64);
	strings = backtrace_symbols(bt, sz);
	size   += snprintf(logbuf,MAX_LOG_SIZE,"%s",str);	    		    			
	for(i = start,f = 0; i < sz; ++i) {
		if(strstr(strings[i],"main+")) break;
		ptr  = logbuf + size;
		if(getaddr(strings[i],addr,32) && !addr2line(addr,buf,1024))
			size += snprintf(ptr,MAX_LOG_SIZE-size,
				"\t% 2d: %s %s\n",++f,strings[i],buf);
		else
			size += snprintf(ptr,MAX_LOG_SIZE-size,
				"\t% 2d: %s\n",++f,strings[i]);		
	}
	SYS_LOG(logLev,"%s",logbuf);
	free(strings);	
}
Esempio n. 11
0
/*
 * Display an individual arp entry
 */
static int
get(char *host)
{
	struct sockaddr_in *addr;
	int found;

	addr = getaddr(host);
	if (addr == NULL)
		return (1);

	xo_set_version(ARP_XO_VERSION);
	xo_open_container("arp");
	xo_open_list("arp-cache");

	found = search(addr->sin_addr.s_addr, print_entry);

	if (found == 0) {
		xo_emit("{d:hostname/%s} ({d:ip-address/%s}) -- no entry",
		    host, inet_ntoa(addr->sin_addr));
		if (rifname)
			xo_emit(" on {d:interface/%s}", rifname);
		xo_emit("\n");
	}

	xo_close_list("arp-cache");
	xo_close_container("arp");
	xo_finish();

	return (found == 0);
}
Esempio n. 12
0
 safe_func_offset getsym_safe(ElfAddr addr, char* buffer, size_t length)
 {
   // inside bootloader area
   if (UNLIKELY(addr >= 0x7c00 && addr < 0x7e00))
       return {boot_stringz, 0x7c00, (uint32_t) addr - 0x7c00};
   // find symbol name for all addresses above first page
   // which are treated as possible null pointers
   if (LIKELY(addr > 0x1000))
   {
     // resolve manually from symtab
     auto* sym = getaddr(addr);
     if (LIKELY(sym)) {
       auto     base   = sym->st_value;
       uint32_t offset = (uint32_t) (addr - base);
       // return string name for symbol
       return {demangle_safe( sym_name(sym), buffer, length ), static_cast<uintptr_t>(base), offset};
     }
   }
   else if (addr == 0x0) {
     return {"0x0 (null)", static_cast<uintptr_t>(addr), 0};
   }
   // function or space not found
   snprintf(buffer, length, "%p", (void*) addr);
   return {buffer, static_cast<uintptr_t>(addr), 0};
 }
Esempio n. 13
0
void
add_client_nat_to_option_list(struct client_nat_option_list *dest,
                              const char *type,
                              const char *network,
                              const char *netmask,
                              const char *foreign_network,
                              int msglevel)
{
    struct client_nat_entry e;
    bool ok;

    if (!strcmp(type, "snat"))
    {
        e.type = CN_SNAT;
    }
    else if (!strcmp(type, "dnat"))
    {
        e.type = CN_DNAT;
    }
    else
    {
        msg(msglevel, "client-nat: type must be 'snat' or 'dnat'");
        return;
    }

    e.network = getaddr(0, network, 0, &ok, NULL);
    if (!ok)
    {
        msg(msglevel, "client-nat: bad network: %s", network);
        return;
    }
    e.netmask = getaddr(0, netmask, 0, &ok, NULL);
    if (!ok)
    {
        msg(msglevel, "client-nat: bad netmask: %s", netmask);
        return;
    }
    e.foreign_network = getaddr(0, foreign_network, 0, &ok, NULL);
    if (!ok)
    {
        msg(msglevel, "client-nat: bad foreign network: %s", foreign_network);
        return;
    }

    add_entry(dest, &e);
}
Esempio n. 14
0
File: tap.c Progetto: nhanh0/hah
int main(int argc, char *argv[])
{
	int i;

	if (argc < 4) {
		fprintf(stderr, "syntax: %s <tapdevice> <localaddr or ::> <remotename>\n", argv[0]);
		return 1;
	}

	tapdevice = argv[1];

	if (getaddr(argv[2], &localaddr)) {
		fprintf (stderr, "Can't resolve local hostname/address %s\n",
			argv[2]);
		return 1;
	}

	numremote = argc - 3;
	for (i=3;i<argc;i++)
		if (getaddr(argv[i], &remoteaddr[i-3])) {
			fprintf(stderr,
				"can't resolve hostname %s\n",
				argv[i]);
			return 1;
		}

	if ((tap = open(tapdevice, O_RDWR)) < 0) {
		perror("open");
		return 1;
	}

	if ((sock = socket(AF_INET6, SOCK_RAW, 97)) < 0) {
		perror("socket");
		return 1;
	}

	if (bind(sock, &localaddr, sizeof(localaddr)) < 0) {
		perror("bind");
		return 1;
	}

	handle();

	return 0;
}
Esempio n. 15
0
static void branch(int flag) {
	signed char dist;
	dist=(signed char)getaddr(imm);
	wval=pc+dist;
	if (flag) {
		cycles+=((pc&0x100)!=(wval&0x100))?2:1;
		pc=wval;
	}
}
Esempio n. 16
0
void test_AddrMatch_self6(void)
{
	sockaddr_u   ip6;
	unsigned int bits;
	
	TEST_ASSERT_TRUE(getaddr(AF_INET6, "::1" , &ip6));
	for (bits = 0; bits < 136; ++bits)
		TEST_ASSERT_TRUE(keyacc_amatch(&ip6, &ip6, bits));
}
Esempio n. 17
0
void test_AddrMatch_self4(void)
{
	sockaddr_u   ip4;
	unsigned int bits;
	
	TEST_ASSERT_TRUE(getaddr(AF_INET, "192.128.1.1", &ip4));
	for (bits = 0; bits < 40; ++bits)
		TEST_ASSERT_TRUE(keyacc_amatch(&ip4, &ip4, bits));
}
Esempio n. 18
0
void
ifconfig_pool_read(struct ifconfig_pool_persist *persist, struct ifconfig_pool *pool)
{
    const int buf_size = 128;

    update_time();
    if (persist && persist->file && pool)
    {
        struct gc_arena gc = gc_new();
        struct buffer in = alloc_buf_gc(256, &gc);
        char *cn_buf;
        char *ip_buf;
        int line = 0;

        ALLOC_ARRAY_CLEAR_GC(cn_buf, char, buf_size, &gc);
        ALLOC_ARRAY_CLEAR_GC(ip_buf, char, buf_size, &gc);

        while (true)
        {
            ASSERT(buf_init(&in, 0));
            if (!status_read(persist->file, &in))
            {
                break;
            }
            ++line;
            if (BLEN(&in))
            {
                int c = *BSTR(&in);
                if (c == '#' || c == ';')
                {
                    continue;
                }
                msg( M_INFO, "ifconfig_pool_read(), in='%s', TODO: IPv6",
                     BSTR(&in) );

                if (buf_parse(&in, ',', cn_buf, buf_size)
                    && buf_parse(&in, ',', ip_buf, buf_size))
                {
                    bool succeeded;
                    const in_addr_t addr = getaddr(GETADDR_HOST_ORDER, ip_buf, 0, &succeeded, NULL);
                    if (succeeded)
                    {
                        msg( M_INFO, "succeeded -> ifconfig_pool_set()");
                        ifconfig_pool_set(pool, cn_buf, addr, persist->fixed);
                    }
                }
            }
        }

        ifconfig_pool_msg(pool, D_IFCONFIG_POOL);

        gc_free(&gc);
    }
}
Esempio n. 19
0
int base::TCPClient::Connect(const char *ipaddr, in_port_t port)
{
	const char *ipaddr32 = getaddr(ipaddr);
	struct in_addr ipv4addr;
	inet_pton(AF_INET, ipaddr32, &ipv4addr);
	
	struct sockaddr_in addrin;
	addrin.sin_family = AF_INET;
	addrin.sin_port = htons(port);
	addrin.sin_addr.s_addr = ipv4addr.s_addr;
	return connect(_sockfd, (const struct sockaddr *)&addrin, sizeof(addrin));
}
Esempio n. 20
0
/* Used by a, b, c, C, d and g commands to find linenumber */
setdot() {
	if (ncolonflag) {
		dot = integ;
		get(dot, ISP);
		if (errflg)
			dot = -1;
	} else {
		dot = getaddr(proc, integ);
		if (dot == -1)
			errflg = "Bad line number";
	}
}
Esempio n. 21
0
int main(int argc, char* argv[])
{
	const int BUF_SIZE = 50;
	char url[BUF_SIZE];
	char filepath[BUF_SIZE];
	char filename[BUF_SIZE];
	int sock;
	struct addrinfo* addrinf;
	
	//* GET url, filepath, AND filename
	if( argc>1)
		get_url_file( argv[1], url, filepath, filename, BUF_SIZE);
	else
		finish("Too few arguments\n", 1);
	
	if( !strlen( filename)) strcpy( filename, "index.html");	
	printf( "url: [%s]\nfilepath: [%s]\nfilename: [%s]\n\n", url, filepath, filename);
	//*/
	
	//* GET REMOTE addrinf
	addrinf = getaddr( url, "80", AF_UNSPEC);
	if( !addrinf) finish( "getaddrinfo() returned no results\n", 1);
	//*/
	
	//* CREATE AND CONNECT THE SOCKET
	sock = socket( addrinf->ai_family, SOCK_STREAM, 0);
	if( sock == -1)
	{
		printf( "couldn't create the socket, errno(%d): %s\n", errno, strerror( errno));
		exit(1);
	}
	if( connect( sock, addrinf->ai_addr, addrinf->ai_addrlen) != 0)
	{
		printf( "couldn't connect, errno(%d): %s\n", errno, strerror( errno));
		exit(1);
	}//*/

	//* DO IT
	send_request( sock, url, filepath);
	recv_response( sock, filename);
	//*/

	//* CLEAN UP AND EXIT
	assert( shutdown( sock, SHUT_RDWR)==0);
	//*/

	return 0;
}
Esempio n. 22
0
putvalue(struct header *hd, int fd, struct sym *s, char *loc, int len)
{
	long		adr, getaddr();

	adr = getaddr(hd, s);
	if (adr == -1)
		return (-1);

	if (lseek(fd, (off_t) adr, 0) < 0)
		return (-1);

	if (write(fd, loc, len) != len)
		return (-2);

	return (0);
}
Esempio n. 23
0
int
main(int argc, char *argv[])
{
	int sfd;
	int c;
	struct sockaddr_storage ss;
	const char *msg = "hello";
	const char *addr = "127.0.0.1";
	int type = SOCK_STREAM;
	in_port_t port = 6161;
	socklen_t slen;
	char buf[128];

	while ((c = getopt(argc, argv, "a:m:p:u")) != -1) {
		switch (c) {
		case 'a':
			addr = optarg;
			break;
		case 'm':
			msg = optarg;
			break;
		case 'p':
			port = (in_port_t)atoi(optarg);
			break;
		case 'u':
			type = SOCK_DGRAM;
			break;
		default:
			usage(c);
		}
	}

	getaddr(addr, port, &ss, &slen);

	if ((sfd = socket(AF_INET, type, 0)) == -1)
		err(EXIT_FAILURE, "socket");

	sockaddr_snprintf(buf, sizeof(buf), "%a:%p", (const void *)&ss);
	printf("connecting to: %s\n", buf);
	if (connect(sfd, (const void *)&ss, slen) == -1)
		err(EXIT_FAILURE, "connect");

	size_t len = strlen(msg) + 1;
	if (write(sfd, msg, len) != (ssize_t)len)
		err(EXIT_FAILURE, "write");
	return 0;
}
Esempio n. 24
0
static int ui_cmd_go(ui_cmdline_t *cmd,int argc,char *argv[])
{
    char *arg;

    arg = cmd_getarg(cmd,0);
    if (arg) {
	cfe_loadargs.la_entrypt = getaddr(arg);
	}

    if (cmd_sw_isset(cmd,"-noclose")) {
	cfe_loadargs.la_flags |= LOADFLG_NOCLOSE;
	}

    cfe_go(&cfe_loadargs);

    return 0;
}
Esempio n. 25
0
getvalue(struct header *hd, int fd, struct sym *s, char *cp, int len)
{
	register int	i;
	long		getaddr(), addr;

	addr = getaddr(hd, s);
	if (addr == -1)
		return (-1);

	if (lseek(fd, (off_t) addr, 0) < 0)
		return (-1);

	if ((i = read(fd, cp, len)) != len)
		return (-1);

	return (0);
}
Esempio n. 26
0
/*
 * Display an individual arp entry
 */
static int
get(char *host)
{
	struct sockaddr_in *addr;

	addr = getaddr(host);
	if (addr == NULL)
		return (1);
	if (0 == search(addr->sin_addr.s_addr, print_entry)) {
		printf("%s (%s) -- no entry",
		    host, inet_ntoa(addr->sin_addr));
		if (rifname)
			printf(" on %s", rifname);
		printf("\n");
		return (1);
	}
	return (0);
}
Esempio n. 27
0
static int client_connect(void)
{
	int ret;
	socklen_t addrlen;
	struct sockaddr *sin;

	ret = common_setup();
	if (ret != 0)
		goto err;

	ret = getaddr(dst_addr, port, (struct sockaddr **) &sin,
			  (socklen_t *) &addrlen);
	if (ret != 0)
		goto err;

	ret = fi_connect(ep, sin, NULL, 0);
	if (ret) {
		printf("fi_connect %s\n", fi_strerror(-ret));
		goto err;
	}

	// send initial message to server
	ret = send_xfer(4);
	if (ret != 0)
		goto err;


	// wait for reply to know server is ready
	ret = recv_xfer(4);
	if (ret != 0)
		goto err;

	return 0;

err:
	free_ep_res();
	fi_close(&av->fid);
	fi_close(&ep->fid);
	fi_close(&dom->fid);
	fi_close(&fab->fid);
	return ret;
}
Esempio n. 28
0
static int cmd_write_raw(int argc, char **argv)
{
    uint32_t addr;

    if (argc < 3) {
        printf("usage: %s <addr> <data>\n", argv[0]);
        return 1;
    }

    addr = getaddr(argv[1]);

    /* try to align */
    memcpy(raw_buf, argv[2], strlen(argv[2]));

    flashpage_write_raw((void*)addr, raw_buf, strlen(raw_buf));

    printf("wrote local data to flash address %#lx of len %u\n",
           addr, strlen(raw_buf));
    return 0;
}
Esempio n. 29
0
//------------------------------------------------------------------------
//  netout  -  start network by finding address and forward IP packets
//------------------------------------------------------------------------
PROCESS
netout(int userpid, int icmpp)
{
	struct epacket *packet;
	struct ip *ipptr;
	long tim;
	int len;
	char name[MNAMELEN];
	IPaddr addr;

	getaddr(addr);
	gettime(&tim);
	getname(name, MNAMELEN);
	resume(userpid);
	while (TRUE) {
		packet = (struct epacket *)preceive(icmpp);
		ipptr = (struct ip *)packet->ep_data;
		memmove(addr, ipptr->i_dest, IPLEN);
		len = net2hs(ipptr->i_paclen) - IPHLEN;
		ipsend(addr, packet, len);
	}
}
Esempio n. 30
0
static void
cecon(char *path)
{
	Proc *up = externup();
	char buf[64];
	uint8_t ea[6];
	Chan *dc, *cc;
	If *ifc, *nifc;

	nifc = nil;
	for(ifc = ifs; ifc < ifs+nelem(ifs); ifc++)
		if(ifc->d == nil)
			nifc = ifc;
		else if(strcmp(ifc->path, path) == 0)
			return;
	ifc = nifc;
	if(ifc == nil)
		error("out of interface structures");

	getaddr(path, ea);
	snprint(buf, sizeof buf, "%s!0xbcbc", path);
	dc = chandial(buf, nil, nil, &cc);
	if(dc == nil || cc == nil){
		if (cc)
			cclose(cc);
		if (dc)
			cclose(dc);
		snprint(up->genbuf, sizeof up->genbuf, "can't dial %s", buf);
		error(up->genbuf);
	}
	ifc->d = cc->dev;
	ifc->cc = cc;
	ifc->dc = dc;
	strncpy(ifc->path, path, sizeof ifc->path);
	memmove(ifc->ea, ea, 6);
	snprint(up->genbuf, sizeof up->genbuf, "cec:%s", path);
	kproc(up->genbuf, cecrdr, ifc);
}