LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2005, 10:06 PM   #1
Elric of Grans
Member
 
Registered: May 2005
Posts: 46

Rep: Reputation: 15
Adding Ethernet communication


G'Day,

I came across a library a little while ago which provided some useful features for a project I am working on --- it would save a few days work, and a lot of bug testing, so you can see why I want to use it --- but it relies on serial communication, whereas I want to so everything via ethernet (because the serial port is already tied up). I would imagine adding ethernet support to these functions would be relatively simple, but I am a little stuck here.

I searched this forum the other day, and came up with libpcap, which sounded nice, however, as I get deeper into it, I get the feeling it is not quite what I need. While libpcap has some nice features for reading packets, what I want is simple receive and transmit of data between two systems: libpcap seems to have more than I need for receive, and does not seem to support transmit.

Obviously there would be something already out there (likely a heck of a lot simpler than I am thinking too), but I am a little stuck now as to what I need to do. If I could be directed to any HOWTOs or other guides which explain how to use ethernet in a C program, I would be really grateful.

Thanks!
 
Old 12-13-2005, 04:26 PM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Hello.

as you have found, libpcap is pretty much just for sniffing packets on the wire. I am not sure how low-level you want to get, but I would start with "man socket" which will describe how to open a file-like descriptor to read or write data over the wire.

Here is a short tutorial to get you going:
http://www.linuxgazette.com/issue47/bueno.html

google "socket programming C linux" for more...
 
Old 12-14-2005, 04:10 PM   #3
Elric of Grans
Member
 
Registered: May 2005
Posts: 46

Original Poster
Rep: Reputation: 15
That seems to be what I was after! Thanks for your time
 
Old 12-15-2005, 05:00 PM   #4
Elric of Grans
Member
 
Registered: May 2005
Posts: 46

Original Poster
Rep: Reputation: 15
I have made use of this document to extend the library I had found, and everything works fine, except for one point I had not thought about before it happened. If enough clients connect to the server, further connections will be refused --- which makes sense --- but what about if all the currently connected clients have used close(fd)? How do I know when the server should close() the socket returned by accept(), and therefore be prepared to accept() future connections? Is there a simple way to know that the client has disconnected, or should there be some protocol whereby the client says "bye" before they call close()? I have thought about time outs, which would not be a bad idea to add, but there should surely be a cleaner option for when the client leaves like this.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Communication via lan paulmedic555 Linux - Networking 1 11-03-2004 05:34 PM
Adding a second Ethernet Card DiBosco Linux - Networking 8 06-04-2004 09:22 AM
adding a third ethernet card.. murphaph Linux - Networking 7 04-10-2004 05:50 PM
communication redirection chtthies Linux - Networking 1 12-08-2003 10:49 AM
communication redirection chtthies Linux - Newbie 1 11-11-2003 08:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration