当前位置: 技术问答>linux和unix
linux makeFile的问题
来源: 互联网 发布时间:2017-01-14
本文导语: makefile: #makefile to run TCPEchoClient4.c TCPEchoServer4.c UDPEchoClient.c UDPEchoServer.c TCPEchoServer4 :TCPEchoServer4.o gcc -o TCPEchoServer4 TCPEchoServer4.o TCPEchoServer4.o:TCPEchoServer4.c gcc -c TCPEchoServer4.c Practical.h: #ifndef PRACTICAL_H_ #define PRA...
makefile:
#makefile to run TCPEchoClient4.c TCPEchoServer4.c UDPEchoClient.c UDPEchoServer.c
TCPEchoServer4 :TCPEchoServer4.o
gcc -o TCPEchoServer4 TCPEchoServer4.o
TCPEchoServer4.o:TCPEchoServer4.c
gcc -c TCPEchoServer4.c
Practical.h:
#ifndef PRACTICAL_H_
#define PRACTICAL_H_
#include
#include
#include
// Handle error with user msg
void DieWithUserMessage(const char *msg, const char *detail);
// Handle error with sys msg
void DieWithSystemMessage(const char *msg);
// Print socket address
void PrintSocketAddress(const struct sockaddr *address, FILE *stream);
// Test socket address equality
bool SockAddrsEqual(const struct sockaddr *addr1, const struct sockaddr *addr2);
// Create, bind, and listen a new TCP server socket
int SetupTCPServerSocket(const char *service);
// Accept a new TCP connection on a server socket
int AcceptTCPConnection(int servSock);
// Handle new TCP client
void HandleTCPClient(int clntSocket);
// Create and connect a new TCP client socket
int SetupTCPClientSocket(const char *server, const char *service);
enum sizeConstants {
MAXSTRINGLENGTH = 128,
BUFSIZE = 512,
};
#endif // PRACTICAL_H_
TCPEchoServer4.c
#include
#include
#include
#include
#include
#include
#include
#include "Practical.h"
static const int MAXPENDING = 5; // Maximum outstanding connection requests
int main(int argc, char *argv[]) {
if (argc != 2) // Test for correct number of arguments
DieWithUserMessage("Parameter(s)", "");
in_port_t servPort = atoi(argv[1]); // First arg: local port
// Create socket for incoming connections
int servSock; // Socket descriptor for server
if ((servSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))
#makefile to run TCPEchoClient4.c TCPEchoServer4.c UDPEchoClient.c UDPEchoServer.c
TCPEchoServer4 :TCPEchoServer4.o
gcc -o TCPEchoServer4 TCPEchoServer4.o
TCPEchoServer4.o:TCPEchoServer4.c
gcc -c TCPEchoServer4.c
Practical.h:
#ifndef PRACTICAL_H_
#define PRACTICAL_H_
#include
#include
#include
// Handle error with user msg
void DieWithUserMessage(const char *msg, const char *detail);
// Handle error with sys msg
void DieWithSystemMessage(const char *msg);
// Print socket address
void PrintSocketAddress(const struct sockaddr *address, FILE *stream);
// Test socket address equality
bool SockAddrsEqual(const struct sockaddr *addr1, const struct sockaddr *addr2);
// Create, bind, and listen a new TCP server socket
int SetupTCPServerSocket(const char *service);
// Accept a new TCP connection on a server socket
int AcceptTCPConnection(int servSock);
// Handle new TCP client
void HandleTCPClient(int clntSocket);
// Create and connect a new TCP client socket
int SetupTCPClientSocket(const char *server, const char *service);
enum sizeConstants {
MAXSTRINGLENGTH = 128,
BUFSIZE = 512,
};
#endif // PRACTICAL_H_
TCPEchoServer4.c
#include
#include
#include
#include
#include
#include
#include
#include "Practical.h"
static const int MAXPENDING = 5; // Maximum outstanding connection requests
int main(int argc, char *argv[]) {
if (argc != 2) // Test for correct number of arguments
DieWithUserMessage("Parameter(s)", "");
in_port_t servPort = atoi(argv[1]); // First arg: local port
// Create socket for incoming connections
int servSock; // Socket descriptor for server
if ((servSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))