Common linux Network Programming header files, linux Network Programming

Source: Internet
Author: User
Tags crypt

Common linux Network Programming header files, linux Network Programming

Sys/types. h: Data Type Definition

Sys/socket. h: Provides socket functions and data structures.

Netinet/in. h: defines the data structure sockaddr_in

Arpa/inet. h: Provides IP address conversion functions.

Netdb. h: provides functions for setting and retrieving domain names.

Sys/ioctl. h: provides functions for I/O control.

Sys/poll. h: a function that provides the socket wait test mechanism

 

Other common header files in network programs

Unistd. h: provides common functions for file, directory, program, and process operations.

Errno. h: defines the error code errno for error handling.

Fcntl. h: provides functions for file control.

Time. h: provides functions related to time.

Crypt. h: provides encryption functions using the DES encryption algorithm.

Pwd. h: provides functions for accessing the/etc/passwd file.

Shadow. h: provides a function for accessing the/etc/shadow file.

Pthread. h: provides multi-threaded functions.

Signal. h: provides functions for signal operations.

Sys/wait. h, sys/ipc. h, sys/shm. h: provides functions such as process waiting, inter-process communication (IPC), and shared memory.

 

Suggestion: when writing a network program, you can directly use the following header file code

# Include <unistd. h>

# Include <sys/types. h>

# Include <sys/socket. h>

# Include <netdb. h>

# Include <stdio. h>

# Include <stdlib. h>

# Include <string. h>

# Include <ctype. h>

# Include <errno. h>

# Include <malloc. h>

# Include <netinet/in. h>

# Include <arpa/inet. h>

# Include <sys/ioctl. h>

# Include <stdarg. h>

# Include <fcntl. h>

# Include <fcntl. h>

 

Add the following statement when it comes to user permission and password verification:

# Include <shadow. h>

# Include <crypt. h>

# Include <pwd. h>

Note that you should link the encryption algorithm library during compilation, that is, add the compilation option:-lcrypt

 

Add the following statement to file and time operations:

# Include <sys/time. h>

# Include <utime. h>

# Include <time. h>

# Include <sys/stat. h>

# Include <sys/file. h>

 

When multi-process operations are involved, add the following statement:

# Include <sys/wait. h>

# Include <sys/ipc. h>

# Include <sys/shm. h>

# Include <signal. h>

 

When multithreading is involved, add the following statement:

# Include <pthread. h>

# Include <sys/poll. h>

Note that the thread library should be linked during compilation, that is, the compilation option-lthread should be added.


C Programming header file in Linux

The first one stores some constants and functions related to the system status. For example, how to view functions in the file status?
The second one stores the type definitions used. For example, _ ssize_t, and Other types used by the System

Windows and linux header files

The general Linux interface is described in "Advanced Programming in Unix environment" in detail.
For more information about socket, see the book Unix network programming.
If the graphic interface is used, the GDK and Qt libraries are usually used in Linux. That is to say, if you use a library function that contains the graphic interface in Windows, then you must modify the implementation of all your function calls, not just replacing the header file.

For cross-platform programs, we recommend that you use Qt, which is written in C ++. graphic interface operations can be directly used on Win \ Mac \ * nix and other platforms.

Good luck!

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.