Okay so let me see if i understand you correctly. I have two classes. Class A and Class B. I give class A 5 properties int prop1(){} int prop2(){} int prop3(){} int prop4(){} classB prop5(){} what i would like to do is to create a 5th property and make its type equal to ClassB. but i would also like to index this property too. BTW Class B also has some properties to it. So in the end i would be able to access my items like this: classA xyz = new classA(); xyz.prop1=1; xyz.prop2=2; xyz.prop3=3; xyz.prop4=4; xyz.prop5[0].prop1=1; xyz.prop5[0].prop2=2; xyz.prop5[1].prop1=1; xyz.prop5[1].prop2=2; I remember doing stuff like this a while ago in VB6 but i'm pretty new to C# and i'm just learning out to do this sort of stuff. I hope that explain helps a little bit more. I think i understand what your saying though.
mmatteson
Posts
-
make a class property an array of an instantiated class? -
make a class property an array of an instantiated class?hey thanks for the reply. yea sorry i wasn't too clear as it was a post right as i was leaving work today. i think i understand what you mean and i will give it a try! thanks
-
make a class property an array of an instantiated class?v9ExportPacket p = new v9ExportPacket(); p.TemplateRecord = new TemplateRecord[5]; TemplateRecord t_tmp = new TemplateRecord(); t_tmp.FlowSetID=0; t_tmp.Length=10; t_tmp.id=23; t_tmp.FieldCount=4; t_tmp.Fields= new FieldPairs[t_tmp.FieldCount]; t_tmp.Fields[0] = new FieldPairs(1,2); t_tmp.Fields[1] = new FieldPairs(3,4); t_tmp.Fields[2] = new FieldPairs(5,6); t_tmp.Fields[3] = new FieldPairs(7,8); p.TemplateRecord[0] = t_tmp; i was wondering if there is a way that i could just use p.TemplateRecord[0].id=1; instead of having to create a TemplateRecord object t_tmp to set the properties of that class and then set the TemplateRecord[0] property object equal to t_tmp object. i have looked into using indexers but i haven't seen an example where you could access a property of an indexed property.
-
Why is the binary number flipped when reading from a byte array?I am reading UDP packets that a router is sending to me. In this example i am reading the "system uptime" field which starts at bit position 64 from the begining of the packet and is a 32 bit field. So the end of the field is calculated to end at 95. I know that the first byte of this two bit field prints to the console 69 when i Console.WriteLine(buffer[8]). When I do a Convert.ToString(buffer[8],2) I get 101000101 printed on the console. I converted this byte to a decimal number. unfortunatly this is revered! and is being counted LEFT to RIGHT! When the binary numbers should start from Right to left. the real binary number of 69 is 01000101. which is the mirror opposite of what the console printed. Do you have any idea why this is? Here is the code that I am looking at. public static uint Parse(byte[] datagram, int offset, int length) { uint total = 0; int byte_index; int bit_offset; int bit; byte b; for ( int i = 0; i < length; i++ ) { bit_offset = (offset+i) % 8; byte_index = (offset+i-bit_offset) / 8; b = datagram[byte_index]; //Writing the datagram to the console and performing the Convert.ToString is where i notice this. bit = (int)(b >> (7 - bit_offset)); bit = bit & 0x0001; if ( bit > 0 ) { total += (uint)Math.Pow(2,length-i-1); } } return total; } Is this why there is the shift right and then the AND to somehow fix this issue?
-
is a byte array an octal number ?when i'm looking at a value and using console.writeline(byte[0]); to print the output of a network stream. i am getting a 69 printed to the screen. is this an octal number or the binary number 69? 01000101?
-
reading network binary data from LEFT or RIGHT?When i first started to learn about the binary system i always ended up learning that to count in binary you work from right to left. 128,64,32,16,8,4,2,1. But while looking at the Netflow packet 9 format from cisco. (http://www.cisco.com/en/US/tech/tk648/tk362/technologies\_white\_paper09186a00800a3db9.shtml) it shows the field bit positions starting from left to right. [0,1,2,3,4,5,6,7]. how to I align up those bit values? does bit position 7 have a value of 1, or 128? or does this not matter since i am reading my data from a byte array and then i could just use the convert.tostring(2,byte) to view the binary data and the resulting string would be in the format of 128,64,32,16,8,4,2,1? thanks. hopefully i'll figure this out soon so i can get to sleep before 3am like last night!!
-
socket.beginrecieve method for UDP. find out who sent you the data?Is there anyway when using the beginrecieve method for a socket bounded to listen on a udp port to find out who is sending the data (remote ip address)?
-
bit operations question for binary>decimalhey thanks a lot. this is helpful
-
bit operations question for binary>decimali just started a socket application that recieves UDP data. The data that i am recieving is a netflow packet from cisco devices. to learn how to do this i have been searching the forums and looking at other people's code for reference. some code that i came across was the following. pretty much what you do is, passed a byte[2048] to the procedure ToUInt and specify the starting point to get the datafield in the byte and the length from that starting position to get. the first field in the packet is the version field which starts at position 0 and is 16 bits long. so you would end up passing to the following code the byte[2048] of your data buffer, 0 for your offset and 16 for your length. i understand mostly all of the code except that part there the Shift Right occurs and the ANDing against 0x0001. b is 10, and then after the bitwise operations is it 5. which is the correct version number for the netflow packet that my application recieved. public static uint ToUInt(byte[] datagram, int offset, int length) { uint total = 0; int byte_index; int bit_offset; int bit; byte b; for ( int i = 0; i < length; i++ ) { bit_offset = (offset+i) % 8; byte_index = (offset+i-bit_offset) / 8; b = datagram[byte_index]; bit = (int)(b >> (7 - bit_offset)); bit = bit & 0x0001; if ( bit > 0 ) { total += (uint)Math.Pow(2,length-i-1); } } return total; } i modified the code to print to a console the values of each variable during each iteration of the loop. here are the values. i bit_offset byte_index b bit total 0 0 0 0 0 0 1 1 0 0 0 0 2 2 0 0 0 0 3 3 0 0 0 0 4 4 0 0 0 0 5 5 0 0 0 0 6 6 0 0 0 0 7 7 0 0 0 0 8 0 1 5 0 0 9 1 1 5 0 0 10 2 1 5 0 0 11 3 1 5 0 0 12 4 1 5 0 0 13 5 1 5 1 4 14 6 1 5 0 4 15 7 1 5 0 5 i relize that the byte_index is just a counter for how many bits you have iterated through. once you went through 8 bits, incriment the byte index by 1. since the length is 16, that is two bytes and that would account for 0, and 1. i is just the counter set to the length of 16. i don't understand the B, bit, and total values. could someone explain the logic behind this to me?
-
listening for Dgrams. need to parse IP header?nevermind. i used BytesReceived = so2.EndReceive(ar); System.Console.WriteLine("Bytes Received:" + BytesReceived); and then matched up that number with the data bytes field in the UDP packet in ethereal. i think i made the logical assumption that bytes received: 282 and the length of the data in the udp packet in ethereal is 282 that its one in the same..
-
listening for Dgrams. need to parse IP header?I was wondering if you are creating a socket by using this code: Socket socket_ = new Socket(AddressFamily.InterNetwork,SocketType.Dgram,ProtocolType.Udp); what sort of data will you receive? will you get only the UDP portion of the IP packet? or will you get all ip packets with the upperprotocol matching UDP on the port you specified in your IPEndPoint? I'm trying to figure out where i go next in my code. if i need to write code to parse out the udp datagram from the ip packet or the data from the udp datagram. thanks!
-
what would the best way to approach this project be?well this is my first post on codeproject, first of all thanks too all that have posted so many good articles in the past that has helped me out greatly. anyways down to the question. i was to create an application that will recieved Cisco Netflow packets (http://www.cisco.com/en/US/tech/tk648/tk362/technologies\_white\_paper09186a00800a3db9.shtml) and then parse out the data. store the data and then use RRDTool to create pretty little graphs. I have never done socket programming before or really know where to start. If i can aquire the individual pieces of data in those fields then i can dump it to txt files or a database or w/e i please :). i'm pretty sure that i don't want to use raw sockets, and that i want to impliment a socket in the tcp/ip stack itself. I'm relitivily sure i can get the raw data itself, but from there i don't know how to turn the string of jibberish i would get into english. does anyone have any ideas? i'm not asking for a free hand out of code, but just to be pointed in the right direction. thanks.