Implementation of Message Receiver

 

 

/** * @copyright Copyright © 2025. All rights reserved. * * @file checksum.c * @brief Implementation of rotational checksum calculation and verification * @details Contains functions for computing a checksum using byte-wise summation with bit rotation, * and verifying data integrity against stored checksum values. * * @author Chen Xinxin <chenxinxin1@tp-link.com.hk> * @date 2025-08-14 */ #ifndef CHECKSUM_H #define CHECKSUM_H #include <stddef.h> /******************************************************************************/ /* PUBLIC FUNCTIONS */ /** * @fn unsigned int calculate_checksum(const unsigned char *data, size_t size) * @brief Calculate rotational checksum for binary data * @param[in] data Pointer to the input data buffer * @param[in] size Size of the data buffer in bytes * @return 32-bit checksum value computed with rotation * @details Computes checksum by summing each byte with left rotation (3 bits) after each addition. * Rotation formula: sum = (sum << 3) | (sum >> 29) */ unsigned int calculate_checksum(const unsigned char *data, size_t size); /** * @fn int verify_checksum(const unsigned char *data, size_t size, unsigned int checksum) * @brief Validates data integrity using precomputed checksum * @param[in] data Pointer to data buffer for verification * @param[in] size Length of data buffer in bytes * @param[in] checksum Reference checksum value for comparison * @return 1 if computed checksum matches reference, 0 otherwise */ int verify_checksum(const unsigned char *data, size_t size, unsigned int checksum); #endif /* CHECKSUM_H */按照这个格式给以下的文件添加完整注释/** * @file common.h * @brief Common definitions and structures for the network simulation */ #ifndef COMMON_H #define COMMON_H #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #define MAX_DATA_SIZE 1024 #define MSG_TYPE_A_TO_B 1 #define MSG_TYPE_B_TO_A 2 #define MSG_TYPE_B_READY 3 /** * @struct message * @brief Structure for inter-process communication messages */ struct message { long mtype; pid_t sender_pid; size_t data_size; unsigned char data[MAX_DATA_SIZE]; unsigned int checksum; int is_valid; }; /** * @struct stats_entry * @brief Structure for tracking statistics of each transfer */ struct stats_entry { time_t timestamp; size_t data_size; int is_valid; }; /** * @struct stats_collector * @brief Structure for collecting overall statistics */ struct sender_stats_collector { struct stats_entry *entries; size_t count; size_t total_valid; size_t total_invalid; size_t total_bytes_sent; }; struct reciever_stats_collector { struct stats_entry *entries; size_t count; size_t total_valid; size_t total_invalid; size_t total_bytes_received; }; #endif /* COMMON_H */
08-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值