[uClinux-dev] How to get information about Interface

Ashish Kumar Batwara ashishkb at mindtree.com
Sun Nov 11 05:51:49 EST 2001


Hi Thanks for your reply.
How can i get the last_change attribute of the inteface?

Regards
Ashish

-----Original Message-----
From: Tom Walsh [mailto:tom at cyberiansoftware.com]
Sent: Sunday, November 11, 2001 2:37 PM
To: uclinux-dev at geekcreek.net
Subject: Re: [uClinux-dev] How to get information about Interface


Ashish Kumar Batwara wrote:
> 
> Hi,
> Could anyone help me out in getting the baud rate and the last change for a
> particular interface on Linux 2.0.38. Which structure i have to use to get
> that information? For other interface information, i am usind "struct
> ifreq"...
> As i am not findinf "struct if_data" on linux 2.0.38, which is having info
> about baud rate and last change...
> 

Use tcgetattr, then use cfgetispeed (see: "man tcgetattr" and "man
cfgetispeed").  The code fragment below should get you started on the
right path...



=====================================================================
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <limits.h>
#include "timeclock.h"

extern char * SerialPortName;

static struct termios SerialOptions, OldSerialOptions;
static FILE	* SerialPort;
static int	SerialPortNo;
static char	Line [MAXLINE+1];
static int	LineIdx = 0;

int OpenSerialPort (void)
{
	if ((SerialPort = fopen (SerialPortName, "r+")) == NULL) {
		fprintf (stderr, "Failed to open %s\n", SerialPortName);
		return 0;
	}
	SerialPortNo = fileno (SerialPort);
	tcgetattr (SerialPortNo, &OldSerialOptions);
	tcgetattr (SerialPortNo, &SerialOptions);
	memset (&SerialOptions, 0, sizeof (SerialOptions));
		/* set to 8n1 */
	SerialOptions.c_cflag |= (CS8 | CREAD | CLOCAL);
	SerialOptions.c_iflag |= (IGNPAR | IGNBRK | IGNCR);
	SerialOptions.c_oflag = 0;
		/* set baudrate. */
	SerialOptions.c_ispeed = B2400;
	SerialOptions.c_ospeed = B2400;
	cfsetispeed (&SerialOptions, B2400);
	cfsetospeed (&SerialOptions, B2400);
		/* turn off CANONICAL mode */
	SerialOptions.c_lflag = 0;
		/* access single char at a time */
	SerialOptions.c_cc[VTIME] = 0;
	SerialOptions.c_cc[VMIN] = 0;
	tcsetattr (SerialPortNo, TCSANOW, &SerialOptions);
		/* set the queue variables. */
	LineIdx = 0;
	return 1;
}

void CloseSerialPort (void)
{
	tcsetattr (SerialPortNo, TCSANOW, &OldSerialOptions);
}

int ReadSerialLine (char * Str)
{
int	amt;
	amt = fread (&Line[LineIdx], 1, 1, SerialPort);
	if (amt) {
		if (LineIdx < MAXLINE) {
			Line [++LineIdx] = '\0';
			if (Line [LineIdx-1] == 0xa) {
				strncpy (Str, Line, MAXLINE);
				Str [MAXLINE] = '\0';
				LineIdx = 0;
				return True;
			}
		} else {
				// we exceeded line space, kill this line!
			LineIdx = 0;
		}
	}
	*Str = '\0';
	return False; 
}

=====================================================================


TomW


-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------
This message resent by the uclinux-dev at uclinux.org list server
http://www.uClinux.org/
This message resent by the uclinux-dev at uclinux.org list server http://www.uClinux.org/



More information about the uClinux-dev mailing list