当前位置:网站首页>TCP specifies the source port
TCP specifies the source port
2022-06-24 21:23:00 【already_ skb】
- Reprint , Original address :http://blog.csdn.net/liangxiaozhang/article/details/8267854
- #include <stdio.h>
- #include <stdlib.h>
- #include <strings.h>
- #include <arpa/inet.h>
- #include <sys/socket.h>
- int main(){
- int sockfd = socket(AF_INET,SOCK_STREAM,0);
- if(sockfd==-1)perror("sock");
- struct sockaddr_in mine,dest;
-
- bzero(&mine,sizeof(mine));
- mine.sin_family = AF_INET;
- mine.sin_port = htons(3334);
- inet_pton(AF_INET,"192.168.1.100",&mine.sin_addr);
-
- bzero(&dest,sizeof(dest));
- dest.sin_family = AF_INET;
- dest.sin_port = htons(9999);
- inet_pton(AF_INET,"192.168.1.100",&dest.sin_addr);
- int b = bind(sockfd,(struct sockaddr*)&mine,sizeof(mine));
- if(b==-1)perror("");
-
- int c = connect(sockfd,(struct sockaddr*)&dest,sizeof(dest));
- if(c!=0)perror("");
- close(sockfd);
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/socket.h>
- #include <arpa/inet.h>
- #include <strings.h>
- int main(){
- int sockfd = socket(AF_INET,SOCK_STREAM,0);
- struct sockaddr_in addr;
- bzero(&addr,sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(9999);
- inet_pton(AF_INET,"192.168.1.100",&addr.sin_addr);
- bind(sockfd,(struct sockaddr*)&addr,sizeof(addr));
- listen(sockfd,5);
- while(1){
- struct sockaddr_in c_addr;
- int c_len = sizeof(c_addr);
- bzero(&c_addr,c_len);
- int c = accept(sockfd,(struct sockaddr*)&addr,&c_len);
- if(c==-1)perror("");
- char ip[40]={ 0};
- int port;
- inet_ntop(AF_INET,&addr.sin_addr,ip,40);
- port = ntohs(addr.sin_port);
- printf("from %s:%d\n",ip,port);
- close(c);
- }
- }
边栏推荐
- 网络安全审查办公室对知网启动网络安全审查
- The virtual currency evaporated $2trillion in seven months, and the "musks" ended the dream of 150000 people becoming rich
- Bridging mode -- law firm
- Smooth live broadcast | analysis of key technologies for live broadcast pain points
- Microsoft Certification (dynamic 365) test
- Physical layer introduction
- Use of kubernetes storage volumes
- Php-pdo parameter binding problem
- Logical backup: mysqldump vs physical backup: xtrabackup
- memcached全面剖析–5. memcached的应用和兼容程序
猜你喜欢

Arkit与Character Creator动画曲线的对接

What are the problems with traditional IO? Why is zero copy introduced?
[email protected] -Perfmon metric collector listener steps"/>JMeter installation plug-in, adding [email protected] -Perfmon metric collector listener steps

ping: www.baidu.com: 未知的名称或服务

Pod lifecycle in kubernetes

Variable setting in postman

网络安全审查办公室对知网启动网络安全审查

Alibaba cloud schedules tasks and automatically releases them

Responsibility chain mode -- through interview

基于STM32的物联网下智能化养鱼鱼缸控制控制系统
随机推荐
Format method and parse method of dateformat class
123. 买卖股票的最佳时机 III
Packaging_ Conversion between basic type and string type
Handwritten RPC the next day -- review of some knowledge
DHCP operation
What are the problems with traditional IO? Why is zero copy introduced?
Network security review office starts network security review on HowNet
regular expression
Simpledateformat thread unsafe
Does the developer want to change to software testing?
Web automation: summary of special scenario processing methods
188. 买卖股票的最佳时机 IV
Alibaba cloud schedules tasks and automatically releases them
Read all text from stdin to a string
Postman assertion
I just purchased a MySQL database and prompted that there are already instances. The console login instance needs to provide a database account. How do I know the database account.
Sleep revolution - find the right length of rest
Intermediary model -- collaboration among departments
The Google File System (GFS) learning notes
CondaValueError: The target prefix is the base prefix. Aborting.