c# raw socket ip header total length -
i using udp raw sockets.
i wish read first, example, 64 bytes of every packet.
ipaddr = ipaddress.parse( "10.1.2.3" ); sock = new socket(addressfamily.internetwork, sockettype.raw, protocoltype.ip); sock.bind(new ipendpoint(ipaddr, 0)); sock.setsocketoption(socketoptionlevel.ip, socketoptionname.headerincluded, true); sock.iocontrol(iocontrolcode.receiveall, bitconverter.getbytes(rcvall_iplevel), null); sock.receivebuffersize = 32768; byte[] buffer = new byte[64]; // max ip header, plus tcp/udp ports while (!btheend ) { int ret = sock.receive(buffer, buffer.length, socketflags.none); ... }
i receive packets, ip header' "total length" <= 64.
if use bigger buffer ( byte[] buffer = new byte[32768] ), got right "total length" ( value <= 32768 ).
the goal packets, ip header, corret packet length; routine doesn't have cause packet fragmentation tcp/ip stack.
socketflags.peek
means data returned left intact subsequent read - that's why same data after reading again. read subsequent packets don't want use peek, perform regular read no special flags.
according documentation:
if datagram receive larger size of buffer parameter, buffer gets filled first part of message, excess data lost , socketexception thrown.
is behavior you're after?
Comments
Post a Comment