main.c
/**
print the contents of the buffer containing packet info
@param buffer: the paket buffer to print
@param len: the buffer size
**/
print the contents of the buffer containing packet info
print the contents of the buffer containing packet info
void printPacket(const char* buffer, size_t len) {
	switch (buffer[1]) {
		case 1:
			printf("RRQ|%s|%s\n", buffer+2, strchr(buffer+2, 0)+1);
			break;
		case 2:
			printf("WRQ|%s|%s\n", buffer+2, strchr(buffer+2, 0)+1);
			break;
		case 3:
			printf("DATA|%d|%.*s\n", packetBlockNumber(buffer), (int) len-4, buffer+4);
			break;
		case 4:
			printf("ACK|%u\n", packetBlockNumber(buffer));
			break;
		case 5:
			printf("ERROR|%d|%s\n", packetBlockNumber(buffer), buffer+4);
			break;
		default:
			printf("Invalid packet\n");
	}
}
void printPacket ( const char * buffer , size_t len ) { switch ( buffer [ 1 ] ) { case 1 : printf ( " \n " , buffer + 2 , strchr ( buffer + 2 , 0 ) + 1 ) ; break ; case 2 : printf ( " \n " , buffer + 2 , strchr ( buffer + 2 , 0 ) + 1 ) ; break ; case 3 : printf ( " \n " , packetBlockNumber ( buffer ) , ( int ) len - 4 , buffer + 4 ) ; break ; case 4 : printf ( " \n " , packetBlockNumber ( buffer ) ) ; break ; case 5 : printf ( " \n " , packetBlockNumber ( buffer ) , buffer + 4 ) ; break ; default : printf ( " \n " ) ; } }
print the contents of the buffer containing packet info
print the contents of the buffer containing packet info