通讯协议数据包的话,前面放你用来判断你这个包所做事情的功能码,然后后面接数据所占字符的长度,最后一段是你要发送的数据,可以是数组也可以是结构体,看你喜欢
CMD是你要做的事
LENGTH是你后面数据的长度,方便你读数据
INFO是你的数据,你想发什么都行
解包你就从CMD开始用if,else来判断,找到对应的读取里面的内容,做你这个判断要做的事。
而相对复杂点的协议变色前面的判断内容更多的,比如控制变电所的设备,那就增加哪个变电所,变电所哪台设备,数据格式变化不大,基本都是承载在tcp,udp,.modbus这类协议上面,这些都是数据内容,是你自己定义的
去下载busybox的源码,在busybox-XXXX/coreutils/mkdir.c/* vi: set sw=4 ts=4: */
/*
* Mini mkdir implementation for busybox
*
* Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
*
* Fixed broken permission setting when -p was usedespecially in
* conjunction with -m.
*/
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
*/
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
static const char mkdir_longopts[] ALIGN1 =
"mode\0"Required_argument "m"
"parents\0" No_argument "p"
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
#endif
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE
int mkdir_main(int argc, char **argv)
{
mode_t mode = (mode_t)(-1)
int status = EXIT_SUCCESS
int flags = 0
unsigned opt
char *smode
#if ENABLE_SELINUX
security_context_t scontext
#endif
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
applet_long_options = mkdir_longopts
#endif
opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext))
if (opt &1) {
mode = 0777
if (!bb_parse_mode(smode, &mode)) {
bb_error_msg_and_die("invalid mode '%s'", smode)
}
}
if (opt &2)
flags |= FILEUTILS_RECUR
#if ENABLE_SELINUX
if (opt &4) {
selinux_or_die()
setfscreatecon_or_die(scontext)
}
#endif
if (optind == argc) {
bb_show_usage()
}
argv += optind
do {
if (bb_make_directory(*argv, mode, flags)) {
status = EXIT_FAILURE
}
} while (*++argv)
return status
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)