summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAN-TW <lantw44@gmail.com>2013-12-21 00:11:26 +0800
committerLAN-TW <lantw44@gmail.com>2013-12-21 00:11:26 +0800
commit0a4779e0b1c1b8177aa1c2aa575e79d1c51aad2c (patch)
tree1b1c711a160ec23487390c6ad3954291c97a57ba
parent36f00fbd5aee43a564d5932a6a9c2956c4ab24cc (diff)
downloadcn2013-0a4779e0b1c1b8177aa1c2aa575e79d1c51aad2c.tar.gz
cn2013-0a4779e0b1c1b8177aa1c2aa575e79d1c51aad2c.tar.zst
cn2013-0a4779e0b1c1b8177aa1c2aa575e79d1c51aad2c.zip
HW2: 移除 ump_common_copy
-rw-r--r--hw2/ump-common.h17
-rw-r--r--hw2/ump-pkt.h3
2 files changed, 4 insertions, 16 deletions
diff --git a/hw2/ump-common.h b/hw2/ump-common.h
index 0457f88..a295736 100644
--- a/hw2/ump-common.h
+++ b/hw2/ump-common.h
@@ -9,16 +9,6 @@
#define SOCKADDR_IN(x) ((struct sockaddr_in*)(x))
#define SOCKADDR_IN6(x) ((struct sockaddr_in6*)(x))
-static inline void ump_common_copy (
- void* dest, const void* src, size_t len) {
-
- uint8_t* dest_byte = dest;
- const uint8_t* src_byte = src;
- for (int i = 0; i < len; i++) {
- dest_byte[i] = src_byte[i];
- }
-}
-
#define UMP_COMMON_MOVE_POINTER(x,offset) (((uint8_t*)(x)) + (offset))
#define UMP_COMMON_UINT8_ONE ((uint8_t)(1))
#define UMP_COMMON_IPV4_ADDRLEN 4
@@ -26,15 +16,12 @@ static inline void ump_common_copy (
#define UMP_COMMON_DEFINE_GETTER(struct_type,func_ns,name,offset,type) \
static inline type func_ns ## _get_ ## name (struct_type* pkt) { \
- type x; \
- ump_common_copy (&x, UMP_COMMON_MOVE_POINTER (pkt, offset), \
- sizeof (type) / sizeof (uint8_t)); \
+ type x = *(type*)UMP_COMMON_MOVE_POINTER (pkt, offset); \
return x; \
}
#define UMP_COMMON_DEFINE_SETTER(struct_type,func_ns,name,offset,type) \
static inline void func_ns ## _set_ ## name (struct_type* pkt, type x) { \
- memcpy (UMP_COMMON_MOVE_POINTER (pkt, offset), &x, \
- sizeof (type) / sizeof (uint8_t)); \
+ *(type*)UMP_COMMON_MOVE_POINTER (pkt, offset) = x; \
}
#define UMP_COMMON_DEFINE_BOTH(struct_type,func_ns,name,offset,type) \
UMP_COMMON_DEFINE_GETTER (struct_type,func_ns,name,offset,type) \
diff --git a/hw2/ump-pkt.h b/hw2/ump-pkt.h
index f1f3d7c..05b97df 100644
--- a/hw2/ump-pkt.h
+++ b/hw2/ump-pkt.h
@@ -8,6 +8,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include <string.h>
#define UMP_PKT_SIZE 1024
@@ -64,7 +65,7 @@ static inline void ump_pkt_set_app_data (
UmpPkt* pkt, const uint8_t* data, size_t len) {
uint8_t* app_data = ump_pkt_get_app_data (pkt);
- ump_common_copy (app_data, data, len);
+ memcpy (app_data, data, len);
pkt->app_data_len = len;
}