-   Programming (
-   -   cannot open ethernet device (

lucky6969b 01-23-2006 03:47 AM

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");
str = (char *)malloc (10000);

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



lucky6969b 01-23-2006 04:00 AM

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?


pretty messy hey :)

Wim Sturkenboom 01-23-2006 05:52 AM

I've never tried to open a connection like that. Network programming examples

FLLinux 01-23-2006 11:38 AM

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.

lucky6969b 01-24-2006 01:47 AM

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?

Wim Sturkenboom 01-24-2006 06:12 AM


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.

All times are GMT -5. The time now is 01:30 PM.