|
[code:1]
#include"unp.h"
int main(int argc ,char **argv)
{
int sockfd,n;
char recvline[MAXLINE+1];
struct sockaddr_in servaddr;
if(argc!=2)
err_quit("usage:a.out<'IPaddress'>");
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
err_sys("socket error");
bzero(&servaddr,sizeof(servaddr));
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(13);
if(inet_pton(AF_INET,argv[1],&servaddr.sin_addr)<=0)
err_quit("Inet_pton erro for %s",argv[1]);
if(connect(sockfd,(SA *)&servaddr,sizeof(servaddr))<0)
err_sys("connet erro");
while((n=read(sockfd,recvline,MAXLINE))>0)
{
recvline[n]=0;
if(fputs(recvline,stdout)==EOF)
err_sys("fputs erro");
}
if(n<0)
err_sys("read erro");
exit(0);
}
[/code:1]
[root@firescript root]# gcc -g -o tcp tcp.c
[code:1]
/tmp/ccKiMmft.o(.text+0x22): In function `main':
/root/tcp.c:8: undefined reference to `err_quit'
/tmp/ccKiMmft.o(.text+0x4c):/root/tcp.c:10: undefined reference to `err_sys'
/tmp/ccKiMmft.o(.text+0xb8):/root/tcp.c:15: undefined reference to `err_quit'
/tmp/ccKiMmft.o(.text+0xe3):/root/tcp.c:17: undefined reference to `err_sys'
/tmp/ccKiMmft.o(.text+0x142):/root/tcp.c:22: undefined reference to `err_sys'
/tmp/ccKiMmft.o(.text+0x15a):/root/tcp.c:25: undefined reference to `err_sys'
collect2: ld returned 1 exit status
[/code:1]
|
|