R
RThaden
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
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