Subject: [Sipping] sending structure over socket

From: [email-masked]
Date: Tue, 8 Feb 2005 17:23:33 +0530 (IST)

hi,

i want to send a structure over socket and receive it in a unsigned char
array, is it possible?

typedef struct {
       int a;
       char *name;
       int b;
} test;
test mystruct;

// i am initializing the members a,b,name to say, 100,"hai",200.

in sendto(), i am giving as :

n=sendto(sockfd, &mystruct, sizeof(mystruct), 0, (struct sockaddr
*)server, sizeof(server);

while receiving the structure in the server, i want to receive it in an
array as 100hai200

since the second arg of sendto and recvfrom are void*, can I receive it as
char

_______________________________________________
Sipping mailing list  https://www1.ietf.org/mailman/listinfo/sipping
This list is for NEW development of the application of SIP
Use [email-masked] for questions on current sip
Use [email-masked] for new developments of core SIP

---

From: Jim Reid <[email-masked]>
Date: Tue, 08 Feb 2005 12:42:17 +0000

>>>>> "suganya" == suganya  <[email-masked]> writes:

    suganya> i want to send a structure over socket and receive it in
    suganya> a unsigned char array, is it possible?

Of course it's possible. However it may not be sensible. You could run
into all sorts of portability problems: for example if the computers
at either end of the socket have different word sizes. Or character
sets. Or byte ordering.

You're asking naive questions that are inappropriate for this list. It's
not supposed to provide tutorials on DNS APIs and network programming.
I think you should go somewhere else to get this information. Read
W. Richard Stevens "Unix Network Programming". This'll teach you
everything you could ever want to know about using sockets. Snader's
"Effective TCP/IP Programming" is also very good, though not as
comprehensive as Stevens. I've already pointed you at a source for a
tutorial on the de facto standard DNS API.