|
Do they have to be legal ip addresses?
And since an ip address can be represented by a single 32bit number wouldn't rand() work?
Here is one structure that windows uses to store ip addresses you can find it in the MSDN help:
struct in_addr {
union {
struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { u_short s_w1,s_w2; } S_un_w;
u_long S_addr;
} S_un;
};
So the code is simple:
in_addr address;
address.S_addr = rand();
John
|
|
|
|
|
All you have to do is generate a number between 0 and 255, once for each octet.
unsigned char s[16];
sprintf(s, "%u.%u.%u.%u",
rand() % 256,
rand() % 256,
rand() % 256,
rand() % 256);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
if you need it into a bind() call, use ADDR_ANY.
TOXCCT >>> GEII power
|
|
|
|
|
I think I'd want to know why.
Is there a legitimate reason for doing this?
Paul
|
|
|
|
|
hello everybody... using vc6/MFC how can i grab highlighted (selected) text from the current screen? Sorta like firing up a spell checker from the task bar to fetch selected word(s). All helpful suggestions appreciated! Thanks!
tom
|
|
|
|
|
This is from the PushSource filter example for DirectShow:
int cbFileHeader = sizeof(BITMAPFILEHEADER);
// Store the size of the BITMAPINFO
BITMAPFILEHEADER *pBm = (BITMAPFILEHEADER*)m_pFile;
m_cbBitmapInfo = pBm->bfOffBits - cbFileHeader;
I'm not quite sure why "bfOffbits - cbFileHeader" is done.. bfOffbits tells you where the actual picture information starts right? So if you subtracted that offset by the header wouldn't you end up with 0?
|
|
|
|
|
When you set a breakpoint on the m_cbBitmapInfo = pBm->bfOffBits - cbFileHeader statement, what are the values of the three variables? In some test code that I had lying around, the value of bfOffBits was 54, so subtracting 14 from that yielded 40.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Because an image is comprised of the following
a header and then the bitmap info
i.e.
a BITMAPFILEHEADER
a BITMAPINFO
then data in 3 tuples RGB RGB RGB RGB etc (for 24 bit)
So the offset must be the addition of the sizes of the header and the info structure.
Regards,
Axe
|
|
|
|
|
The BITMAPINFO consists of a BITMAPINFOHEADER followed by a number of RGBQUAD structures. bfOffBits tells you where in the image the actual image bits start.
The line is computing how big the BITMAPINFO is - the size of the BITMAPINFOHEADER plus the size of the colour table.
The actual layout of a bitmap file is:BITMAPFILEHEADER BITMAPINFOHEADER - One
RGBQUAD for every colour in the colour table - Bitmap bits
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi, I want to sort the contents of a CObList which contains CString objects. Being more experienced in C rather than C++, I immediately thought that qsort() would be the way to go.
However, I now realise that I don't know how to organise the compare routine, as I assume that it is supplied with POSITION elements, but don't know how to access the array from within the routine to compare the CStrings. Is qsort() the way to go with CObList, or is there a better way ? If qsort() is the way, how do I access the CStrings ? Thanks in advance !
Doug
|
|
|
|
|
See this article.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I have an IP Address in CString format
i need it in the BYTE format below.
//BYTE localIp[] = {127,0,0,1};
could anyone show me how to do this?
Thanks
|
|
|
|
|
CString str("127.0.0.1");
struct in_addr ia;
ia.S_addr = inet_addr(str);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hey,
i am familar with that
its a cstring to a byte[] im looking to do
|
|
|
|
|
ooops, sory, i didn't see either it was a CString... (and i didn't see David's posts 'cause i was writing mine).
well, by passing it to the function, just cast it before with the (LPCTSTR) operator defined in CString.
TOXCCT >>> GEII power
|
|
|
|
|
maybe a standard fonction does this (inet_addr() i think, but i don't remember), the folowing works fine, even if it can seem "heavy" :
<font style="color:blue;">#include</font> <stdlib.h> <font style="color:green;">
<font style="color:blue;">#include</font> <ctype.h> <font style="color:green;">
<font style="color:blue;">#include</font> <string.h> <font style="color:green;">
<font style="color:blue;">enum </font>IPValidate {
IP_ERR = 0,
IP_OK = 1
};
<font style="color:blue;">int</font> str2bytesIPAddr (<font style="color:blue;">char </font>pcDestTab[], <font style="color:blue;">const char</font>* pcIPAddr) {
<font style="color:green;">
</font>
<font style="color:blue;">int </font>iCptCharIntoIPAddr = 0;
<font style="color:blue;">int </font>iCptCharIntoByte = 0;
<font style="color:blue;">int </font>iResult = IP_OK;
<font style="color:blue;">short </font>sNbBytes = 0;
<font style="color:blue;">char </font>pstrByte[16];<font style="color:green;">
</font>
<font style="color:blue;">if </font>(strlen(pcIPAddr) > 15) {<font style="color:green;">
</font> iResult = IP_ERR;
}
<font style="color:blue;">else </font>{
<font style="color:blue;">do </font>{
<font style="color:blue;">if </font>(isdigit(pcIPAddr[iCptCharIntoIPAddr])) {
<font style="color:green;">
<font style="color:blue;">if </font>((iCptCharIntoByte == 0) && (pcIPAddr[iCptCharIntoIPAddr] == '0') && (isdigit(pcIPAddr[iCptCharIntoIPAddr+1]))) {
iResult = IP_ERR;
}
<font style="color:blue;">else </font>{
pstrByte[iCptCharIntoByte] = pcIPAddr[iCptCharIntoIPAddr];
iCptCharIntoIPAddr++;
iCptCharIntoByte++;
}
}
<font style="color:blue;">else </font>{
<font style="color:blue;">if </font>(pcIPAddr[iCptCharIntoIPAddr] == '.') {
<font style="color:green;">
</font>
pstrByte[iCptCharIntoByte] = '\0';
iCptCharIntoByte = 0;
iCptCharIntoIPAddr++;
pcDestTab[sNbBytes] = atoi(pstrByte);
sNbBytes++;
<font style="color:blue;">if </font>((atoi(pstrByte) > 255) || (atoi(pstrByte) < 0)) {
<font style="color:green;">
iResult = IP_ERR;
}
}
<font style="color:blue;">else </font>{
<font style="color:green;">
iResult = IP_ERR;
}
}
} <font style="color:blue;">while </font>((pcIPAddr[iCptCharIntoIPAddr] != '\0') && (sNbBytes <= 3) && (iResult == IP_OK));
<font style="color:blue;">if </font>((pcIPAddr[iCptCharIntoIPAddr] == '\0') && (sNbBytes <= 3) && (iResult == IP_OK)) {
pstrByte[iCptCharIntoByte] = '\0';
pcDestTab[sNbBytes] = atoi(pstrByte);
sNbBytes++;
<font style="color:blue;">if </font>((atoi(pstrByte) > 255) || (atoi(pstrByte) < 0)) {
iResult = IP_ERR;
}
}
<font style="color:green;">
</font>
<font style="color:blue;">if </font>(sNbBytes != 4) {
iResult = IP_ERR;
}
}
<font style="color:blue;">return </font>iResult;
}
TOXCCT >>> GEII power
|
|
|
|
|
cheers guys
tis working
struct in_addr ia;
ia.s_addr = inet_addr(strAdapterInfo);
BYTE localIp[3];
localIp[0] = ia.S_un.S_un_b.s_b1;
localIp[1] = ia.S_un.S_un_b.s_b2;
localIp[2] = ia.S_un.S_un_b.s_b3;
localIp[3] = ia.S_un.S_un_b.s_b4;
Thanks again
|
|
|
|
|
i forgot to say (if it was interresting you) that it was previously a isIPAddr() that i added two lines (twice the following : pcDestTab[sNbBytes] = atoi(pstrByte); ).
i hope that can be helpful to understand the way an IP Address is analysed, and so on.
TOXCCT >>> GEII power
|
|
|
|
|
Hi
I Hope this will work
1.
CString str = "127,0,0,1";
int length = str .GetLength();
BYTE localIp[length] ;
memcpy(localIp,str,length);
or do it
for(int i = 0;i
|
|
|
|
|
ah ah ahh,
do you just know what is an IP ?
what you are suggesting will do so : ['1', '2', '7', '.', '0', '.', '.', '1']
that's not what we want.
a coded IP Address is coded on 4 bytes, which represent each blocks of values.
it will be either : [0x7F, 0x00, 0x00, 0x01].
TOXCCT >>> GEII power
|
|
|
|
|
Hi
I want to initialize this struct
struct CATEGORY_CODES
{
CString strCategoryCode;
int nCategoryID;
CString strCategoryName;
int nHasSubCategory;
int nActive;
};
if i do CATEGORY_CODE stCatCode = {0};
I get the Fatal error on CString members if i try to insert the values init.
Can anybody help me how to intialize the structures in MFC
thanks
shailesh
|
|
|
|
|
it is not an MFC problem, it is a simple C rule !
if you write {0} , the compiler wont accept for such strusture because it doesn't contain only one member (an such member cannot be stored with a 0 ).
you have two possibilities :
first one :
<font style="color:purple;">CATEGORY_CODE </font>stCatCode = {
<font style="color:gray;">""</font>,
0,
<font style="color:gray;">""</font>,
0,
0
}; <font style="color:green;">
with a GNU compiler, you could also write :
<font style="color:purple;">CATEGORY_CODE </font>stCatCode = {
strCategoryCode: <font style="color:gray;">""</font>,
nCategoryID: 0,
strCategoryName: <font style="color:gray;">""</font>,
nHasSubCategory: 0,
nActive: 0
};
second one :
<font style="color:purple;">CATEGORY_CODE </font>stCatCode;
stCatCode.strCategoryCode = <font style="color:gray;">""</font>;
stCatCode.nCategoryID = 0;
stCatCode.strCategoryName = <font style="color:gray;">""</font>;
stCatCode.nHasSubCategory = 0;
stCatCode.nActive = 0;
is that ok for you ?
TOXCCT >>> GEII power
|
|
|
|
|
Give it a constructor that initializes the variables.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
I am attempting to save data to a MatLab .mat file from Visual C++. I know how to use matPutVariable to do this in the standard way, but I would like to be able to save this data incrementally without allocating the full mxArray, because the size of the array would be so large as to cause a memory shortage.
Analogously, if I were writing this data to a text file, I would open the text file in append mode and print each datum to the end of the file as it's calculated. Is there a way to do this when saving to a .mat file?
|
|
|
|
|
Hello gurus
well actually i am looking for a data structure or something like that for fast access to data. Actually my problem is that i have this image file dimensions size is 200 X 200 and what actually i want to do with the image is extract exhaustively 20X20 parts and make some calcualtions on that window from the image and store them. At present i am storing each 20X20 window in a vector object actually this takes a lot time when i want to retrieve the window and make calculations is there some way i can store this 20X20 window somewhere in the memory my point is fast access where i retrieve the values please help
Regards
Ahmed Ajmal
|
|
|
|