Two sections of Linux code, project decommissioned, some use, throwing a pity
Source: Internet
Author: User
Two sections of Linux code, project decommissioned, and some use, throwing away a pity-general Linux technology-Linux programming and kernel information. The following is a detailed description. 1. For normal Linux input, you must press enter to receive the input. You can use this function to perform each response. However, when a BUG is printf, A '\ n' must be added for output. The cause is unknown.
Void get_callee_number (char * buf)
{
Fd_set keyset;
Struct timeval TV;
Int keyfd = fileno (stdin), ret;
Char c;
Struct termios save, ne;
Int I = 0;
Ioctl (0, TCGETS, & save );
Ioctl (0, TCGETS, & ne );
Ne. c_lflag & = ~ (ECHO | ICANON );
Ioctl (0, TCSETS, & ne );
While (1)
{
TV. TV _sec = 2;
TV. TV _usec = 0;
FD_SET (keyfd, & keyset );
Ret = select (keyfd + 1, & keyset, NULL, NULL, & TV );
If (ret = 0 & strlen (buf )! = 0)
Break;
If (FD_ISSET (keyfd, & keyset ))
{
Read (keyfd, & c, 1 );
Buf [I ++] = c;
// Printf ("the key is % c \ n", c );
}
If (c! = 0) printf ("% c \ n", c );
}
Ioctl (0, TCSETS, & save );
}
2. Obtain the local Internet IP address (the first Nic)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.