Am Montag, 24. Oktober 2005 19:36 schrieb John Heffner:
> > Unfortunately I never get to the point "connection not found" -- it looks
> > like I'm stuck in an infinite loop ...
>
> That's what I get for just typing in code and not trying it out. :)
>
> The while loop needs a conn = web100_connectoin_next(conn); at the end.
Great, that thing was missing. And I found another crucial error in my code. I
shouldn't manipulate the host byte order of the addresses, so when I set the
spec values, I should write:
inet_aton(LocalAddress, &src_t);
spec->src_addr = src_t.s_addr;
inet_aton(RemoteAddress, &dst_t);
spec->dst_addr = dst_t.s_addr;
spec->src_port = LocalPort;
spec->dst_port = RemotePort;
instead of using the ntohl() function ...
So finally I get the CID *yippiieee* :-)
Here is the code snippet for the archive:
-------------------------8<--------------------------
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <pthread.h>
#include "web100.h"
#include "web100-int.h"
const unsigned int LocalPort = 0;
const char LocalAddress[13] = "141.3.17.217";
const unsigned int RemotePort = 1980;
const char RemoteAddress[15] = "84.163.232.249";
int main(int argc, char *argv[]) {
web100_agent *agent;
web100_connection *conn;
struct web100_connection_spec *spec, *spec2;
int cid = -1;
struct in_addr src_t, dst_t;
spec = (struct web100_connection_spec*) malloc(sizeof(struct
web100_connection_spec));
spec2 = (struct web100_connection_spec*) malloc(sizeof(struct
web100_connection_spec));
if((agent = web100_attach(WEB100_AGENT_TYPE_LOCAL, NULL)) == NULL) {
web100_perror("web100_attach");
exit(EXIT_FAILURE);
}
inet_aton(LocalAddress, &src_t);
spec->src_addr = src_t.s_addr;
inet_aton(RemoteAddress, &dst_t);
spec->dst_addr = dst_t.s_addr;
spec->src_port = LocalPort;
spec->dst_port = RemotePort;
conn = web100_connection_head(agent);
while(conn) {
web100_get_connection_spec(conn, spec2);
if (spec->src_addr == spec2->src_addr &&
spec->dst_addr == spec2->dst_addr &&
spec->dst_port == spec2->dst_port)
break;
conn = web100_connection_next(conn);
}
if(conn == NULL) {
printf("connection not found\n");
return 1;
}
cid = web100_get_connection_cid(conn);
printf("Connection ID: %i\n", cid);
/*
* Instead of using a local int cid, one could use
* conn->cid directly.
*/
return 0;
}
-------------------------8<--------------------------
Further steps include to read the parameters for addresses and ports from a
file and write a separate function to retrieve the CID.
Now I can go on to get the real work done and read the wanted variables
periodically into a log file. :-)
Thank you very much, John.
Martin
_______________________________________________
Discussion mailing list
Discussion@xxxxxxxxxx
http://internal.web100.org/mailman/listinfo/discussion
|