/*@author: lgh@
*
* */
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <netinet/in.h>//ntohl
#include <arpa/inet.h> //inet_addr
#include <sys/types.h>
#ifdef UNICODE
#define T(x) __TXT(x)
#define __TXT(s) L ## s
#else
#define T(s) s
#endif /* UNICODE */
/*
#if defined (DEBUG_DISABLE)
#undef DEBUG_DISABLE
#else
#endif
*/
/*********************************************************************/
#ifndef DEBUG_DISABLE
/*
#define lprint(tag, fmt...) \
do{if(tag)printf(fmt);}while(0)
*/
#define lprint(x, ...) do{printf(x, ##__VA_ARGS__);}while(0)
#else
#define lprint(tag, fmt...)
#endif
/*********************************************************************/
#ifdef CONFIG_DUAL_IMAGE
#if defined (CONFIG_RT2880_FLASH_2M)
#define IMAGE1_SIZE 0x100000
#elif defined (CONFIG_RT2880_FLASH_4M)
#define IMAGE1_SIZE 0x200000
#elif defined (CONFIG_RT2880_FLASH_8M)
#define IMAGE1_SIZE 0x400000
#elif defined (CONFIG_RT2880_FLASH_16M)
#define IMAGE1_SIZE 0x800000
#elif defined (CONFIG_RT2880_FLASH_32M)
#define IMAGE1_SIZE 0x1000000
#else
#define IMAGE_SIZE TEST
#endif
#endif//end #ifdef,否则会出现25:1: error: unterminated #ifdef,这样的错
/*********************************************************************/
typedef void* (*square_t)(int* x);
void* square (int* x)
{
*x *= *x;
return (void*)square;
}
int lt1224(void)
{
int x = ;
((square_t)((square_t)((square_t)square (&x)) (&x)) (&x)) (&x);
printf ("%d\n", x);
return ;
}
/*********************************************************************/
#ifndef NIP4
#define NIP4_FMT "%u.%u.%u.%u"
#define NIP4(addr) \
((unsigned char *)&addr)[], \
((unsigned char *)&addr)[], \
((unsigned char *)&addr)[], \
((unsigned char *)&addr)[]
#define HIP4_FMT "%u.%u.%u.%u"
#define HIP4(addr) \
((unsigned char *)&addr)[], \
((unsigned char *)&addr)[], \
((unsigned char *)&addr)[], \
((unsigned char *)&addr)[]
#endif
#ifndef NIP6
#define NIP6_FMT "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x"
#define NIP6(addr) \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[]), \
(unsigned)((addr)[])
#endif
/*
#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
#else
#define __bitwise__
#endif
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else
#define __bitwise
#endif
typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
typedef __u32 __bitwise __be32;
typedef __u64 __bitwise __le64;
typedef __u64 __bitwise __be64;
*/
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
typedef __signed__ long __s64;
typedef unsigned long __u64;
union nf_inet_addr {
__u32 all[];
__u32 ip;// __be32 ip;
// __be32 ip6[4];
struct in_addr in;
struct in6_addr in6;
};
/*********************************************************************/
union endian{
int i;
char c;
};
int main(int argc, char *argv[])
{
char *s="";
char *p;
p=strpbrk(s,"a1 839"); /*1会最先在s字符串中找到*/
lprint("%s\n",p);
p=strpbrk(s,"");/*3 会最先在s 字符串中找到*/
lprint("%s\n",p);
lprint("%s\n", T("deling"));
lprint("************************************************************************\n");
lt1224();
lprint("************************************************************************\n");
if(argc != )
{
return ;
}
union endian le;
le.i = 0x3456;/*16bit宽的数*/
if(le.c == 0x56){
lprint("little endian\n");
}else lprint("big endian\n");
printf("%0x, %0x\n", le.i, le.c);
char ipdot[] = {};/*点分十进制*/
long iphost = ;/*主机字节序,x86一般都是小端模式*/
long ipnet = ;/*网络字节序,大端模式*/
strncpy(ipdot, argv[], sizeof(ipdot));
lprint("Get ipdot:%s\n", ipdot);
ipnet = inet_addr(ipdot);
lprint("Get ipnet:%ld:"NIP4_FMT"\n", ipnet, NIP4(ipnet));
iphost = ntohl(ipnet);
lprint("Get iphost:%ld:"NIP4_FMT"\n", iphost, NIP4(iphost));
lprint("Get iphost:%ld:"HIP4_FMT"\n", iphost, HIP4(iphost));
iphost++;
lprint("Get iphost++:%ld:"HIP4_FMT"\n", iphost, HIP4(iphost));
/*net --> host*/
unsigned array[];
array[] = (ntohl(ipnet) >> ) & 0xFF;
array[] = (ntohl(ipnet) >> ) & 0xFF;
array[] = (ntohl(ipnet) >> ) & 0xFF;
array[] = ntohl(ipnet) & 0xFF;
lprint(NIP4_FMT"\n", array[], array[], array[], array[]);
lprint("%ld.%ld.%ld.%ld\n", ipnet & 0xff,
ipnet>> & 0xff,
ipnet>> & 0xff,
ipnet>> & 0xff);
lprint("************************************************************************\n");
return ;
}