473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to effectively represent and Increase MAC address

Hi all,

I have a text file with a list of MAC addresses.
Each time, my program is called it reads the last MAC address entry
from the file, increases it by one, writes this new address into a 6
byte binary file and stores the new address in text representation in
the text file. Looks like this

00-0C-F1-B9-A1-11
00-0C-F1-B9-A1-12
00-0C-F1-B9-A1-13
....

My questions are:
1. How do I effectively read the last line of the file.
Right now, I read the whole file until I come to the last line. Not
very elegant but maybe the only quick way to do it?

2. How would you represent the MAC addresses in order to increase them?
I am reading them, ignoring the dashes between the bytes and convert
them with strtol into a 32 bit integer (where I should use 48 bits but
I assume that the first 16 bytes are not changed).
Then I increase this number and convert it back to chars. Sounds
horrible, doesn't it?
Is there a better way?

Thanks in advance,

Rainer Thaden

Oct 26 '06 #1
5 2758
RT*****@web.de wrote:
I have a text file with a list of MAC addresses.
Each time, my program is called it reads the last MAC address entry
from the file, increases it by one, writes this new address into a 6
byte binary file and stores the new address in text representation in
the text file. Looks like this

00-0C-F1-B9-A1-11
00-0C-F1-B9-A1-12
00-0C-F1-B9-A1-13
...

My questions are:
1. How do I effectively read the last line of the file.
Right now, I read the whole file until I come to the last line. Not
very elegant but maybe the only quick way to do it?
Use std::ifstream::seekg().
2. How would you represent the MAC addresses in order to increase them?
I am reading them, ignoring the dashes between the bytes and convert
them with strtol into a 32 bit integer (where I should use 48 bits but
I assume that the first 16 bytes are not changed).
Then I increase this number and convert it back to chars. Sounds
horrible, doesn't it?
Is there a better way?
I generally prefer std::stringstreams to C-style number conversions
(cf.
http://parashift.com/c++-faq-lite/mi....html#faq-39.1
and the FAQ following). You could do a lazy conversion where you
convert the least significant byte, add one, and if and only if there
is a carry, convert the next byte and add one to it. Continue
converting and adding as long as there is a carry.

Cheers! --M

Oct 26 '06 #2
VJ
RT*****@web.de wrote:
Hi all,

I have a text file with a list of MAC addresses.
Each time, my program is called it reads the last MAC address entry
from the file, increases it by one, writes this new address into a 6
byte binary file and stores the new address in text representation in
the text file. Looks like this

00-0C-F1-B9-A1-11
00-0C-F1-B9-A1-12
00-0C-F1-B9-A1-13
...

My questions are:
1. How do I effectively read the last line of the file.
Right now, I read the whole file until I come to the last line. Not
very elegant but maybe the only quick way to do it?

2. How would you represent the MAC addresses in order to increase them?
I am reading them, ignoring the dashes between the bytes and convert
them with strtol into a 32 bit integer (where I should use 48 bits but
I assume that the first 16 bytes are not changed).
Then I increase this number and convert it back to chars. Sounds
horrible, doesn't it?
Is there a better way?

Thanks in advance,

Rainer Thaden


Tried using istream:: seekg?

Here is a link for ifstream:
http://www.cplusplus.com/ref/iostream/ifstream/
Oct 26 '06 #3
I am reading them, ignoring the dashes between the bytes and convert
them with strtol into a 32 bit integer (where I should use 48 bits but
I assume that the first 16 bytes are not changed).
Then I increase this number and convert it back to chars. Sounds
horrible, doesn't it?
This way you'll get character not supported by MAC address. How are you
handling that?

Oct 27 '06 #4

VJ wrote:
RT*****@web.de wrote:
Hi all,

I have a text file with a list of MAC addresses.
Each time, my program is called it reads the last MAC address entry
from the file, increases it by one, writes this new address into a 6
byte binary file and stores the new address in text representation in
the text file. Looks like this

00-0C-F1-B9-A1-11
00-0C-F1-B9-A1-12
00-0C-F1-B9-A1-13
...

My questions are:
1. How do I effectively read the last line of the file.
Right now, I read the whole file until I come to the last line. Not
very elegant but maybe the only quick way to do it?

2. How would you represent the MAC addresses in order to increase them?
I am reading them, ignoring the dashes between the bytes and convert
them with strtol into a 32 bit integer (where I should use 48 bits but
I assume that the first 16 bytes are not changed).
Then I increase this number and convert it back to chars. Sounds
horrible, doesn't it?
Is there a better way?

Thanks in advance,

Rainer Thaden

Tried using istream:: seekg?

Here is a link for ifstream:
http://www.cplusplus.com/ref/iostream/ifstream/
Yes, I tried. But what do you seek for? The end of the file? And where
to put the position after finding it? Then, you need to make
assumptions over the length of a line. Bad, if you want to allow
comments in lines.

Best regards,

Rainer

Nov 2 '06 #5

Amit wrote:
I am reading them, ignoring the dashes between the bytes and convert
them with strtol into a 32 bit integer (where I should use 48 bits but
I assume that the first 16 bytes are not changed).
Then I increase this number and convert it back to chars. Sounds
horrible, doesn't it?
This way you'll get character not supported by MAC address. How are you
handling that?
No, I don't

If, e.g., the last byte of the MAC address is bf, then I convert the
chars 'bf' to the number bf, increase it to get c0, save it in a binary
file, convert it back to two chars 'c0' and save that in my text file.
I see no problem here.

Best regards,

Rainer

Nov 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: nvjoglekar | last post by:
Hi All My program needs a lot of memory and after allocating some using NEW statement, it returns NULL for any new object created. I guess that is becuase of the heap size limitation of the...
3
by: gary | last post by:
Hi, 1. About all C/C++ compilers, Does stack increase from high address to low address and heap grow increase from low to high? What on earth decides their increase direction, CPU architecture, OS...
22
by: Fred Ma | last post by:
I'm using the expression "int a = ceil( SomeDouble )". The man page says that ceil returns the smallest integer that is not less than SomeDouble, represented as a double. However, my...
3
by: akunal | last post by:
I'm trying to represent a linked relationship among between nodes as follows: <!-- Top level nodes --> <Cities> <City>Los Angeles</City> <City>San Francisco</City> <City>Seattle</City>...
4
by: Daniel | last post by:
is there some per-process-limit on memory in .net processes? is there any way to increase it? i keep getting System.OutOfMemoryException when my box has 8 gigs of unused memory.
16
by: Mikhail Kovalev | last post by:
Was reading an article the other day (now offline for some reason) which included some "new lines of code"-statistics, this is different, but shows the same trend: ...
10
by: Devang | last post by:
Hello, I am using php script to upload file. some times if file size is too big(1GB) it takes too much time to upload. Can someone suggest me the way to increase upload speed. thanks
8
by: Guy Macon | last post by:
How to increase web server uptime with DNS failover: For illustration, let's start with some really bad hosting... Find four free web hosts that are each 90% reliable -- in other words they...
3
by: James Harris | last post by:
Do you remember a previous discussion on this newsgroup as at http://groups.google.com/group/comp.lang.c/browse_frm/thread/cb502ce8414cea06/bb738c4f91113b4e It concerned code to manage a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.