[ee122] sockaddr_in and pointers.

Richard Schmidt huntingtonsurfca at gmail.com
Sat Sep 22 22:11:46 PDT 2007


The sockaddr_in struct doesn't like to be modified via a pointer.

I'm trying to modularize my code but this is preventing me from doing so.

prototype: char *clientParse(char*buff, struct sockaddr_in *serv, ...)
and calling it: sBuff = clientParse(inBuff, &serv_addr, &my_addr);

I dereference the pointer in the function like this:

serv->sin_family = AF_INET;

But when I try to bind the connection, using the serv_addr (in main), it
fails.

So I tried making local variables (in the function) and then:

memcpy(serv, &servAddr, sizeof(struct sockaddr_in)); (in function)

but this is still failing. Anyone else have an idea? I know this is the
reason why it is failing because I've had this problem before with it and I
found a workaround using memcpy() but that was in the same scope. I guess
that's why it didn't work across function calls.

Any ideas?
Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ICSI.Berkeley.EDU/pipermail/ee122/attachments/20070922/bd4facb2/attachment.html 


More information about the ee122 mailing list