K
Kifah Abbad
This part finds the destination IP in a packet, and converts into a
string.
code:--------------------------------------------------------------------------------
char destination_IP[40]; //For saving destination IP
..
..
..
..
..
//save destination IP
sprintf(&Destination_IP_temp,"%d.%d.%d.%d",(vp->packet[30] &
0xff),(vp->packet[31] & 0xff),(vp->packet[32] & 0xff),(vp->packet[33]
& 0xff));
--------------------------------------------------------------------------------
Then i have a part for socket connection, that uses this IP in a
connect part:
code:--------------------------------------------------------------------------------
..
..
..
..
their_addr.sin_addr.s_addr = inet_addr(destination_IP);
memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the
struct
if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct
sockaddr)) == -1) {
perror("connect");
exit(1);
}
--------------------------------------------------------------------------------
But when i start proggie, it keeps exiting with error:
code:--------------------------------------------------------------------------------
connect: Invalid argument
--------------------------------------------------------------------------------
Although the ip gets printed out correctly when i try to debug with:
code:--------------------------------------------------------------------------------
printf("Destination %d.%d.%d.%d\n",
(vp->packet[30] & 0xff),
(vp->packet[31] & 0xff),
(vp->packet[32] & 0xff),
(vp->packet[33] & 0xff));
string.
code:--------------------------------------------------------------------------------
char destination_IP[40]; //For saving destination IP
..
..
..
..
..
//save destination IP
sprintf(&Destination_IP_temp,"%d.%d.%d.%d",(vp->packet[30] &
0xff),(vp->packet[31] & 0xff),(vp->packet[32] & 0xff),(vp->packet[33]
& 0xff));
--------------------------------------------------------------------------------
Then i have a part for socket connection, that uses this IP in a
connect part:
code:--------------------------------------------------------------------------------
..
..
..
..
their_addr.sin_addr.s_addr = inet_addr(destination_IP);
memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the
struct
if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct
sockaddr)) == -1) {
perror("connect");
exit(1);
}
--------------------------------------------------------------------------------
But when i start proggie, it keeps exiting with error:
code:--------------------------------------------------------------------------------
connect: Invalid argument
--------------------------------------------------------------------------------
Although the ip gets printed out correctly when i try to debug with:
code:--------------------------------------------------------------------------------
printf("Destination %d.%d.%d.%d\n",
(vp->packet[30] & 0xff),
(vp->packet[31] & 0xff),
(vp->packet[32] & 0xff),
(vp->packet[33] & 0xff));