/* SPDX-License-Identifier: GPL-2.0-or-later */ #include "wire.h" #include #include #include int main(void){struct sockaddr_ipx s={.sipx_family=AF_IPX,.sipx_network=htonl(0x12345678),.sipx_port=htons(0x4001),.sipx_node={2,3,4,5,6,7}},d={.sipx_family=AF_IPX,.sipx_network=htonl(0x11223344),.sipx_port=htons(0x451),.sipx_node={0,0,0,0,0,1},.sipx_type=17};uint8_t p[8192],f[1514],data[]={0x11,0x11,0x22,0x33};int n=ipx_make(p,sizeof p,&s,&d,data,sizeof data);assert(n==34);assert(get32(p+6)==0x11223344&&get32(p+18)==0x12345678&&get16(p+16)==0x451&&get16(p+28)==0x4001&&p[5]==17); int kinds[]={IPX_FRAME_ETHERII,IPX_FRAME_8023,IPX_FRAME_8022,IPX_FRAME_SNAP};for(unsigned i=0;i<4;i++){int l=frame_encode(f,sizeof f,kinds[i],d.sipx_node,s.sipx_node,p,n);assert(l==60);int k;size_t z;const uint8_t *r;assert(!frame_decode(f,l,&k,&r,&z));assert(k==kinds[i]&&z==(size_t)n&&!memcmp(r,p,n));for(int x=0;x<14;x++)assert(frame_decode(f,x,&k,&r,&z)<0);size_t off=r-f;f[off+2]=0;f[off+3]=0;assert(frame_decode(f,l,&k,&r,&z)<0);assert(frame_encode(f,sizeof f,kinds[i],d.sipx_node,s.sipx_node,p,n)>0);f[off+4]=16;assert(frame_decode(f,l,&k,&r,&z)<0);assert(frame_encode(f,sizeof f,kinds[i],d.sipx_node,s.sipx_node,p,n)>0);assert(frame_decode(f,off+n-1,&k,&r,&z)<0);} memset(data,0,sizeof data);uint8_t big[1470]={0};n=ipx_make(p,sizeof p,&s,&d,big,sizeof big);assert(n==1500);assert(frame_encode(f,sizeof f,IPX_FRAME_ETHERII,d.sipx_node,s.sipx_node,p,n)==1514);assert(frame_encode(f,sizeof f,IPX_FRAME_SNAP,d.sipx_node,s.sipx_node,p,n)<0);puts("PASS: 4 frame types, addresses, padding, lengths, malformed frames and MTU");return 0;}