linuxÏÂIP v6 tcp·þÎñÆ÷¶ËÔ´ÂëʾÀý
/******************************
*
* server.c
*
******************************/
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<errno.h>
#include<string.h>
#include<netinet/in.h>
#include<sys/wait.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<pthread.h>
#define MAXBUF 1024
#define LISNUM 10
#define DEFULT_PORT 8787
void *connect_to_client(void *data);
struct sockaddr_in6 serv_addr,client_addr;
/**************************/
int main(int argc,char *argv[])
{
int sockfd,new_fd;
unsigned int serv_port;
unsigned int lisnum;
char buf[MAXBUF+1];
printf( "the command is %s [port] [listen_num]\n", argv[0] );
// ¼àÌýÆðʼ¶Ë¿Ú
if ( argv[1] != NULL )
{
serv_port = atoi( argv[1] );
}
else
{
serv_port = DEFULT_PORT;
}
// ¼àÌý¶Ë¿Ú¸öÊý
if ( argv[2] != NULL )
{
lisnum = atoi(argv[2]);
}
else
{
lisnum = LISNUM;
}
// ´´½¨socket
if ( (sockfd = socket(PF_INET6,SOCK_STREAM,0)) < 0 )
{
perror("creat socket");
exit(1);
}
// ÅäÖ÷þÎñÆ÷µØÖ·Óë¶Ë¿Ú
bzero(&serv_addr, sizeof(serv_addr));
serv_addr.sin6_family = AF_INET6;
serv_addr.sin6_port = htons(serv_port);
serv_addr.sin6_addr = in6addr_any;
// µØÖ·°ó¶¨²Ù×÷
if ( bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr) ) <0 )
{
perror("bind");
exit(1);
}
// ·þÎñÆ÷¼àÌý
if ( listen(sockfd, lisnum) < 0 )
{
perror("listen");
exit(1);
}
while(1)
{
int len = sizeof(struct
Ïà¹ØÎĵµ£º
ÐéÄâ»úlinux°æ±¾£ºredhat9.0
×ܽáһϣºÒª±£Ö¤ÐéÄâ»úϵͳ¿ÉÒÔÉÏÍø£¬µÃÏȽâ¾öÐéÄâ»úºÍÕæʵÖ÷»úµÄÁ¬½Ó¹Øϵ¡£VMwareÖ÷Òª¸ø³ö3ÖÖģʽ£¬ÎÒÃdz£ÓõÄÓГbridge£¨ÇŽӣ©”ºÍ
“Nat£¨ÍøÂçµØַת»»£©”·½Ê½¡£ÐéÄâ»úÉèÖ÷½·¨£ºµ¥»÷“ÐéÄâ»ú”→“ÉèÖÔ→“ÒÔÌ«Íø£¬È»ºóÑ¡ÔñÁ ......
ÎÄÕÂÑ¡È¡µÄÀý×ӷdz£¼òµ¥£¬ÉÏÊÖÈÝÒ×£¬Ö»ÊÇΪÁ˽²Êö¾²Ì¬Ó붯̬Á´½Ó¿âµÄÉú³ÉºÍÁ´½Ó¹ý
³Ì£¬»¹ÓÐËûÃÇÖ®¼äµÄÇø±ð¡£ÒÔÏÂÀý×ÓÔÚ gcc 4.1.1 ÏÂ˳Àûͨ¹ý¡£
ÎļþÔ¤ÀÀ
ÎļþĿ¼Ê÷ÈçÏ£¬ÈçÄãËù¼û£¬·Ç³£¼òµ¥¡£
libtest/
|-- lt.c
|-- lt.h
`-- test. ......
ÓɲÙ×÷ϵͳʵÏÖµÄËùÓÐϵͳµ÷ÓÃËù¹¹³ÉµÄ¼¯ºÏ¼´³ÌÐò½Ó¿Ú»òÓ¦Óñà³Ì½Ó¿Ú(Application Programming Interface£¬API)¡£ÊÇÓ¦ÓóÌÐòͬϵͳ֮¼äµÄ½Ó¿Ú¡£
¡¡¡¡²Ù×÷ϵͳµÄÖ÷Òª¹¦ÄÜÊÇΪӦÓóÌÐòµÄÔËÐд´½¨Á¼ºÃµÄ»·¾³£¬ÎªÁË´ïµ½Õâ¸öÄ¿µÄ£¬ÄÚºËÌṩһϵÁо߱¸Ô¤¶¨¹¦ÄܵĵÄÄں˺¯Êý£¬Í¨¹ýÒ»×é³ÆΪϵͳµ÷Óõģ¨system call)µÄ½Ó¿Ú³ÊÏÖ¸øÓà ......
[root@ns1 opt]# du -h -s /* | sort
12K /mnt
13M /sbin
16K /lost+found
1.8G /usr
194M /root
22G /opt
24K /tmp
4.0K&n ......
linux shell pwd ÏÔʾµ±Ç°Â·¾¶
¼ÙÈôÓÐtest.cpp
g++ test.cpp -o test
./test
ÏëÔÚtestÖÐÕÒµ½µ±Ç°Ö´ÐгÌÐòËùÔڵķ¾¶
¿ÉÒÔÔÙtest.cppÖÐʹÓÃreadlinkº¯Êý
¾ßÌå¼ûÈçÏÂʵÀý£º
#include<iostream>
#include<unistd.h>
#include<dirent.h>
#include<string.h>
#include<string>
using ......