ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi I want to make 2 processes communicate using sockets... I want to transfer a structure with its data.. I am a little if this is possible because everything example i read send single characters and not integers and longs that i want to send...
It works the same, you call send() on one side and pass in the address of the structure along with its length, and you receive the same number of bytes on the other end.
In general you need to be careful that both sides agree on the size of an integer/long etc., and also agree on packing as well as byte endian. This is not a problem if you compile and run both processes on the same computer and never on 2 different computers.
Thx i have searched a little and i have also found this one
Unix Network Programming: The Sockets Networking Api
Stevens, W.Richard, Fenner, Bill, Rudoff, Andrew M.
Do u know which one is better?
The two are just different editions of the same book. The Stevens, Fenner, Rudoff version you mention (the 3rd Edition of UNP) is the later edition - it's the one I'd recommend. The last version Stevens himself was able to complete (before his untimely death) was the 2nd edition - it's the one I own.
Satisfaction guaranteed! It's really in indispensible book!
I have one more question.. I am trying to pass a socket...
I think i have succesfully make it work
if (sendto( sock, &ds_stats, bufsiz, 0, (struct sockaddr *) &server, server_len) <0){
The struct is declared as struct mystruct ds_stats[10]
I have noticed that when i was using the sendto system call with if (sendto( sock, &ds_stats[10], bufsiz, 0, (struct sockaddr *) &server, server_len) <0){
I couldnt receive the correct values.. So can u explain me the difference betweern &ds_stats[10] and &ds_stats
Thx a lot
hi,
seems to me you are using some junk memory location. you have declared ds_stats[10], which means you can access ds_stats[0] to ds_stats[9] in C/C++. But you are using ds_stats[10] which has some junk contains.
It turns out if you declare a structure ds_stats[10], that the three will all have the same value
ds_stats
&ds_stats[0]
&ds_stats
the last one however is improper (but works) because ds_stats is already a pointer and does not have an address.
<= uh... what do you mean "trying to pass a socket???""
I hope you mean "I'm trying to send some data".
I hope you *don't* mean that you're somehow trying to pass the socket itself to another process!!!!
Quote:
So the declaration ds_stats[10] dont means 10 structures...?
<= Yes, that's *exactly* what it means.
"mystruct ds_stats[10]" declares an array of exactly 10 items of "mystruct".
Quote:
&ds_stats[10]
<= Unfortunately, this takes the address of the *11th* element of your 10 element array.
It's almost certainly *not* what you want.
This is the error mehuljv was trying to point out.
Quote:
&ds_statis[0]
<= This takes the address of the *first* element.
It is probably what you meant to do.
Please buy the Stevens book and work through some of the examples before you go too much further in this project. I assure you, you'll be much happier and much more productive!
And please, if you haven't already done so, look for an SNMP library that you can use. Please do *not* try to "roll your own" SNMP library (if that's indeed what you're doing...) As sundialsvcs says below, you do *NOT* want to re-invent the wheel!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.