IP:分片与重组
1. 引言
为了与互联网上的任意计算机通信,每个应用TCP/IP的计算机必须具有分片和重组的代码,一个设计良好的应用软件,会生成足够小的数据报,
因此主机并不需要经常执行分片任务.
2. 数据报的分片
分片发生在选择路由之后,以及放入接口队列之前.IP把数据报长度与MTU进行比较,确定是否需要分片.
如需分片,IP首先生成多个数据报,并将每个数据报中的分片位置1,将源数据报中的数据按顺序分......
Read more
归档于 ‘LINUX C’ 分类
1 引言
讨论选择路由的细节,选路表的结构,以及实现算法,路由如何使用子网掩码,如何区分网络路由子网路由以及主机路由
2 路由维护和查找
应当选择能使查找路由花费最小的IP数据结构和算法,维护路由的花费则并不那么重要
利用桶散列(bucket hashing)迅速找到正确的散列表元
3 选路表结构
保存路由的主要数据结构是数组。数组的每个元素对应一个散列表元,并包含一个指针,指向被装入这个散列表元......
Read more
Read more
1.中心环节
IP是整个协议软件的中心环节,不要把IP软件简单的分割成输入和输出两部分,因为输入和输出的界限很模糊.以下把重点放在网关上.
2. IP软件设计思想
* 统一的输入队列以及统一的选路过程
* 独立的IP进程
* 本地主机接口
3. IP软件结构和数据报流程
4. IP软件结构和数据报流程
4.1 选择传入数据报的策略
挑选数据报并为其选择路由的IP程序段实现了一个重要策略:它决......
Read more
Read more
1. ARP高速缓存的数据结构
/* arp.h - SHA, SPA, THA, TPA */
/* 互联网地址解析协议 (see RFCs 826, 920) */
#define AR_HARDWARE 1 /* 以太网硬件类型代码 */
/* Definitions of codes used in operation field of ARP packet */
#define AR_REQUEST 1 /* ARP请求解决地址 ARP request to resolve address */
#define......
Read more
Read more
1. 接口数据结构
/* netif.h - NIGET */
#define NI_MAXHWA 14 /* 任何硬件最大尺寸 max size of any hardware*/
/* (物理)网络地址 */
struct hwa { /* *硬件地址 */
int ha_len;......
Read more
Read more
学习linux有些时日了,这个就是我的一第一真正的作品,发表一下作品,希望其中的一些技巧对朋友们有所帮助,也希望达人指正一下其中的不足。主要应用知识:linux的网络通信文件的属性及操作多进程的应用进程的回收信号的应用下面是客户端文件的意义:command.c 命令模块 ,common.h 公共声明, input.c 分割命令, main.c 主程序 ,Makefile make工具用的,ssjio.c ssjio.h 是我自己的模块main.c#include "common.h"int main(void){char clin......
Read more
Read more
这个与AF_INET不同地方在于,客户端也要用bind绑定一下,不要靠connect分配,不然服务器是无法知道客户用的是哪个套接字文件服务器端[ssj@main test]$ cat AFunixserver.c#include <stdio.h>#include <stdlib.h>#include <stddef.h>#include <sys/socket.h>#include <sys/un.h>#include <string.h>#include <time.h>#include <sys/stat.h>#define PATH "/home/ssj/source/test/connect.socket"#define STALE 30#define MAX 1024void my_turn(char *p){if (p == N......
Read more
Read more
这个东西和匿名管道就没有什么区别呀[ssj@main test]$ cat socketpair.c#include <stdio.h>#include <stdlib.h>#include <fcntl.h>#include <unistd.h>#include <sys/socket.h>#include <string.h>#define MAX 100int main(void){int sockfd[2],n;pid_t pid;char buf[MAX];bzero(buf,sizeof(buf));if(socketpair(AF_UNIX,SOCK_STREAM,0,sockfd)==-1) {perror("Fail to socketpair");exit(1);}pid=fork();if(pid<0){perror("Fail to fork");exit(1);}else if(pid==0){ close(sockfd[0]); strcpy(buf,......
Read more
Read more
书中自有言如玉呀,select函数的使用方法,我在中间加入了一些printf语言,更方便理解程序的流程客户端用之前的TCP例子就行了,见http://www.kumouse.com/article.asp?id=141[ssj@main test]$ cat selectserver.c#include <stdio.h>#include <string.h>#include <unistd.h>#include <ctype.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <errno.h>#define MAX 80int port=65533;void my_turn(char *p){slee......
Read more
Read more
服务器端:[ssj@main test]$ cat noneasyserver.c#include <stdio.h>#include <string.h>#include <unistd.h>#include <ctype.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <stdlib.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>#define MAX 80void my_turn(char *p){if (p == NULL)return;while( *p != '\0'){if( *p >= (char)0x61 && *p <= (char)0x7a)*p=(char)((int)*p-(int)0x20);p++;}}int main(void){ struct sockadd......
Read more
Read more