LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 01-23-2006, 02:47 AM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
cannot open ethernet device


I'm simulating a client/server environment
Here is the error "can't open ethernet device"
It is supposed to be the simpliest. How come it doesn't work?

#define ETHERNET_DEVICE "/dev/eth0"

void main()
{
// char *str = "hello LAN\n";
char *str;
char *filenametosave = "/root/hello.txt";
FILE *filetosave;

FILE *fp;
int bytes_read = 0;
fp = fopen (ETHERNET_DEVICE, "r");
if (fp == NULL)
{
fprintf (stderr, "can't open ethernet device\n");
exit (-1);
}


filetosave = fopen (filenametosave, "w");
if (filetosave == NULL)
{
fclose (fp);
fprintf (stderr, "can't open database\n");
exit(-1);
}
str = (char *)malloc (10000);

for (;bytes_read == 0 {
bytes_read = fread (str, 10000, 1, fp);
printf ("Waiting for data...\n");
usleep(10000);
}
fwrite (str,1, strlen(str), filetosave);
fclose (fp);
fclose (filetosave);

}



Thanks
Jack
 
Old 01-23-2006, 03:00 AM   #2
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Sorry about it. I did not find eth0 in that dir.
But there were several eth0 scattered around different places.
Which one should I use?

./proc/irq/10/eth0
./proc/sys/net/ipv6/conf/eth0
./proc/sys/net/ipv6/neigh/eth0
./proc/sys/net/ipv4/conf/eth0
./proc/sys/net/ipv4/neigh/eth0
./proc/net/dev/snmp6/eth0
./sys/class/net/eth0

pretty messy hey
Thanks
Jack
 
Old 01-23-2006, 04:52 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I've never tried to open a connection like that. Network programming examples
 
Old 01-23-2006, 10:38 AM   #4
FLLinux
Member
 
Registered: Jul 2004
Location: USA
Distribution: Fedora 9, LFS 6.3, Unbuntu 8.04, Slax 6.0.7
Posts: 145

Rep: Reputation: 15
Lucky, An ethernet device does not act like a standard I/O device. It does not use open and read. you have to use sockets. I would suggest getting Linux Socket Programming by example. It is a good book to learn the basic socket interface.
 
Old 01-24-2006, 12:47 AM   #5
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
But I learned from school that all devices on L/UNIX behave like files
I think "connect" ultimately would call open ("dev/eth0, ?)
Am I right or not?
Thanks
Jack
 
Old 01-24-2006, 05:12 AM   #6
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by lucky6969b
But I learned from school that all devices on L/UNIX behave like files
Once you have a socket open, it behaves the same as a filedescriptor. So you can use read and write (although there are different functions available).

I think that that's where the confusion comes from.
 
  


Reply

Tags
example, network, programming


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
HELP- ethernet device not working correctly vdo Linux - Hardware 1 08-24-2005 10:25 AM
Failed to open device /dev/usb/ttyUSB0: No such device efm Linux - Newbie 2 04-04-2005 08:46 PM
Can't open USSP device. No such device (19). triona Linux - Software 0 02-04-2005 02:21 AM
Ethernet Device Installation? MainBrain Linux - Networking 1 10-10-2004 05:58 AM
loop: can't open device /dev/loop0: No such device or address miaviator278 Linux - Security 3 06-09-2004 09:24 PM


All times are GMT -5. The time now is 07:37 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration