allow size set
[tridge/junkcode.git] / alignsmb.c
1 #include <stdio.h>
2
3 typedef unsigned __u32;
4 typedef unsigned char __u8;
5 typedef unsigned short __u16;
6
7 #pragma pack(1)
8
9 # define offsetof(T,F) ((unsigned int)((char *)&((T *)0L)->F - (char *)0L))
10
11 struct smb_hdr {
12         __u32 smb_buf_length;   /* big endian on wire *//* BB length is only two or three bytes - with one or two byte type preceding it but that is always zero - we could mask the type byte off just in case BB */
13         __u8 Protocol[4];
14         __u8 Command;
15         union {
16                 struct {
17                         __u8 ErrorClass;
18                         __u8 Reserved;
19                         __u16 Error;    /* note: treated as little endian (le) on wire */
20                 } DosError;
21                 __u32 CifsError;        /* note: le */
22         } Status;
23         __u8 Flags;
24         __u16 Flags2;           /* note: le */
25         __u16 PidHigh;          /* note: le */
26         union {
27                 struct {
28                         __u32 SequenceNumber;  /* le */
29                         __u32 Reserved; /* zero */
30                 } Sequence;
31                 __u8 SecuritySignature[8];      /* le */
32         } Signature;
33         __u8 pad[2];
34         __u16 Tid;
35         __u16 Pid;              /* note: le */
36         __u16 Uid;
37         __u16 Mid;
38         __u8 WordCount;
39 };
40
41 struct smb_hdr h;
42
43 int main(void)
44 {
45         printf("size is %d\n", sizeof(h));
46
47         h.Status.CifsError = 3;
48
49         printf("error is at %d\n", offsetof(struct smb_hdr, Status.CifsError));
50
51         
52         h.Status.CifsError++;
53
54         printf("error is %d\n", h.Status.CifsError++);
55
56         return 0;
57 }