Exemplo n.º 1
0
Arquivo: cartio.c Projeto: d-a-v/if2a
int cart_read_mem_to_file (const char* file, int address, int size, enum read_type_e read_type)
{
	FILE* f;
	unsigned char data[size];

	if (cart_read_mem(data, address, size) < 0)
		return -1;

	switch (read_type)
	{
	case READ_MANY: // to read several memory areas into file
		if ((f = fopen(file, "ab")) == NULL)
		{
			printerrno(file);
			return -1;
		}
		break;
		
	case READ_ONCE:
		if ((f = fopen(file, "wb")) == NULL)
		{
			printerrno(file);
			return -1;
		}
		break;
		
	default:
		printerr("This is bad. Should have reached either WRITE_MANY or WRITE_ONCE\n");
		return -1;
	}

	if (fwrite(data, size, 1, f) != 1)
	{
		printerrno(file);
		fclose(f);
		return -1;
	}
	fclose(f);
	return 0;
}
Exemplo n.º 2
0
/*
 * Class:     com_leandrosales_jdccp_wrapper_JDCCPSocket
 * Method:    bind
 * Signature: (Ljava/lang/String;I)V
 */
JNIEXPORT void JNICALL Java_com_leandrosales_jdccp_wrapper_JDCCPSocket_bind
  (JNIEnv *env, jobject thisObj, jstring host, jstring port) {

  	socketId = (jint)socket(AF_INET, SOCK_DCCP, IPPROTO_DCCP);
  	const char *hostconn = (*env)->GetStringUTFChars(env, host, 0);
  	const char *portconn = (*env)->GetStringUTFChars(env, port, 0);

	if (getaddrinfo("localhost", "5001", NULL, &hostinfo)) {
		printerrno("getaddrinfo");
    }

    (*env)->ReleaseStringUTFChars(env, host, hostconn);
    (*env)->ReleaseStringUTFChars(env, port, portconn);
    
    socket_options(socketId);
    if (errno) {
    	printerrno("set option");
    }
    
    alreadyBind = 1;
	Java_com_leandrosales_jdccp_wrapper_JDCCPSocket_connect(env, thisObj, host, port);
}
Exemplo n.º 3
0
/*
 * Class:     com_leandrosales_jdccp_wrapper_JDCCPSocket
 * Method:    connect
 * Signature: (Ljava/lang/String;I)V
 */
JNIEXPORT jint JNICALL Java_com_leandrosales_jdccp_wrapper_JDCCPSocket_connect
  (JNIEnv *env, jobject thisObj, jstring host, jstring port) {

	if (alreadyBind == 0) {
		Java_com_leandrosales_jdccp_wrapper_JDCCPSocket_connect(env, thisObj, host, port);
	}
	//return connect(socketId, hostinfo->ai_addr, hostinfo->ai_addrlen);
	connect(socketId, hostinfo->ai_addr, hostinfo->ai_addrlen);
	if (errno) {
		printerrno("connect");
	}
    //just for test propose!
    writen(socketId, "testando jdccp", strlen("testando jdccp"));
}