- 论坛徽章:
- 0
|
好贴,呵呵,借问:
480 int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
481 size_t len)
482 {
483 struct inet_opt *inet = inet_sk(sk);
484 struct udp_opt *up = udp_sk(sk);
485 int ulen = len
486 struct ipcm_cookie ipc;
487 struct rtable *rt = NULL;
488 int free = 0;
489 int connected = 0;
490 u32 daddr, faddr, saddr;
491 u16 dport
……
525 /*
526 * Get and verify the address.
527 */
//检查struct msghdr结构的msg_name字段,确定目的地址是否合法
528 if (msg->msg_name) {
529 struct sockaddr_in * usin = (struct sockaddr_in*)msg->msg_name;
530 if (msg->msg_namelen < sizeof(*usin))
531 return -EINVAL;
532 if (usin->sin_family != AF_INET) {
533 if (usin->sin_family != AF_UNSPEC)
534 return -EINVAL;
535 }
//将套接字地址结构中的地址以及端口值赋给本函数中的地址端口值。
537 daddr = usin->sin_addr.s_addr;
538 dport = usin->sin_port;
539 if (dport == 0)
540 return -EINVAL;
541 }
//即使目的地址为空,但如果套接字处于TCP_ESTABLISHED状态,仍然认为目的地址合法,允许继续传输数据
else {
542 if (sk->sk_state != TCP_ESTABLISHED)
543 return -EDESTADDRREQ;
544 daddr = inet->daddr;
545 dport = inet->dport;
……
544 daddr = inet->daddr;
545 dport = inet->dport;
这两句是把inet结构体中的地址,端口值赋给本函数中的地址,端口值。
我想问一下
inet->daddr
inet->dport
inet结构体中这个地址,端口的值是哪里来的啊,谁付给它的呢?
源代码网址: http://lxr.oss.org.cn/source/net/ipv4/udp.c#L480
inet结构体为:
110 struct inet_opt {
111 /* Socket demultiplex comparisons on incoming packets. */
112 __u32 daddr; /* Foreign IPv4 addr */
113 __u32 rcv_saddr; /* Bound local IPv4 addr */
114 __u16 dport; /* Destination port */
115 __u16 num; /* Local port */
116 __u32 saddr; /* Sending source */
117 int uc_ttl; /* Unicast TTL */
118 int tos; /* TOS */
119 unsigned cmsg_flags;
120 struct ip_options *opt;
121 __u16 sport; /* Source port */
122 unsigned char hdrincl; /* Include headers ? */
123 __u8 mc_ttl; /* Multicasting TTL */
124 __u8 mc_loop; /* Loopback */
125 __u8 pmtudisc;
126 __u16 id; /* ID counter for DF pkts */
127 unsigned recverr : 1,
128 freebind : 1;
129 int mc_index; /* Multicast device index */
130 __u32 mc_addr;
131 struct ip_mc_socklist *mc_list; /* Group array */
132 /*
133 * Following members are used to retain the infomation to build
134 * an ip header on each ip fragmentation while the socket is corked.
135 */
136 struct {
137 unsigned int flags;
138 unsigned int fragsize;
139 struct ip_options *opt;
140 struct rtable *rt;
141 int length; /* Total length of all frames */
142 u32 addr;
143 struct flowi fl;
144 } cork;
145 };
146 |
|