view test/strinit.c @ 553:293f827ccfb2 linux-kernel-source

Linux kernel source compiled.
author kono
date Thu, 05 Jan 2006 21:29:55 +0900
parents df60b120675d
children c55b51d51f8f
line wrap: on
line source

#include <stdio.h>

int b[3] = {1,2,3};

struct temp {
   int a;
   int b;
   int c;
   int d;
    struct hoge {
	int k;
	int j;
    } m;
   int e;
} temp1 = {
//   101,
//   102,
//   103,
//   104,
//   105,
   .e = 5,
   .a = 3
};

struct temp temp3 = {
   .c = (int)&b,
   .d = -10,
   .a = (int)b
};

struct temp temp4 = { 1,2,3,4,5,6,7};
struct temp temp7 = { 1,2,3,4,{5,6},7};

#if 0
struct temp temp10 = {
   .m = (struct hoge){},    // not allowed in global
   .c = (int)&b,
};
#endif 

void
linux_kernel();

int
main()
{
    struct temp temp2 = { .c = 5, .e=99 };
#ifdef WRONG
    struct temp temp5 = { 1,2,3,4,5,6,7,8};
    struct temp temp6 = { 1,2,3,4,5,6};
#else
    struct temp temp5 = { 1,2,3,4,5,6,7};
    struct temp temp6 = { 1,2,3,4,5,6,7};
    struct temp temp8 = { 1,2,3,4,{5,6},7};
#endif
    struct temp temp11 = {
       .m = (struct hoge){},
       .c = (int)&b,
    };
    struct temp temp12 = {
       .m = (struct hoge){1,3},
       .c = (int)&temp4,
    };

    printf("#0064:1: %d\n",temp1.a);
    printf("#0065:1: %d\n",temp1.e);
    printf("#0066:1: %d\n",temp1.b);
    printf("#0067:2: %d\n",temp2.c);
    printf("#0068:2: %d\n",temp2.e);
    printf("#0069:2: %d\n",temp2.b);
    printf("#0070:2: %d\n",(void*)temp3.c==b);
    printf("#0071:2: %d\n",temp3.c==(int)b);
    printf("#0072:2: %d\n",temp3.a==(int)&b);
    printf("#0073:2: %d\n",temp4.m.j);
    printf("#0074:2: %d\n",temp5.m.j);
    printf("#0075:2: %d\n",temp11.m.j);
    printf("#0076:2: %d\n",temp12.m.k);
    printf("#0077:2: %d\n",temp12.m.j);
    printf("#0078:2: %d\n",temp11.c==(int)&b);
    linux_kernel();
    return 0;
}

typedef unsigned int __u32;
typedef unsigned short __u16;
typedef unsigned char __u8;
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
struct in6_addr { char hoge[128]; };

struct flowi {
        int oif;
        int iif;

        union {
                struct {
                        __u32 daddr;
                        __u32 saddr;
                        __u32 fwmark;
                        __u8 tos;
                        __u8 scope;
                } ip4_u;

                struct {
                        struct in6_addr daddr;
                        struct in6_addr saddr;
                        __u32 flowlabel;
                } ip6_u;

                struct {
                        __u16 daddr;
                        __u16 saddr;
                        __u32 fwmark;
                        __u8 scope;
                } dn_u;
        } nl_u;
        __u8 proto;
        __u8 flags;
        union {
                struct {
                        __u16 sport;
                        __u16 dport;
                } ports;

                struct {
                        __u8 type;
                        __u8 code__;
                } icmpt;

                struct {
                        __u16 sport;
                        __u16 dport;

                        __u8 objnum;
                        __u8 objnamel;
                        __u8 objname[16];
                } dnports;

                __u32 spi;
        } uli_u;
} __attribute__((__aligned__(32/8)));


static __inline__ __attribute__((always_inline)) __attribute__((always_inline)) 
int ip_route_connect(/* struct rtable **rp, */ u32 dst,
                                   u32 src, u32 tos, int oif, u8 protocol,
                                   u16 sport, u16 dport /*, struct sock *sk */)
{
        struct flowi fl = { .oif = oif,
                            .nl_u = { .ip4_u = { .daddr = dst,
                                                 .saddr = src,
                                                 .tos = tos } },
                            .proto = protocol,
                            .uli_u = { .ports =
                                       { .sport = sport,
                                         .dport = dport } } };

	printf("#0158:%d %d\n",fl.oif,fl.uli_u.ports.dport);
}

static 
int ip_route_connect0(/* struct rtable **rp, */ u32 dst,
                                   u32 src, u32 tos, int oif, u8 protocol,
                                   u16 sport, u16 dport /*, struct sock *sk */)
{
        struct flowi fl = { .oif = oif,
			    .iif = 55,
                            .nl_u = { .ip4_u = { .daddr = dst,
                                                 .saddr = 66,
                                                 .tos = tos } },
                            .proto = protocol,
                            .uli_u = { .ports =
                                       { .sport = sport,
                                         .dport = dport } } };

	printf("#0176:%d %d\n",fl.oif,fl.uli_u.ports.dport);
	printf("#0177:%d %d\n",fl.iif,fl.nl_u.ip4_u.saddr);
}

void
linux_kernel()
{
    ip_route_connect0(1,2,3,4,5,6,7);
    ip_route_connect(1,2,3,4,5,6,7);
    ip_route_connect(11,12,13,14,15,16,17);
}

// end