Beispiel #1
0
/*---------------------------------------------------------------------------*/
void sendbyte(unsigned char bbyte) //发送一个字节
{
    PORT_FUNC_GPIO(SID_PORT, SID_PIN);
    PORT_DIR_OUTPUT(SID_PORT, SID_PIN);
    PORT_FUNC_GPIO(CLK_PORT, CLK_PIN);
    PORT_DIR_OUTPUT(CLK_PORT, CLK_PIN);
	
	unsigned char i;
	for(i=0;i<8;i++)
	{
		if(bbyte&0x80)//取出最高位
			PORT_SET(SID_PORT, SID_PIN); 
		else
			PORT_CLEAR(SID_PORT, SID_PIN);
	 PORT_SET(CLK_PORT, CLK_PIN); 
	 PORT_CLEAR(CLK_PORT, CLK_PIN);
	 bbyte <<= 1; //左移
	 }  
}
Beispiel #2
0
void *port_list(struct tracedump *td, bool tcp)
{
	char *path;
	char buf[BUFSIZ], *ptr1, *ptr2;
	FILE *fp;
	uint8_t *list;
	unsigned long port;

	path = tcp ? "/proc/net/tcp" : "/proc/net/udp";

	fp = fopen(path, "r");
	if (!fp) {
		dbg(1, "fopen(%s): %s\n", path, strerror(errno));
		return NULL;
	}

	/* a bitmask 1: active, 0: inactive */
	list = mmatic_zalloc(td->mm, UINT16_MAX / sizeof(uint8_t));

	while (fgets(buf, sizeof buf, fp)) {
		/* first : */
		ptr1 = strchr(buf, ':');
		if (!ptr1) continue;
		ptr1++;

		/* second : */
		ptr1 = strchr(ptr1, ':');
		if (!ptr1) continue;
		ptr1++;

		/* space */
		ptr2 = strchr(ptr1, ' ');
		if (!ptr2) continue;
		ptr2[0]  = '\0';

		/* translate */
		port = strtol(ptr1, NULL, 16);
		PORT_SET(list, port);
	}

	fclose(fp);
	return list;
}